Wed, 19 Sep 2018 18:00:50 +0800
#7557 removed redundant get_thread to save interpreter code size
1 /*
2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2015, 2018, Loongson Technology. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
26 #include "precompiled.hpp"
27 #include "interp_masm_mips_64.hpp"
28 #include "interpreter/interpreter.hpp"
29 #include "interpreter/interpreterRuntime.hpp"
30 #include "oops/arrayOop.hpp"
31 #include "oops/markOop.hpp"
32 #include "oops/methodData.hpp"
33 #include "oops/method.hpp"
34 #include "prims/jvmtiExport.hpp"
35 #include "prims/jvmtiRedefineClassesTrace.hpp"
36 #include "prims/jvmtiThreadState.hpp"
37 #include "runtime/basicLock.hpp"
38 #include "runtime/biasedLocking.hpp"
39 #include "runtime/sharedRuntime.hpp"
40 #include "runtime/thread.inline.hpp"
43 // Implementation of InterpreterMacroAssembler
45 #ifdef CC_INTERP
46 void InterpreterMacroAssembler::get_method(Register reg) {
47 }
48 #endif // CC_INTERP
50 void InterpreterMacroAssembler::get_2_byte_integer_at_bcp(Register reg, Register tmp, int offset) {
51 /* 2016/5/6 Jin: the runtime address of BCP may be unaligned.
52 * Refer to the SPARC implementation. */
53 lbu(reg, BCP, offset+1);
54 lbu(tmp, BCP, offset);
55 #ifdef _LP64
56 dsll(reg, reg, 8);
57 daddu(reg, tmp, reg);
58 #else
59 sll(reg, reg, 8);
60 addu(reg, tmp, reg);
61 #endif
62 }
64 void InterpreterMacroAssembler::get_4_byte_integer_at_bcp(Register reg, Register tmp, int offset) {
65 assert(reg != tmp, "need separate temp register");
66 if (offset & 3) { // Offset unaligned?
67 lbu(reg, BCP, offset+3);
68 lbu(tmp, BCP, offset+2);
69 #ifdef _LP64
70 dsll(reg, reg, 8);
71 daddu(reg, tmp, reg);
72 lbu(tmp, BCP, offset+1);
73 dsll(reg, reg, 8);
74 daddu(reg, tmp, reg);
75 lbu(tmp, BCP, offset);
76 dsll(reg, reg, 8);
77 daddu(reg, tmp, reg);
78 #else
79 sll(reg, reg, 8);
80 addu(reg, tmp, reg);
81 lbu(tmp, BCP, offset+1);
82 sll(reg, reg, 8);
83 addu(reg, tmp, reg);
84 lbu(tmp, BCP, offset);
85 sll(reg, reg, 8);
86 addu(reg, tmp, reg);
87 #endif
88 } else {
89 lwu(reg, BCP, offset);
90 }
91 }
93 #ifndef CC_INTERP
95 void InterpreterMacroAssembler::call_VM_leaf_base(address entry_point,
96 int number_of_arguments) {
97 // interpreter specific
98 //
99 // Note: No need to save/restore bcp & locals (r13 & r14) pointer
100 // since these are callee saved registers and no blocking/
101 // GC can happen in leaf calls.
102 // Further Note: DO NOT save/restore bcp/locals. If a caller has
103 // already saved them so that it can use esi/edi as temporaries
104 // then a save/restore here will DESTROY the copy the caller
105 // saved! There used to be a save_bcp() that only happened in
106 // the ASSERT path (no restore_bcp). Which caused bizarre failures
107 // when jvm built with ASSERTs.
108 #ifdef ASSERT
109 save_bcp();
110 {
111 Label L;
112 ld(AT,FP,frame::interpreter_frame_last_sp_offset * wordSize);
113 beq(AT,R0,L);
114 delayed()->nop();
115 stop("InterpreterMacroAssembler::call_VM_leaf_base: last_sp != NULL");
116 bind(L);
117 }
118 #endif
119 // super call
120 MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments);
121 // interpreter specific
122 #ifdef ASSERT
123 {
124 Label L;
125 ld(T3, FP, frame::interpreter_frame_bcx_offset * wordSize);
126 Assembler::beq(BCP, T3, L);
127 delayed()->nop();
128 stop("InterpreterMacroAssembler::call_VM_leaf_base: esi not callee saved?");
129 bind(L);
130 }
131 {
132 Label L;
133 ld(T3, FP, frame::interpreter_frame_locals_offset * wordSize);
134 Assembler::beq(LVP, T3, L);
135 delayed()->nop();
136 stop("InterpreterMacroAssembler::call_VM_leaf_base: edi not callee saved?");
137 bind(L);
138 }
139 #endif
140 }
142 void InterpreterMacroAssembler::call_VM_base(Register oop_result,
143 Register java_thread,
144 Register last_java_sp,
145 address entry_point,
146 int number_of_arguments,
147 bool check_exceptions) {
148 // interpreter specific
149 //
150 // Note: Could avoid restoring locals ptr (callee saved) - however doesn't
151 // really make a difference for these runtime calls, since they are
152 // slow anyway. Btw., bcp must be saved/restored since it may change
153 // due to GC.
154 assert(java_thread == noreg , "not expecting a precomputed java thread");
155 save_bcp();
156 #ifdef ASSERT
157 {
158 Label L;
159 ld(AT, FP, frame::interpreter_frame_last_sp_offset * wordSize);
160 beq(AT, R0, L);
161 delayed()->nop();
162 stop("InterpreterMacroAssembler::call_VM_base: last_sp != NULL");
163 bind(L);
164 }
165 #endif /* ASSERT */
166 // super call
167 MacroAssembler::call_VM_base(oop_result, java_thread, last_java_sp,
168 entry_point, number_of_arguments,
169 check_exceptions);
170 // interpreter specific
171 restore_bcp();
172 restore_locals();
173 }
176 void InterpreterMacroAssembler::check_and_handle_popframe(Register java_thread) {
177 if (JvmtiExport::can_pop_frame()) {
178 Label L;
179 // Initiate popframe handling only if it is not already being
180 // processed. If the flag has the popframe_processing bit set, it
181 // means that this code is called *during* popframe handling - we
182 // don't want to reenter.
183 // This method is only called just after the call into the vm in
184 // call_VM_base, so the arg registers are available.
185 // Not clear if any other register is available, so load AT twice
186 assert(AT != java_thread, "check");
187 lw(AT, java_thread, in_bytes(JavaThread::popframe_condition_offset()));
188 andi(AT, AT, JavaThread::popframe_pending_bit);
189 beq(AT, R0, L);
190 delayed()->nop();
192 lw(AT, java_thread, in_bytes(JavaThread::popframe_condition_offset()));
193 andi(AT, AT, JavaThread::popframe_processing_bit);
194 bne(AT, R0, L);
195 delayed()->nop();
196 call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry));
197 jr(V0);
198 delayed()->nop();
199 bind(L);
200 }
201 }
204 void InterpreterMacroAssembler::load_earlyret_value(TosState state) {
205 Register thread = T8;
206 #ifndef OPT_THREAD
207 get_thread(thread);
208 #else
209 move(T8, TREG);
210 #endif
211 ld_ptr(thread, thread, in_bytes(JavaThread::jvmti_thread_state_offset()));
212 const Address tos_addr (thread, in_bytes(JvmtiThreadState::earlyret_tos_offset()));
213 const Address oop_addr (thread, in_bytes(JvmtiThreadState::earlyret_oop_offset()));
214 const Address val_addr (thread, in_bytes(JvmtiThreadState::earlyret_value_offset()));
215 //V0, oop_addr,V1,val_addr
216 switch (state) {
217 case atos:
218 ld_ptr(V0, oop_addr);
219 st_ptr(R0, oop_addr);
220 verify_oop(V0, state);
221 break;
222 case ltos:
223 ld_ptr(V0, val_addr); // fall through
224 break;
225 case btos: // fall through
226 case ztos: // fall through
227 case ctos: // fall through
228 case stos: // fall through
229 case itos:
230 lw(V0, val_addr);
231 break;
232 case ftos:
233 lwc1(F0, thread, in_bytes(JvmtiThreadState::earlyret_value_offset()));
234 break;
235 case dtos:
236 ldc1(F0, thread, in_bytes(JvmtiThreadState::earlyret_value_offset()));
237 break;
238 case vtos: /* nothing to do */ break;
239 default : ShouldNotReachHere();
240 }
241 // Clean up tos value in the thread object
242 move(AT, (int)ilgl);
243 sw(AT, tos_addr);
244 sw(R0, thread, in_bytes(JvmtiThreadState::earlyret_value_offset()));
245 }
248 void InterpreterMacroAssembler::check_and_handle_earlyret(Register java_thread) {
249 if (JvmtiExport::can_force_early_return()) {
250 Label L;
251 Register tmp = T9;
253 assert(java_thread != AT, "check");
254 assert(java_thread != tmp, "check");
255 ld_ptr(AT, java_thread, in_bytes(JavaThread::jvmti_thread_state_offset()));
256 beq(AT, R0, L);
257 delayed()->nop();
259 // Initiate earlyret handling only if it is not already being processed.
260 // If the flag has the earlyret_processing bit set, it means that this code
261 // is called *during* earlyret handling - we don't want to reenter.
262 lw(AT, AT, in_bytes(JvmtiThreadState::earlyret_state_offset()));
263 move(tmp, JvmtiThreadState::earlyret_pending);
264 bne(tmp, AT, L);
265 delayed()->nop();
267 // Call Interpreter::remove_activation_early_entry() to get the address of the
268 // same-named entrypoint in the generated interpreter code.
269 ld_ptr(tmp, java_thread, in_bytes(JavaThread::jvmti_thread_state_offset()));
270 lw(AT, tmp, in_bytes(JvmtiThreadState::earlyret_tos_offset()));
271 move(A0, AT);
272 call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), A0);
273 jr(V0);
274 delayed()->nop();
275 bind(L);
276 }
277 }
280 void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp(Register reg,
281 int bcp_offset) {
282 assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode");
283 lbu(AT, BCP, bcp_offset);
284 lbu(reg, BCP, bcp_offset + 1);
285 ins(reg, AT, 8, 8);
286 }
289 void InterpreterMacroAssembler::get_cache_index_at_bcp(Register index,
290 int bcp_offset,
291 size_t index_size) {
292 assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
293 if (index_size == sizeof(u2)) {
294 get_2_byte_integer_at_bcp(index, AT, bcp_offset);
295 } else if (index_size == sizeof(u4)) {
296 assert(EnableInvokeDynamic, "giant index used only for JSR 292");
297 get_4_byte_integer_at_bcp(index, AT, bcp_offset);
298 // Check if the secondary index definition is still ~x, otherwise
299 // we have to change the following assembler code to calculate the
300 // plain index.
301 assert(ConstantPool::decode_invokedynamic_index(~123) == 123, "else change next line");
302 nor(index, index, R0);
303 sll(index, index, 0);
304 } else if (index_size == sizeof(u1)) {
305 lbu(index, BCP, bcp_offset);
306 } else {
307 ShouldNotReachHere();
308 }
309 }
312 void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache,
313 Register index,
314 int bcp_offset,
315 size_t index_size) {
316 assert_different_registers(cache, index);
317 get_cache_index_at_bcp(index, bcp_offset, index_size);
318 ld(cache, FP, frame::interpreter_frame_cache_offset * wordSize);
319 assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
320 assert(exact_log2(in_words(ConstantPoolCacheEntry::size())) == 2, "else change next line");
321 shl(index, 2);
322 }
325 void InterpreterMacroAssembler::get_cache_and_index_and_bytecode_at_bcp(Register cache,
326 Register index,
327 Register bytecode,
328 int byte_no,
329 int bcp_offset,
330 size_t index_size) {
331 get_cache_and_index_at_bcp(cache, index, bcp_offset, index_size);
332 // We use a 32-bit load here since the layout of 64-bit words on
333 // little-endian machines allow us that.
334 dsll(AT, index, Address::times_ptr);
335 dadd(AT, cache, AT);
336 lw(bytecode, AT, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset()));
338 const int shift_count = (1 + byte_no) * BitsPerByte;
339 assert((byte_no == TemplateTable::f1_byte && shift_count == ConstantPoolCacheEntry::bytecode_1_shift) ||
340 (byte_no == TemplateTable::f2_byte && shift_count == ConstantPoolCacheEntry::bytecode_2_shift),
341 "correct shift count");
342 dsrl(bytecode, bytecode, shift_count);
343 assert(ConstantPoolCacheEntry::bytecode_1_mask == ConstantPoolCacheEntry::bytecode_2_mask, "common mask");
344 move(AT, ConstantPoolCacheEntry::bytecode_1_mask);
345 andr(bytecode, bytecode, AT);
346 }
348 void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache,
349 Register tmp,
350 int bcp_offset,
351 size_t index_size) {
352 assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
353 assert(cache != tmp, "must use different register");
354 get_cache_index_at_bcp(tmp, bcp_offset, index_size);
355 assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
356 // convert from field index to ConstantPoolCacheEntry index
357 // and from word offset to byte offset
358 assert(exact_log2(in_bytes(ConstantPoolCacheEntry::size_in_bytes())) == 2 + LogBytesPerWord, "else change next line");
359 shl(tmp, 2 + LogBytesPerWord);
360 ld(cache, FP, frame::interpreter_frame_cache_offset * wordSize);
361 // skip past the header
362 daddi(cache, cache, in_bytes(ConstantPoolCache::base_offset()));
363 dadd(cache, cache, tmp);
364 }
366 void InterpreterMacroAssembler::get_method_counters(Register method,
367 Register mcs, Label& skip) {
368 Label has_counters;
369 ld(mcs, method, in_bytes(Method::method_counters_offset()));
370 bne(mcs, R0, has_counters);
371 delayed()->nop();
372 call_VM(noreg, CAST_FROM_FN_PTR(address,
373 InterpreterRuntime::build_method_counters), method);
374 ld(mcs, method, in_bytes(Method::method_counters_offset()));
375 beq(mcs, R0, skip); // No MethodCounters allocated, OutOfMemory
376 delayed()->nop();
377 bind(has_counters);
378 }
380 // Load object from cpool->resolved_references(index)
381 void InterpreterMacroAssembler::load_resolved_reference_at_index(
382 Register result, Register index) {
383 assert_different_registers(result, index);
384 // convert from field index to resolved_references() index and from
385 // word index to byte offset. Since this is a java object, it can be compressed
386 Register tmp = index; // reuse
387 shl(tmp, LogBytesPerHeapOop);
389 get_constant_pool(result);
390 // load pointer for resolved_references[] objArray
391 ld(result, result, ConstantPool::resolved_references_offset_in_bytes());
392 // JNIHandles::resolve(obj);
393 ld(result, result, 0); //? is needed?
394 // Add in the index
395 dadd(result, result, tmp);
396 load_heap_oop(result, Address(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
397 }
399 // Resets LVP to locals. Register sub_klass cannot be any of the above.
400 void InterpreterMacroAssembler::gen_subtype_check( Register Rsup_klass, Register Rsub_klass, Label &ok_is_subtype ) {
401 assert( Rsub_klass != Rsup_klass, "Rsup_klass holds superklass" );
402 assert( Rsub_klass != T1, "T1 holds 2ndary super array length" );
403 assert( Rsub_klass != T0, "T0 holds 2ndary super array scan ptr" );
404 // Profile the not-null value's klass.
405 // [20130904] Fu: Here T9 and T1 are used as temporary registers.
406 profile_typecheck(T9, Rsub_klass, T1); // blows rcx, reloads rdi
408 // Do the check.
409 check_klass_subtype(Rsub_klass, Rsup_klass, T1, ok_is_subtype); // blows rcx
411 // Profile the failure of the check.
412 profile_typecheck_failed(T9); // blows rcx
413 }
417 // Java Expression Stack
419 void InterpreterMacroAssembler::pop_ptr(Register r) {
420 ld(r, SP, 0);
421 daddiu(SP, SP, Interpreter::stackElementSize);
422 }
424 void InterpreterMacroAssembler::pop_i(Register r) {
425 lw(r, SP, 0);
426 daddiu(SP, SP, Interpreter::stackElementSize);
427 }
429 void InterpreterMacroAssembler::pop_l(Register r) {
430 ld(r, SP, 0);
431 daddiu(SP, SP, 2 * Interpreter::stackElementSize);
432 }
434 void InterpreterMacroAssembler::pop_f(FloatRegister r) {
435 lwc1(r, SP, 0);
436 daddiu(SP, SP, Interpreter::stackElementSize);
437 }
439 void InterpreterMacroAssembler::pop_d(FloatRegister r) {
440 ldc1(r, SP, 0);
441 daddiu(SP, SP, 2 * Interpreter::stackElementSize);
442 }
444 void InterpreterMacroAssembler::push_ptr(Register r) {
445 sd(r, SP, - Interpreter::stackElementSize);
446 daddiu(SP, SP, - Interpreter::stackElementSize);
447 }
449 void InterpreterMacroAssembler::push_i(Register r) {
450 // 20170925: For compatibility reason, don't change to sw.
451 sd(r, SP, - Interpreter::stackElementSize);
452 daddiu(SP, SP, - Interpreter::stackElementSize);
453 }
455 void InterpreterMacroAssembler::push_l(Register r) {
456 sd(r, SP, -2 * Interpreter::stackElementSize);
457 daddiu(SP, SP, -2 * Interpreter::stackElementSize);
458 }
460 void InterpreterMacroAssembler::push_f(FloatRegister r) {
461 swc1(r, SP, - Interpreter::stackElementSize);
462 daddiu(SP, SP, - Interpreter::stackElementSize);
463 }
465 void InterpreterMacroAssembler::push_d(FloatRegister r) {
466 sdc1(r, SP, -2 * Interpreter::stackElementSize);
467 daddiu(SP, SP, -2 * Interpreter::stackElementSize);
468 }
470 void InterpreterMacroAssembler::pop(TosState state) {
471 switch (state) {
472 case atos: pop_ptr(); break;
473 case btos:
474 case ztos:
475 case ctos:
476 case stos:
477 case itos: pop_i(); break;
478 case ltos: pop_l(); break;
479 case ftos: pop_f(); break;
480 case dtos: pop_d(); break;
481 case vtos: /* nothing to do */ break;
482 default: ShouldNotReachHere();
483 }
484 verify_oop(FSR, state);
485 }
487 //FSR=V0,SSR=V1
488 void InterpreterMacroAssembler::push(TosState state) {
489 verify_oop(FSR, state);
490 switch (state) {
491 case atos: push_ptr(); break;
492 case btos:
493 case ztos:
494 case ctos:
495 case stos:
496 case itos: push_i(); break;
497 case ltos: push_l(); break;
498 case ftos: push_f(); break;
499 case dtos: push_d(); break;
500 case vtos: /* nothing to do */ break;
501 default : ShouldNotReachHere();
502 }
503 }
507 void InterpreterMacroAssembler::load_ptr(int n, Register val) {
508 ld(val, SP, Interpreter::expr_offset_in_bytes(n));
509 }
511 void InterpreterMacroAssembler::store_ptr(int n, Register val) {
512 sd(val, SP, Interpreter::expr_offset_in_bytes(n));
513 }
515 // Jump to from_interpreted entry of a call unless single stepping is possible
516 // in this thread in which case we must call the i2i entry
517 void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) {
518 // record last_sp
519 move(Rsender, SP);
520 sd(SP, FP, frame::interpreter_frame_last_sp_offset * wordSize);
522 if (JvmtiExport::can_post_interpreter_events()) {
523 Label run_compiled_code;
524 // JVMTI events, such as single-stepping, are implemented partly by avoiding running
525 // compiled code in threads for which the event is enabled. Check here for
526 // interp_only_mode if these events CAN be enabled.
527 #ifndef OPT_THREAD
528 get_thread(temp);
529 #else
530 move(temp, TREG);
531 #endif
532 // interp_only is an int, on little endian it is sufficient to test the byte only
533 // Is a cmpl faster?
534 lw(AT, temp, in_bytes(JavaThread::interp_only_mode_offset()));
535 beq(AT, R0, run_compiled_code);
536 delayed()->nop();
537 ld(AT, method, in_bytes(Method::interpreter_entry_offset()));
538 jr(AT);
539 delayed()->nop();
540 bind(run_compiled_code);
541 }
543 ld(AT, method, in_bytes(Method::from_interpreted_offset()));
544 jr(AT);
545 delayed()->nop();
546 }
549 // The following two routines provide a hook so that an implementation
550 // can schedule the dispatch in two parts. amd64 does not do this.
551 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) {
552 // Nothing amd64 specific to be done here
553 }
555 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) {
556 dispatch_next(state, step);
557 }
559 // assume the next bytecode in T8.
560 void InterpreterMacroAssembler::dispatch_base(TosState state,
561 address* table,
562 bool verifyoop) {
563 if (VerifyActivationFrameSize) {
564 Label L;
566 dsub(T2, FP, SP);
567 int min_frame_size = (frame::link_offset -
568 frame::interpreter_frame_initial_sp_offset) * wordSize;
569 daddi(T2, T2,- min_frame_size);
570 bgez(T2, L);
571 delayed()->nop();
572 stop("broken stack frame");
573 bind(L);
574 }
575 // FIXME: I do not know which register should pass to verify_oop
576 if (verifyoop) verify_oop(FSR, state);
577 dsll(T2, Rnext, LogBytesPerWord);
579 if((long)table >= (long)Interpreter::dispatch_table(btos) &&
580 (long)table <= (long)Interpreter::dispatch_table(vtos)
581 ) {
582 int table_size = (long)Interpreter::dispatch_table(itos) - (long)Interpreter::dispatch_table(stos);
583 int table_offset = ((int)state - (int)itos) * table_size;
585 // 2013/12/17 Fu: GP points to the starting address of Interpreter::dispatch_table(itos).
586 // See StubGenerator::generate_call_stub(address& return_address) for the initialization of GP.
587 if(table_offset != 0) {
588 daddiu(T3, GP, table_offset);
589 if (UseLoongsonISA) {
590 gsldx(T3, T2, T3, 0);
591 } else {
592 daddu(T3, T2, T3);
593 ld(T3, T3, 0);
594 }
595 } else {
596 if (UseLoongsonISA) {
597 gsldx(T3, T2, GP, 0);
598 } else {
599 daddu(T3, T2, GP);
600 ld(T3, T3, 0);
601 }
602 }
603 } else {
604 li(T3, (long)table);
605 if (UseLoongsonISA) {
606 gsldx(T3, T2, T3, 0);
607 } else {
608 daddu(T3, T2, T3);
609 ld(T3, T3, 0);
610 }
611 }
612 jr(T3);
613 delayed()->nop();
614 }
616 void InterpreterMacroAssembler::dispatch_only(TosState state) {
617 dispatch_base(state, Interpreter::dispatch_table(state));
618 }
620 void InterpreterMacroAssembler::dispatch_only_normal(TosState state) {
621 dispatch_base(state, Interpreter::normal_table(state));
622 }
624 void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) {
625 dispatch_base(state, Interpreter::normal_table(state), false);
626 }
629 void InterpreterMacroAssembler::dispatch_next(TosState state, int step) {
630 // load next bytecode (load before advancing r13 to prevent AGI)
631 lbu(Rnext, BCP, step);
632 increment(BCP, step);
633 dispatch_base(state, Interpreter::dispatch_table(state));
634 }
636 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
637 // load current bytecode
638 lbu(Rnext, BCP, 0);
639 dispatch_base(state, table);
640 }
642 // remove activation
643 //
644 // Unlock the receiver if this is a synchronized method.
645 // Unlock any Java monitors from syncronized blocks.
646 // Remove the activation from the stack.
647 //
648 // If there are locked Java monitors
649 // If throw_monitor_exception
650 // throws IllegalMonitorStateException
651 // Else if install_monitor_exception
652 // installs IllegalMonitorStateException
653 // Else
654 // no error processing
655 // used registers : T1, T2, T3, T8
656 // T1 : thread, method access flags
657 // T2 : monitor entry pointer
658 // T3 : method, monitor top
659 // T8 : unlock flag
660 void InterpreterMacroAssembler::remove_activation(
661 TosState state,
662 Register ret_addr,
663 bool throw_monitor_exception,
664 bool install_monitor_exception,
665 bool notify_jvmdi) {
666 // Note: Registers V0, V1 and F0, F1 may be in use for the result
667 // check if synchronized method
668 Label unlocked, unlock, no_unlock;
670 // get the value of _do_not_unlock_if_synchronized into T8
671 #ifndef OPT_THREAD
672 Register thread = T1;
673 get_thread(thread);
674 #else
675 Register thread = TREG;
676 #endif
677 lb(T8, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
678 // reset the flag
679 sb(R0, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
680 // get method access flags
681 ld(T3, FP, frame::interpreter_frame_method_offset * wordSize);
682 lw(T1, T3, in_bytes(Method::access_flags_offset()));
683 andi(T1, T1, JVM_ACC_SYNCHRONIZED);
684 beq(T1, R0, unlocked);
685 delayed()->nop();
687 // Don't unlock anything if the _do_not_unlock_if_synchronized flag is set.
688 bne(T8, R0, no_unlock);
689 delayed()->nop();
690 // unlock monitor
691 push(state); // save result
693 // BasicObjectLock will be first in list, since this is a
694 // synchronized method. However, need to check that the object has
695 // not been unlocked by an explicit monitorexit bytecode.
696 daddiu(c_rarg0, FP, frame::interpreter_frame_initial_sp_offset * wordSize
697 - (int)sizeof(BasicObjectLock));
698 // address of first monitor
699 lw(T1, c_rarg0, BasicObjectLock::obj_offset_in_bytes());
700 bne(T1, R0, unlock);
701 delayed()->nop();
702 pop(state);
703 if (throw_monitor_exception) {
704 // Entry already unlocked, need to throw exception
705 // I think mips do not need empty_FPU_stack
706 // remove possible return value from FPU-stack, otherwise stack could overflow
707 empty_FPU_stack();
708 call_VM(NOREG, CAST_FROM_FN_PTR(address,
709 InterpreterRuntime::throw_illegal_monitor_state_exception));
710 should_not_reach_here();
711 } else {
712 // Monitor already unlocked during a stack unroll. If requested,
713 // install an illegal_monitor_state_exception. Continue with
714 // stack unrolling.
715 if (install_monitor_exception) {
716 // remove possible return value from FPU-stack,
717 // otherwise stack could overflow
718 empty_FPU_stack();
719 call_VM(NOREG, CAST_FROM_FN_PTR(address,
720 InterpreterRuntime::new_illegal_monitor_state_exception));
722 }
724 b(unlocked);
725 delayed()->nop();
726 }
728 bind(unlock);
729 unlock_object(c_rarg0);
730 pop(state);
732 // Check that for block-structured locking (i.e., that all locked
733 // objects has been unlocked)
734 bind(unlocked);
736 // V0, V1: Might contain return value
738 // Check that all monitors are unlocked
739 {
740 Label loop, exception, entry, restart;
741 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
742 const Address monitor_block_top(FP,
743 frame::interpreter_frame_monitor_block_top_offset * wordSize);
745 bind(restart);
746 // points to current entry, starting with top-most entry (ecx)
747 ld(c_rarg0, monitor_block_top);
748 // points to word before bottom of monitor block (ebx)
749 daddiu(T3, FP, frame::interpreter_frame_initial_sp_offset * wordSize);
750 b(entry);
751 delayed()->nop();
753 // Entry already locked, need to throw exception
754 bind(exception);
756 if (throw_monitor_exception) {
757 // Throw exception
758 // remove possible return value from FPU-stack,
759 // otherwise stack could overflow
760 empty_FPU_stack();
761 MacroAssembler::call_VM(NOREG, CAST_FROM_FN_PTR(address,
762 InterpreterRuntime::throw_illegal_monitor_state_exception));
763 should_not_reach_here();
764 } else {
765 // Stack unrolling. Unlock object and install illegal_monitor_exception
766 // Unlock does not block, so don't have to worry about the frame
767 // We don't have to preserve eax, edx since we are going to
768 // throw an exception
769 unlock_object(c_rarg0);
770 if (install_monitor_exception) {
771 empty_FPU_stack();
772 call_VM(NOREG, CAST_FROM_FN_PTR(address,
773 InterpreterRuntime::new_illegal_monitor_state_exception));
774 }
776 b(restart);
777 delayed()->nop();
778 }
780 bind(loop);
781 ld(T1, c_rarg0, BasicObjectLock::obj_offset_in_bytes());
782 bne(T1, R0, exception);// check if current entry is used
783 delayed()->nop();
785 daddiu(c_rarg0, c_rarg0, entry_size);// otherwise advance to next entry
786 bind(entry);
787 bne(c_rarg0, T3, loop); // check if bottom reached
788 delayed()->nop(); // if not at bottom then check this entry
789 }
791 bind(no_unlock);
793 // jvmpi support (jvmdi does not generate MethodExit on exception / popFrame)
794 if (notify_jvmdi) {
795 notify_method_exit(false,state,NotifyJVMTI); // preserve TOSCA
796 } else {
797 notify_method_exit(false,state,SkipNotifyJVMTI);// preserve TOSCA
798 }
800 // remove activation
801 ld(SP, FP, frame::interpreter_frame_sender_sp_offset * wordSize);
802 ld(ret_addr, FP, frame::interpreter_frame_return_addr_offset * wordSize);
803 ld(FP, FP, frame::interpreter_frame_sender_fp_offset * wordSize);
804 }
806 #endif // C_INTERP
808 // Lock object
809 //
810 // Args:
811 // c_rarg1: BasicObjectLock to be used for locking
812 //
813 // Kills:
814 // rax
815 // c_rarg0, c_rarg1, c_rarg2, c_rarg3, .. (param regs)
816 // rscratch1, rscratch2 (scratch regs)
817 void InterpreterMacroAssembler::lock_object(Register lock_reg) {
818 assert(lock_reg == c_rarg0, "The argument is only for looks. It must be c_rarg0");
820 if (UseHeavyMonitors) {
821 call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
822 lock_reg);
823 } else {
824 Label done;
826 const Register swap_reg = T2; // Must use eax for cmpxchg instruction
827 const Register obj_reg = T1; // Will contain the oop
829 const int obj_offset = BasicObjectLock::obj_offset_in_bytes();
830 const int lock_offset = BasicObjectLock::lock_offset_in_bytes ();
831 const int mark_offset = lock_offset +
832 BasicLock::displaced_header_offset_in_bytes();
834 Label slow_case;
836 // Load object pointer into obj_reg %ecx
837 ld(obj_reg, lock_reg, obj_offset);
839 if (UseBiasedLocking) {
840 // Note: we use noreg for the temporary register since it's hard
841 // to come up with a free register on all incoming code paths
842 biased_locking_enter(lock_reg, obj_reg, swap_reg, noreg, false, done, &slow_case);
843 }
846 // Load (object->mark() | 1) into swap_reg %eax
847 ld(AT, obj_reg, 0);
848 ori(swap_reg, AT, 1);
851 // Save (object->mark() | 1) into BasicLock's displaced header
852 sd(swap_reg, lock_reg, mark_offset);
854 assert(lock_offset == 0, "displached header must be first word in BasicObjectLock");
855 //if (os::is_MP()) {
856 // lock();
857 //}
858 cmpxchg(lock_reg, Address(obj_reg, 0), swap_reg);
860 if (PrintBiasedLockingStatistics) {
861 Label L;
862 beq(AT, R0, L);
863 delayed()->nop();
864 push(T0);
865 push(T1);
866 atomic_inc32((address)BiasedLocking::fast_path_entry_count_addr(), 1, T0, T1);
867 pop(T1);
868 pop(T0);
869 bind(L);
870 }
872 bne(AT, R0, done);
873 delayed()->nop();
875 // Test if the oopMark is an obvious stack pointer, i.e.,
876 // 1) (mark & 3) == 0, and
877 // 2) SP <= mark < SP + os::pagesize()
878 //
879 // These 3 tests can be done by evaluating the following
880 // expression: ((mark - esp) & (3 - os::vm_page_size())),
881 // assuming both stack pointer and pagesize have their
882 // least significant 2 bits clear.
883 // NOTE: the oopMark is in swap_reg %eax as the result of cmpxchg
885 dsub(swap_reg, swap_reg, SP);
886 move(AT, 3 - os::vm_page_size());
887 andr(swap_reg, swap_reg, AT);
888 // Save the test result, for recursive case, the result is zero
889 sd(swap_reg, lock_reg, mark_offset);
890 if (PrintBiasedLockingStatistics) {
891 Label L;
892 bne(swap_reg, R0, L);
893 delayed()->nop();
894 push(T0);
895 push(T1);
896 atomic_inc32((address)BiasedLocking::fast_path_entry_count_addr(), 1, T0, T1);
897 pop(T1);
898 pop(T0);
899 bind(L);
900 }
902 beq(swap_reg, R0, done);
903 delayed()->nop();
904 bind(slow_case);
905 // Call the runtime routine for slow case
906 call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), lock_reg);
908 bind(done);
909 }
910 }
913 // Unlocks an object. Used in monitorexit bytecode and
914 // remove_activation. Throws an IllegalMonitorException if object is
915 // not locked by current thread.
916 //
917 // Args:
918 // c_rarg1: BasicObjectLock for lock
919 //
920 // Kills:
921 // rax
922 // c_rarg0, c_rarg1, c_rarg2, c_rarg3, ... (param regs)
923 // rscratch1, rscratch2 (scratch regs)
924 // Argument: T6 : Points to BasicObjectLock structure for lock
925 // Argument: c_rarg0 : Points to BasicObjectLock structure for lock
926 // Throw an IllegalMonitorException if object is not locked by current thread
927 void InterpreterMacroAssembler::unlock_object(Register lock_reg) {
928 assert(lock_reg == c_rarg0, "The argument is only for looks. It must be c_rarg0");
930 if (UseHeavyMonitors) {
931 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
932 } else {
933 Label done;
935 const Register swap_reg = T2; // Must use eax for cmpxchg instruction
936 const Register header_reg = T3; // Will contain the old oopMark
937 const Register obj_reg = T1; // Will contain the oop
939 save_bcp(); // Save in case of exception
941 // Convert from BasicObjectLock structure to object and BasicLock structure
942 // Store the BasicLock address into %eax
943 daddi(swap_reg, lock_reg, BasicObjectLock::lock_offset_in_bytes());
945 // Load oop into obj_reg(%ecx)
946 ld(obj_reg, lock_reg, BasicObjectLock::obj_offset_in_bytes ());
947 //free entry
948 sd(R0, lock_reg, BasicObjectLock::obj_offset_in_bytes());
949 if (UseBiasedLocking) {
950 biased_locking_exit(obj_reg, header_reg, done);
951 }
953 // Load the old header from BasicLock structure
954 ld(header_reg, swap_reg, BasicLock::displaced_header_offset_in_bytes());
955 // zero for recursive case
956 beq(header_reg, R0, done);
957 delayed()->nop();
959 // Atomic swap back the old header
960 if (os::is_MP()); //lock();
961 cmpxchg(header_reg, Address(obj_reg, 0), swap_reg);
963 // zero for recursive case
964 bne(AT, R0, done);
965 delayed()->nop();
967 // Call the runtime routine for slow case.
968 sd(obj_reg, lock_reg, BasicObjectLock::obj_offset_in_bytes()); // restore obj
969 call_VM(NOREG,
970 CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
971 lock_reg);
973 bind(done);
975 restore_bcp();
976 }
977 }
979 #ifndef CC_INTERP
981 void InterpreterMacroAssembler::test_method_data_pointer(Register mdp,
982 Label& zero_continue) {
983 assert(ProfileInterpreter, "must be profiling interpreter");
984 ld(mdp, Address(FP, frame::interpreter_frame_mdx_offset * wordSize));
985 beq(mdp, R0, zero_continue);
986 delayed()->nop();
987 }
990 // Set the method data pointer for the current bcp.
991 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
992 assert(ProfileInterpreter, "must be profiling interpreter");
993 Label set_mdp;
995 // V0 and T0 will be used as two temporary registers.
996 sd(V0, SP, (-1) * wordSize);
997 sd(T0, SP, (-2) * wordSize);
998 daddiu(SP, SP, (-2) * wordSize);
1000 get_method(T0);
1001 // Test MDO to avoid the call if it is NULL.
1002 ld(V0, T0, in_bytes(Method::method_data_offset()));
1003 beq(V0, R0, set_mdp);
1004 delayed()->nop();
1006 // method: T0
1007 // bcp: BCP --> S0
1008 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), T0, BCP);
1009 // mdi: V0
1010 // mdo is guaranteed to be non-zero here, we checked for it before the call.
1011 get_method(T0);
1012 ld(T0, T0, in_bytes(Method::method_data_offset()));
1013 daddiu(T0, T0, in_bytes(MethodData::data_offset()));
1014 daddu(V0, T0, V0);
1015 bind(set_mdp);
1016 sd(V0, FP, frame::interpreter_frame_mdx_offset * wordSize);
1017 daddiu(SP, SP, 2 * wordSize);
1018 ld(V0, SP, (-1) * wordSize);
1019 ld(T0, SP, (-2) * wordSize);
1020 }
1022 void InterpreterMacroAssembler::verify_method_data_pointer() {
1023 assert(ProfileInterpreter, "must be profiling interpreter");
1024 #ifdef ASSERT
1025 Label verify_continue;
1026 Register method = V0;
1027 Register mdp = V1;
1028 Register tmp = A0;
1029 push(method);
1030 push(mdp);
1031 push(tmp);
1032 test_method_data_pointer(mdp, verify_continue); // If mdp is zero, continue
1033 get_method(method);
1035 // If the mdp is valid, it will point to a DataLayout header which is
1036 // consistent with the bcp. The converse is highly probable also.
1037 lhu(tmp, mdp, in_bytes(DataLayout::bci_offset()));
1038 ld(AT, method, in_bytes(Method::const_offset()));
1039 daddu(tmp, tmp, AT);
1040 daddiu(tmp, tmp, in_bytes(ConstMethod::codes_offset()));
1041 beq(tmp, BCP, verify_continue);
1042 delayed()->nop();
1043 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp), method, BCP, mdp);
1044 bind(verify_continue);
1045 pop(tmp);
1046 pop(mdp);
1047 pop(method);
1048 #endif // ASSERT
1049 }
1052 void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in,
1053 int constant,
1054 Register value) {
1055 assert(ProfileInterpreter, "must be profiling interpreter");
1056 Address data(mdp_in, constant);
1057 sd(value, data);
1058 }
1061 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
1062 int constant,
1063 bool decrement) {
1064 // Counter address
1065 Address data(mdp_in, constant);
1067 increment_mdp_data_at(data, decrement);
1068 }
1070 void InterpreterMacroAssembler::increment_mdp_data_at(Address data,
1071 bool decrement) {
1072 assert(ProfileInterpreter, "must be profiling interpreter");
1073 // %%% this does 64bit counters at best it is wasting space
1074 // at worst it is a rare bug when counters overflow
1075 Register tmp = S0;
1076 push(tmp);
1077 if (decrement) {
1078 // Decrement the register.
1079 ld(AT, data);
1080 daddiu(tmp, AT, (int32_t) -DataLayout::counter_increment);
1081 // If the decrement causes the counter to overflow, stay negative
1082 Label L;
1083 slt(AT, tmp, R0);
1084 bne(AT, R0, L);
1085 delayed()->nop();
1086 daddi(tmp, tmp, (int32_t) DataLayout::counter_increment);
1087 bind(L);
1088 sd(tmp, data);
1089 } else {
1090 assert(DataLayout::counter_increment == 1,
1091 "flow-free idiom only works with 1");
1092 ld(AT, data);
1093 // Increment the register.
1094 daddiu(tmp, AT, DataLayout::counter_increment);
1095 // If the increment causes the counter to overflow, pull back by 1.
1096 slt(AT, tmp, R0);
1097 dsubu(tmp, tmp, AT);
1098 sd(tmp, data);
1099 }
1100 pop(tmp);
1101 }
1104 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
1105 Register reg,
1106 int constant,
1107 bool decrement) {
1108 Register tmp = S0;
1109 push(S0);
1110 if (decrement) {
1111 // Decrement the register.
1112 daddu(AT, mdp_in, reg);
1113 assert(Assembler::is_simm16(constant), "constant is not a simm16 !");
1114 ld(AT, AT, constant);
1116 daddiu(tmp, AT, (int32_t) -DataLayout::counter_increment);
1117 // If the decrement causes the counter to overflow, stay negative
1118 Label L;
1119 slt(AT, tmp, R0);
1120 bne(AT, R0, L);
1121 delayed()->nop();
1122 daddi(tmp, tmp, (int32_t) DataLayout::counter_increment);
1123 bind(L);
1125 daddu(AT, mdp_in, reg);
1126 sd(tmp, AT, constant);
1127 } else {
1128 daddu(AT, mdp_in, reg);
1129 assert(Assembler::is_simm16(constant), "constant is not a simm16 !");
1130 ld(AT, AT, constant);
1132 // Increment the register.
1133 daddiu(tmp, AT, DataLayout::counter_increment);
1134 // If the increment causes the counter to overflow, pull back by 1.
1135 slt(AT, tmp, R0);
1136 dsubu(tmp, tmp, AT);
1138 daddu(AT, mdp_in, reg);
1139 sd(tmp, AT, constant);
1140 }
1141 pop(S0);
1142 }
1144 void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in,
1145 int flag_byte_constant) {
1146 assert(ProfileInterpreter, "must be profiling interpreter");
1147 int header_offset = in_bytes(DataLayout::header_offset());
1148 int header_bits = DataLayout::flag_mask_to_header_mask(flag_byte_constant);
1149 // Set the flag
1150 lw(AT, Address(mdp_in, header_offset));
1151 if(Assembler::is_simm16(header_bits)) {
1152 ori(AT, AT, header_bits);
1153 } else {
1154 push(T8);
1155 // T8 is used as a temporary register.
1156 move(T8, header_bits);
1157 orr(AT, AT, T8);
1158 pop(T8);
1159 }
1160 sw(AT, Address(mdp_in, header_offset));
1161 }
1165 void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in,
1166 int offset,
1167 Register value,
1168 Register test_value_out,
1169 Label& not_equal_continue) {
1170 assert(ProfileInterpreter, "must be profiling interpreter");
1171 if (test_value_out == noreg) {
1172 ld(AT, Address(mdp_in, offset));
1173 bne(AT, value, not_equal_continue);
1174 delayed()->nop();
1175 } else {
1176 // Put the test value into a register, so caller can use it:
1177 ld(test_value_out, Address(mdp_in, offset));
1178 bne(value, test_value_out, not_equal_continue);
1179 delayed()->nop();
1180 }
1181 }
1184 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
1185 int offset_of_disp) {
1186 assert(ProfileInterpreter, "must be profiling interpreter");
1187 assert(Assembler::is_simm16(offset_of_disp), "offset is not an simm16");
1188 ld(AT, mdp_in, offset_of_disp);
1189 daddu(mdp_in, mdp_in, AT);
1190 sd(mdp_in, Address(FP, frame::interpreter_frame_mdx_offset * wordSize));
1191 }
1194 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
1195 Register reg,
1196 int offset_of_disp) {
1197 assert(ProfileInterpreter, "must be profiling interpreter");
1198 // Attention: Until now (20121217), we do not support this kind of addressing on Loongson.
1199 // Address disp_address(mdp_in, reg, Address::times_1, offset_of_disp);
1200 daddu(AT, reg, mdp_in);
1201 assert(Assembler::is_simm16(offset_of_disp), "offset is not an simm16");
1202 ld(AT, AT, offset_of_disp);
1203 daddu(mdp_in, mdp_in, AT);
1204 sd(mdp_in, Address(FP, frame::interpreter_frame_mdx_offset * wordSize));
1205 }
1208 void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in,
1209 int constant) {
1210 assert(ProfileInterpreter, "must be profiling interpreter");
1211 if(Assembler::is_simm16(constant)) {
1212 daddiu(mdp_in, mdp_in, constant);
1213 } else {
1214 move(AT, constant);
1215 daddu(mdp_in, mdp_in, AT);
1216 }
1217 sd(mdp_in, Address(FP, frame::interpreter_frame_mdx_offset * wordSize));
1218 }
1221 void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) {
1222 assert(ProfileInterpreter, "must be profiling interpreter");
1223 push(return_bci); // save/restore across call_VM
1224 call_VM(noreg,
1225 CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret),
1226 return_bci);
1227 pop(return_bci);
1228 }
1231 void InterpreterMacroAssembler::profile_taken_branch(Register mdp,
1232 Register bumped_count) {
1233 if (ProfileInterpreter) {
1234 Label profile_continue;
1236 // If no method data exists, go to profile_continue.
1237 // Otherwise, assign to mdp
1238 test_method_data_pointer(mdp, profile_continue);
1240 // We are taking a branch. Increment the taken count.
1241 // We inline increment_mdp_data_at to return bumped_count in a register
1242 //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
1243 ld(bumped_count, mdp, in_bytes(JumpData::taken_offset()));
1244 assert(DataLayout::counter_increment == 1,
1245 "flow-free idiom only works with 1");
1246 push(T8);
1247 // T8 is used as a temporary register.
1248 daddiu(T8, bumped_count, DataLayout::counter_increment);
1249 slt(AT, T8, R0);
1250 dsubu(bumped_count, T8, AT);
1251 pop(T8);
1252 sd(bumped_count, mdp, in_bytes(JumpData::taken_offset())); // Store back out
1253 // The method data pointer needs to be updated to reflect the new target.
1254 update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
1255 bind(profile_continue);
1256 }
1257 }
1260 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) {
1261 if (ProfileInterpreter) {
1262 Label profile_continue;
1264 // If no method data exists, go to profile_continue.
1265 test_method_data_pointer(mdp, profile_continue);
1267 // We are taking a branch. Increment the not taken count.
1268 increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
1270 // The method data pointer needs to be updated to correspond to
1271 // the next bytecode
1272 update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size()));
1273 bind(profile_continue);
1274 }
1275 }
1278 void InterpreterMacroAssembler::profile_call(Register mdp) {
1279 if (ProfileInterpreter) {
1280 Label profile_continue;
1282 // If no method data exists, go to profile_continue.
1283 test_method_data_pointer(mdp, profile_continue);
1285 // We are making a call. Increment the count.
1286 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1288 // The method data pointer needs to be updated to reflect the new target.
1289 update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
1290 bind(profile_continue);
1291 }
1292 }
1295 void InterpreterMacroAssembler::profile_final_call(Register mdp) {
1296 if (ProfileInterpreter) {
1297 Label profile_continue;
1299 // If no method data exists, go to profile_continue.
1300 test_method_data_pointer(mdp, profile_continue);
1302 // We are making a call. Increment the count.
1303 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1305 // The method data pointer needs to be updated to reflect the new target.
1306 update_mdp_by_constant(mdp,
1307 in_bytes(VirtualCallData::
1308 virtual_call_data_size()));
1309 bind(profile_continue);
1310 }
1311 }
1314 void InterpreterMacroAssembler::profile_virtual_call(Register receiver,
1315 Register mdp,
1316 Register reg2,
1317 bool receiver_can_be_null) {
1318 if (ProfileInterpreter) {
1319 Label profile_continue;
1321 // If no method data exists, go to profile_continue.
1322 test_method_data_pointer(mdp, profile_continue);
1324 Label skip_receiver_profile;
1325 if (receiver_can_be_null) {
1326 Label not_null;
1327 bne(receiver, R0, not_null);
1328 delayed()->nop();
1329 // We are making a call. Increment the count.
1330 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1331 beq(R0, R0, skip_receiver_profile);
1332 delayed()->nop();
1333 bind(not_null);
1334 }
1336 // Record the receiver type.
1337 record_klass_in_profile(receiver, mdp, reg2, true);
1338 bind(skip_receiver_profile);
1340 // The method data pointer needs to be updated to reflect the new target.
1341 update_mdp_by_constant(mdp,
1342 in_bytes(VirtualCallData::
1343 virtual_call_data_size()));
1344 bind(profile_continue);
1345 }
1346 }
1348 // This routine creates a state machine for updating the multi-row
1349 // type profile at a virtual call site (or other type-sensitive bytecode).
1350 // The machine visits each row (of receiver/count) until the receiver type
1351 // is found, or until it runs out of rows. At the same time, it remembers
1352 // the location of the first empty row. (An empty row records null for its
1353 // receiver, and can be allocated for a newly-observed receiver type.)
1354 // Because there are two degrees of freedom in the state, a simple linear
1355 // search will not work; it must be a decision tree. Hence this helper
1356 // function is recursive, to generate the required tree structured code.
1357 // It's the interpreter, so we are trading off code space for speed.
1358 // See below for example code.
1359 void InterpreterMacroAssembler::record_klass_in_profile_helper(
1360 Register receiver, Register mdp,
1361 Register reg2, int start_row,
1362 Label& done, bool is_virtual_call) {
1363 if (TypeProfileWidth == 0) {
1364 if (is_virtual_call) {
1365 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1366 }
1367 return;
1368 }
1370 int last_row = VirtualCallData::row_limit() - 1;
1371 assert(start_row <= last_row, "must be work left to do");
1372 // Test this row for both the receiver and for null.
1373 // Take any of three different outcomes:
1374 // 1. found receiver => increment count and goto done
1375 // 2. found null => keep looking for case 1, maybe allocate this cell
1376 // 3. found something else => keep looking for cases 1 and 2
1377 // Case 3 is handled by a recursive call.
1378 for (int row = start_row; row <= last_row; row++) {
1379 Label next_test;
1380 bool test_for_null_also = (row == start_row);
1382 // See if the receiver is receiver[n].
1383 int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row));
1384 test_mdp_data_at(mdp, recvr_offset, receiver,
1385 (test_for_null_also ? reg2 : noreg),
1386 next_test);
1387 // (Reg2 now contains the receiver from the CallData.)
1389 // The receiver is receiver[n]. Increment count[n].
1390 int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row));
1391 increment_mdp_data_at(mdp, count_offset);
1392 beq(R0, R0, done);
1393 delayed()->nop();
1394 bind(next_test);
1396 if (test_for_null_also) {
1397 Label found_null;
1398 // Failed the equality check on receiver[n]... Test for null.
1399 if (start_row == last_row) {
1400 // The only thing left to do is handle the null case.
1401 if (is_virtual_call) {
1402 beq(reg2, R0, found_null);
1403 delayed()->nop();
1404 // Receiver did not match any saved receiver and there is no empty row for it.
1405 // Increment total counter to indicate polymorphic case.
1406 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1407 beq(R0, R0, done);
1408 delayed()->nop();
1409 bind(found_null);
1410 } else {
1411 bne(reg2, R0, done);
1412 delayed()->nop();
1413 }
1414 break;
1415 }
1416 // Since null is rare, make it be the branch-taken case.
1417 beq(reg2, R0, found_null);
1418 delayed()->nop();
1420 // Put all the "Case 3" tests here.
1421 record_klass_in_profile_helper(receiver, mdp, reg2, start_row + 1, done, is_virtual_call);
1423 // Found a null. Keep searching for a matching receiver,
1424 // but remember that this is an empty (unused) slot.
1425 bind(found_null);
1426 }
1427 }
1429 // In the fall-through case, we found no matching receiver, but we
1430 // observed the receiver[start_row] is NULL.
1432 // Fill in the receiver field and increment the count.
1433 int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row));
1434 set_mdp_data_at(mdp, recvr_offset, receiver);
1435 int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row));
1436 move(reg2, DataLayout::counter_increment);
1437 set_mdp_data_at(mdp, count_offset, reg2);
1438 if (start_row > 0) {
1439 beq(R0, R0, done);
1440 delayed()->nop();
1441 }
1442 }
1444 // Example state machine code for three profile rows:
1445 // // main copy of decision tree, rooted at row[1]
1446 // if (row[0].rec == rec) { row[0].incr(); goto done; }
1447 // if (row[0].rec != NULL) {
1448 // // inner copy of decision tree, rooted at row[1]
1449 // if (row[1].rec == rec) { row[1].incr(); goto done; }
1450 // if (row[1].rec != NULL) {
1451 // // degenerate decision tree, rooted at row[2]
1452 // if (row[2].rec == rec) { row[2].incr(); goto done; }
1453 // if (row[2].rec != NULL) { goto done; } // overflow
1454 // row[2].init(rec); goto done;
1455 // } else {
1456 // // remember row[1] is empty
1457 // if (row[2].rec == rec) { row[2].incr(); goto done; }
1458 // row[1].init(rec); goto done;
1459 // }
1460 // } else {
1461 // // remember row[0] is empty
1462 // if (row[1].rec == rec) { row[1].incr(); goto done; }
1463 // if (row[2].rec == rec) { row[2].incr(); goto done; }
1464 // row[0].init(rec); goto done;
1465 // }
1466 // done:
1468 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,
1469 Register mdp, Register reg2,
1470 bool is_virtual_call) {
1471 assert(ProfileInterpreter, "must be profiling");
1472 Label done;
1474 record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call);
1476 bind (done);
1477 }
1479 void InterpreterMacroAssembler::profile_ret(Register return_bci,
1480 Register mdp) {
1481 if (ProfileInterpreter) {
1482 Label profile_continue;
1483 uint row;
1485 // If no method data exists, go to profile_continue.
1486 test_method_data_pointer(mdp, profile_continue);
1488 // Update the total ret count.
1489 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1491 for (row = 0; row < RetData::row_limit(); row++) {
1492 Label next_test;
1494 // See if return_bci is equal to bci[n]:
1495 test_mdp_data_at(mdp,
1496 in_bytes(RetData::bci_offset(row)),
1497 return_bci, noreg,
1498 next_test);
1500 // return_bci is equal to bci[n]. Increment the count.
1501 increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row)));
1503 // The method data pointer needs to be updated to reflect the new target.
1504 update_mdp_by_offset(mdp,
1505 in_bytes(RetData::bci_displacement_offset(row)));
1506 beq(R0, R0, profile_continue);
1507 delayed()->nop();
1508 bind(next_test);
1509 }
1511 update_mdp_for_ret(return_bci);
1513 bind(profile_continue);
1514 }
1515 }
1518 void InterpreterMacroAssembler::profile_null_seen(Register mdp) {
1519 if (ProfileInterpreter) {
1520 Label profile_continue;
1522 // If no method data exists, go to profile_continue.
1523 test_method_data_pointer(mdp, profile_continue);
1525 set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
1527 // The method data pointer needs to be updated.
1528 int mdp_delta = in_bytes(BitData::bit_data_size());
1529 if (TypeProfileCasts) {
1530 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1531 }
1532 update_mdp_by_constant(mdp, mdp_delta);
1534 bind(profile_continue);
1535 }
1536 }
1539 void InterpreterMacroAssembler::profile_typecheck_failed(Register mdp) {
1540 if (ProfileInterpreter && TypeProfileCasts) {
1541 Label profile_continue;
1543 // If no method data exists, go to profile_continue.
1544 test_method_data_pointer(mdp, profile_continue);
1546 int count_offset = in_bytes(CounterData::count_offset());
1547 // Back up the address, since we have already bumped the mdp.
1548 count_offset -= in_bytes(VirtualCallData::virtual_call_data_size());
1550 // *Decrement* the counter. We expect to see zero or small negatives.
1551 increment_mdp_data_at(mdp, count_offset, true);
1553 bind (profile_continue);
1554 }
1555 }
1558 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) {
1559 if (ProfileInterpreter) {
1560 Label profile_continue;
1562 // If no method data exists, go to profile_continue.
1563 test_method_data_pointer(mdp, profile_continue);
1565 // The method data pointer needs to be updated.
1566 int mdp_delta = in_bytes(BitData::bit_data_size());
1567 if (TypeProfileCasts) {
1568 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1570 // Record the object type.
1571 record_klass_in_profile(klass, mdp, reg2, false);
1572 }
1573 update_mdp_by_constant(mdp, mdp_delta);
1575 bind(profile_continue);
1576 }
1577 }
1580 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
1581 if (ProfileInterpreter) {
1582 Label profile_continue;
1584 // If no method data exists, go to profile_continue.
1585 test_method_data_pointer(mdp, profile_continue);
1587 // Update the default case count
1588 increment_mdp_data_at(mdp,
1589 in_bytes(MultiBranchData::default_count_offset()));
1591 // The method data pointer needs to be updated.
1592 update_mdp_by_offset(mdp,
1593 in_bytes(MultiBranchData::
1594 default_displacement_offset()));
1596 bind(profile_continue);
1597 }
1598 }
1601 void InterpreterMacroAssembler::profile_switch_case(Register index,
1602 Register mdp,
1603 Register reg2) {
1604 if (ProfileInterpreter) {
1605 Label profile_continue;
1607 // If no method data exists, go to profile_continue.
1608 test_method_data_pointer(mdp, profile_continue);
1610 // Build the base (index * per_case_size_in_bytes()) +
1611 // case_array_offset_in_bytes()
1612 move(reg2, in_bytes(MultiBranchData::per_case_size()));
1613 if (UseLoongsonISA) {
1614 gsdmult(index, index, reg2);
1615 } else {
1616 dmult(index, reg2);
1617 mflo(index);
1618 }
1619 daddiu(index, index, in_bytes(MultiBranchData::case_array_offset()));
1621 // Update the case count
1622 increment_mdp_data_at(mdp,
1623 index,
1624 in_bytes(MultiBranchData::relative_count_offset()));
1626 // The method data pointer needs to be updated.
1627 update_mdp_by_offset(mdp,
1628 index,
1629 in_bytes(MultiBranchData::
1630 relative_displacement_offset()));
1632 bind(profile_continue);
1633 }
1634 }
1637 void InterpreterMacroAssembler::narrow(Register result) {
1639 // Get method->_constMethod->_result_type
1640 ld(T9, FP, frame::interpreter_frame_method_offset * wordSize);
1641 ld(T9, T9, in_bytes(Method::const_offset()));
1642 lbu(T9, T9, in_bytes(ConstMethod::result_type_offset()));
1644 Label done, notBool, notByte, notChar;
1646 // common case first
1647 addiu(AT, T9, -T_INT);
1648 beq(AT, R0, done);
1649 delayed()->nop();
1651 // mask integer result to narrower return type.
1652 addiu(AT, T9, -T_BOOLEAN);
1653 bne(AT, R0, notBool);
1654 delayed()->nop();
1655 andi(result, result, 0x1);
1656 beq(R0, R0, done);
1657 delayed()->nop();
1659 bind(notBool);
1660 addiu(AT, T9, -T_BYTE);
1661 bne(AT, R0, notByte);
1662 delayed()->nop();
1663 seb(result, result);
1664 beq(R0, R0, done);
1665 delayed()->nop();
1667 bind(notByte);
1668 addiu(AT, T9, -T_CHAR);
1669 bne(AT, R0, notChar);
1670 delayed()->nop();
1671 andi(result, result, 0xFFFF);
1672 beq(R0, R0, done);
1673 delayed()->nop();
1675 bind(notChar);
1676 seh(result, result);
1678 // Nothing to do for T_INT
1679 bind(done);
1680 }
1683 void InterpreterMacroAssembler::profile_obj_type(Register obj, const Address& mdo_addr) {
1684 Label update, next, none;
1686 verify_oop(obj);
1688 bne(obj, R0, update);
1689 delayed()->nop();
1691 push(T1);
1692 if (mdo_addr.index() == noreg) {
1693 ld(T1, mdo_addr);
1694 } else {
1695 guarantee(T1 != mdo_addr.base(), "The base register will be corrupted !");
1696 guarantee(T1 != mdo_addr.index(), "The index register will be corrupted !");
1698 dsll(AT, mdo_addr.index(), mdo_addr.scale());
1699 daddu(AT, AT, mdo_addr.base());
1700 ld(T1, AT, mdo_addr.disp());
1701 }
1702 li(AT, TypeEntries::null_seen);
1703 orr(AT, T1, AT);
1704 if (mdo_addr.index() == noreg) {
1705 sd(AT, mdo_addr);
1706 } else {
1707 guarantee(T1 != mdo_addr.base(), "The base register will be corrupted !");
1708 guarantee(T1 != mdo_addr.index(), "The index register will be corrupted !");
1710 dsll(T1, mdo_addr.index(), mdo_addr.scale());
1711 daddu(T1, T1, mdo_addr.base());
1712 sd(AT, T1, mdo_addr.disp());
1713 }
1714 pop(T1);
1716 beq(R0, R0, next);
1717 delayed()->nop();
1719 bind(update);
1720 load_klass(obj, obj);
1722 if (mdo_addr.index() == noreg) {
1723 ld(AT, mdo_addr);
1724 } else {
1725 dsll(AT, mdo_addr.index(), mdo_addr.scale());
1726 daddu(AT, AT, mdo_addr.base());
1727 ld(AT, AT, mdo_addr.disp());
1728 }
1729 xorr(obj, obj, AT);
1731 li(AT, TypeEntries::type_klass_mask);
1732 andr(AT, obj, AT);
1733 beq(AT, R0, next);
1734 delayed()->nop();
1736 li(AT, TypeEntries::type_unknown);
1737 andr(AT, AT, obj);
1738 bne(AT, R0, next);
1739 delayed()->nop();
1741 if (mdo_addr.index() == noreg) {
1742 ld(AT, mdo_addr);
1743 } else {
1744 dsll(AT, mdo_addr.index(), mdo_addr.scale());
1745 daddu(AT, AT, mdo_addr.base());
1746 ld(AT, AT, mdo_addr.disp());
1747 }
1748 beq(AT, R0, none);
1749 delayed()->nop();
1752 push(T1);
1753 if (mdo_addr.index() == noreg) {
1754 ld(T1, mdo_addr);
1755 } else {
1756 guarantee(T1 != mdo_addr.base(), "The base register will be corrupted !");
1757 guarantee(T1 != mdo_addr.index(), "The index register will be corrupted !");
1759 dsll(AT, mdo_addr.index(), mdo_addr.scale());
1760 daddu(AT, AT, mdo_addr.base());
1761 ld(T1, AT, mdo_addr.disp());
1762 }
1763 li(AT, TypeEntries::null_seen);
1764 subu(AT, AT, T1);
1765 pop(T1);
1766 beq(AT, R0, none);
1767 delayed()->nop();
1769 // There is a chance that the checks above (re-reading profiling
1770 // data from memory) fail if another thread has just set the
1771 // profiling to this obj's klass
1772 if (mdo_addr.index() == noreg) {
1773 ld(AT, mdo_addr);
1774 } else {
1775 dsll(AT, mdo_addr.index(), mdo_addr.scale());
1776 daddu(AT, AT, mdo_addr.base());
1777 ld(AT, AT, mdo_addr.disp());
1778 }
1779 xorr(obj, obj, AT);
1780 li(AT, TypeEntries::type_klass_mask);
1781 andr(AT, obj, AT);
1782 beq(AT, R0, next);
1783 delayed()->nop();
1785 // different than before. Cannot keep accurate profile.
1786 push(T1);
1787 if (mdo_addr.index() == noreg) {
1788 ld(T1, mdo_addr);
1789 } else {
1790 guarantee(T1 != mdo_addr.base(), "The base register will be corrupted !");
1791 guarantee(T1 != mdo_addr.index(), "The index register will be corrupted !");
1793 dsll(AT, mdo_addr.index(), mdo_addr.scale());
1794 daddu(AT, AT, mdo_addr.base());
1795 ld(T1, AT, mdo_addr.disp());
1796 }
1797 li(AT, TypeEntries::type_unknown);
1798 orr(AT, T1, AT);
1799 if (mdo_addr.index() == noreg) {
1800 sd(AT, mdo_addr);
1801 } else {
1802 guarantee(T1 != mdo_addr.base(), "The base register will be corrupted !");
1803 guarantee(T1 != mdo_addr.index(), "The index register will be corrupted !");
1805 dsll(T1, mdo_addr.index(), mdo_addr.scale());
1806 daddu(T1, T1, mdo_addr.base());
1807 sd(AT, T1, mdo_addr.disp());
1808 }
1809 pop(T1);
1810 beq(R0, R0, next);
1811 delayed()->nop();
1814 bind(none);
1815 // first time here. Set profile type.
1816 if (mdo_addr.index() == noreg) {
1817 sd(obj, mdo_addr);
1818 } else {
1819 dsll(AT, mdo_addr.index(), mdo_addr.scale());
1820 daddu(AT, AT, mdo_addr.base());
1821 sd(obj, AT, mdo_addr.disp());
1822 }
1824 bind(next);
1825 }
1827 void InterpreterMacroAssembler::profile_arguments_type(Register mdp, Register callee, Register tmp, bool is_virtual) {
1828 if (!ProfileInterpreter) {
1829 return;
1830 }
1832 if (MethodData::profile_arguments() || MethodData::profile_return()) {
1833 Label profile_continue;
1835 test_method_data_pointer(mdp, profile_continue);
1837 int off_to_start = is_virtual ? in_bytes(VirtualCallData::virtual_call_data_size()) : in_bytes(CounterData::counter_data_size());
1839 lb(AT, mdp, in_bytes(DataLayout::tag_offset()) - off_to_start);
1840 li(tmp, is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag);
1841 bne(tmp, AT, profile_continue);
1842 delayed()->nop();
1845 if (MethodData::profile_arguments()) {
1846 Label done;
1847 int off_to_args = in_bytes(TypeEntriesAtCall::args_data_offset());
1848 if (Assembler::is_simm16(off_to_args)) {
1849 daddiu(mdp, mdp, off_to_args);
1850 } else {
1851 move(AT, off_to_args);
1852 daddu(mdp, mdp, AT);
1853 }
1856 for (int i = 0; i < TypeProfileArgsLimit; i++) {
1857 if (i > 0 || MethodData::profile_return()) {
1858 // If return value type is profiled we may have no argument to profile
1859 ld(tmp, mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args);
1861 if (Assembler::is_simm16(-1 * i * TypeStackSlotEntries::per_arg_count())) {
1862 addiu32(tmp, tmp, -1 * i * TypeStackSlotEntries::per_arg_count());
1863 } else {
1864 li(AT, i*TypeStackSlotEntries::per_arg_count());
1865 subu32(tmp, tmp, AT);
1866 }
1868 li(AT, TypeStackSlotEntries::per_arg_count());
1869 slt(AT, tmp, AT);
1870 bne(AT, R0, done);
1871 delayed()->nop();
1872 }
1873 ld(tmp, callee, in_bytes(Method::const_offset()));
1875 lhu(tmp, tmp, in_bytes(ConstMethod::size_of_parameters_offset()));
1877 // stack offset o (zero based) from the start of the argument
1878 // list, for n arguments translates into offset n - o - 1 from
1879 // the end of the argument list
1880 ld(AT, mdp, in_bytes(TypeEntriesAtCall::stack_slot_offset(i))-off_to_args);
1881 subu(tmp, tmp, AT);
1883 addiu32(tmp, tmp, -1);
1885 Address arg_addr = argument_address(tmp);
1886 ld(tmp, arg_addr);
1888 Address mdo_arg_addr(mdp, in_bytes(TypeEntriesAtCall::argument_type_offset(i))-off_to_args);
1889 profile_obj_type(tmp, mdo_arg_addr);
1891 int to_add = in_bytes(TypeStackSlotEntries::per_arg_size());
1892 if (Assembler::is_simm16(to_add)) {
1893 daddiu(mdp, mdp, to_add);
1894 } else {
1895 move(AT, to_add);
1896 daddu(mdp, mdp, AT);
1897 }
1899 off_to_args += to_add;
1900 }
1902 if (MethodData::profile_return()) {
1903 ld(tmp, mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args);
1905 int tmp_arg_counts = TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count();
1906 if (Assembler::is_simm16(-1 * tmp_arg_counts)) {
1907 addiu32(tmp, tmp, -1 * tmp_arg_counts);
1908 } else {
1909 move(AT, tmp_arg_counts);
1910 subu32(mdp, mdp, AT);
1911 }
1912 }
1914 bind(done);
1916 if (MethodData::profile_return()) {
1917 // We're right after the type profile for the last
1918 // argument. tmp is the number of cells left in the
1919 // CallTypeData/VirtualCallTypeData to reach its end. Non null
1920 // if there's a return to profile.
1921 assert(ReturnTypeEntry::static_cell_count() < TypeStackSlotEntries::per_arg_count(), "can't move past ret type");
1922 sll(tmp, tmp, exact_log2(DataLayout::cell_size));
1923 daddu(mdp, mdp, tmp);
1924 }
1925 sd(mdp, FP, frame::interpreter_frame_mdx_offset * wordSize);
1926 } else {
1927 assert(MethodData::profile_return(), "either profile call args or call ret");
1928 update_mdp_by_constant(mdp, in_bytes(TypeEntriesAtCall::return_only_size()));
1929 }
1931 // mdp points right after the end of the
1932 // CallTypeData/VirtualCallTypeData, right after the cells for the
1933 // return value type if there's one
1935 bind(profile_continue);
1936 }
1937 }
1939 void InterpreterMacroAssembler::profile_return_type(Register mdp, Register ret, Register tmp) {
1940 assert_different_registers(mdp, ret, tmp, _bcp_register);
1941 if (ProfileInterpreter && MethodData::profile_return()) {
1942 Label profile_continue, done;
1944 test_method_data_pointer(mdp, profile_continue);
1946 if (MethodData::profile_return_jsr292_only()) {
1947 // If we don't profile all invoke bytecodes we must make sure
1948 // it's a bytecode we indeed profile. We can't go back to the
1949 // begining of the ProfileData we intend to update to check its
1950 // type because we're right after it and we don't known its
1951 // length
1952 Label do_profile;
1953 lb(AT, _bcp_register, 0);
1954 daddiu(AT, AT, -1 * Bytecodes::_invokedynamic);
1955 beq(AT, R0, do_profile);
1956 delayed()->nop();
1958 lb(AT, _bcp_register, 0);
1959 daddiu(AT, AT, -1 * Bytecodes::_invokehandle);
1960 beq(AT, R0, do_profile);
1961 delayed()->nop();
1963 get_method(tmp);
1964 lb(tmp, tmp, Method::intrinsic_id_offset_in_bytes());
1965 li(AT, vmIntrinsics::_compiledLambdaForm);
1966 bne(tmp, AT, profile_continue);
1967 delayed()->nop();
1969 bind(do_profile);
1970 }
1972 Address mdo_ret_addr(mdp, -in_bytes(ReturnTypeEntry::size()));
1973 daddu(tmp, ret, R0);
1974 profile_obj_type(tmp, mdo_ret_addr);
1976 bind(profile_continue);
1977 }
1978 }
1980 void InterpreterMacroAssembler::profile_parameters_type(Register mdp, Register tmp1, Register tmp2) {
1981 guarantee(T9 == tmp1, "You are reqired to use T9 as the index register for MIPS !");
1983 if (ProfileInterpreter && MethodData::profile_parameters()) {
1984 Label profile_continue, done;
1986 test_method_data_pointer(mdp, profile_continue);
1988 // Load the offset of the area within the MDO used for
1989 // parameters. If it's negative we're not profiling any parameters
1990 lw(tmp1, mdp, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset()));
1991 bltz(tmp1, profile_continue);
1992 delayed()->nop();
1994 // Compute a pointer to the area for parameters from the offset
1995 // and move the pointer to the slot for the last
1996 // parameters. Collect profiling from last parameter down.
1997 // mdo start + parameters offset + array length - 1
1998 daddu(mdp, mdp, tmp1);
1999 ld(tmp1, mdp, in_bytes(ArrayData::array_len_offset()));
2000 decrement(tmp1, TypeStackSlotEntries::per_arg_count());
2003 Label loop;
2004 bind(loop);
2006 int off_base = in_bytes(ParametersTypeData::stack_slot_offset(0));
2007 int type_base = in_bytes(ParametersTypeData::type_offset(0));
2008 Address::ScaleFactor per_arg_scale = Address::times(DataLayout::cell_size);
2009 Address arg_type(mdp, tmp1, per_arg_scale, type_base);
2011 // load offset on the stack from the slot for this parameter
2012 dsll(AT, tmp1, per_arg_scale);
2013 daddu(AT, AT, mdp);
2014 ld(tmp2, AT, off_base);
2016 subu(tmp2, R0, tmp2);
2018 // read the parameter from the local area
2019 dsll(AT, tmp2, Interpreter::stackElementScale());
2020 daddu(AT, AT, _locals_register);
2021 ld(tmp2, AT, 0);
2023 // profile the parameter
2024 profile_obj_type(tmp2, arg_type);
2026 // go to next parameter
2027 decrement(tmp1, TypeStackSlotEntries::per_arg_count());
2028 bgtz(tmp1, loop);
2029 delayed()->nop();
2031 bind(profile_continue);
2032 }
2033 }
2035 void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) {
2036 if (state == atos) {
2037 MacroAssembler::verify_oop(reg);
2038 }
2039 }
2041 void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) {
2042 }
2043 #endif // !CC_INTERP
2046 void InterpreterMacroAssembler::notify_method_entry() {
2047 // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
2048 // track stack depth. If it is possible to enter interp_only_mode we add
2049 // the code to check if the event should be sent.
2050 Register tempreg = T0;
2051 if (JvmtiExport::can_post_interpreter_events()) {
2052 Label L;
2053 #ifndef OPT_THREAD
2054 get_thread(AT);
2055 #else
2056 move(AT, TREG);
2057 #endif
2058 lw(tempreg, AT, in_bytes(JavaThread::interp_only_mode_offset()));
2059 beq(tempreg, R0, L);
2060 delayed()->nop();
2061 call_VM(noreg, CAST_FROM_FN_PTR(address,
2062 InterpreterRuntime::post_method_entry));
2063 bind(L);
2064 }
2066 {
2067 SkipIfEqual skip_if(this, &DTraceMethodProbes, 0);
2068 call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
2069 //Rthread,
2070 AT,
2071 //Rmethod);
2072 S3);
2073 }
2075 }
2077 void InterpreterMacroAssembler::notify_method_exit(
2078 //TosState state, NotifyMethodExitMode mode) {
2079 bool is_native_method, TosState state, NotifyMethodExitMode mode) {
2080 // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
2081 // track stack depth. If it is possible to enter interp_only_mode we add
2082 // the code to check if the event should be sent.
2083 Register tempreg = T0;
2084 if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {
2085 Label skip;
2086 #ifndef OPT_THREAD
2087 get_thread(AT);
2088 #else
2089 move(AT, TREG);
2090 #endif
2091 lw(tempreg, AT, in_bytes(JavaThread::interp_only_mode_offset()));
2092 beq(tempreg, R0, skip);
2093 delayed()->nop();
2094 // Note: frame::interpreter_frame_result has a dependency on how the
2095 // method result is saved across the call to post_method_exit. If this
2096 // is changed then the interpreter_frame_result implementation will
2097 // need to be updated too.
2099 // For c++ interpreter the result is always stored at a known location in the frame
2100 // template interpreter will leave it on the top of the stack.
2101 save_return_value(state, is_native_method);
2102 call_VM(noreg,
2103 CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit));
2104 restore_return_value(state, is_native_method);
2105 bind(skip);
2106 }
2108 {
2109 // Dtrace notification
2110 //SkipIfEqual skip_if(this, tempreg, R0, &DTraceMethodProbes, equal);
2111 SkipIfEqual skip_if(this, &DTraceMethodProbes, 0);
2112 save_return_value(state, is_native_method);
2113 call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
2114 //Rthread, Rmethod);
2115 AT, S3);
2116 restore_return_value(state, is_native_method);
2117 }
2118 }
2120 void InterpreterMacroAssembler::save_return_value(TosState state, bool is_native_call) {
2121 if (is_native_call) {
2122 // save any potential method result value
2123 sw(V0, FP, (-9) * wordSize);
2124 swc1(F0, FP, (-10) * wordSize);
2125 } else {
2126 push(state);
2127 }
2128 }
2130 void InterpreterMacroAssembler::restore_return_value(TosState state, bool is_native_call) {
2131 if (is_native_call) {
2132 // Restore any method result value
2133 lw(V0, FP, (-9) * wordSize);
2134 lwc1(F0, FP, (-10) * wordSize);
2135 } else {
2136 pop(state);
2137 }
2138 }