Thu, 19 Mar 2009 09:13:24 -0700
Merge
1 /*
2 * Copyright 2003-2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
25 #include "incls/_precompiled.incl"
26 #include "incls/_interp_masm_x86_64.cpp.incl"
29 // Implementation of InterpreterMacroAssembler
31 #ifdef CC_INTERP
32 void InterpreterMacroAssembler::get_method(Register reg) {
33 movptr(reg, Address(rbp, -((int)sizeof(BytecodeInterpreter) + 2 * wordSize)));
34 movptr(reg, Address(reg, byte_offset_of(BytecodeInterpreter, _method)));
35 }
36 #endif // CC_INTERP
38 #ifndef CC_INTERP
40 void InterpreterMacroAssembler::call_VM_leaf_base(address entry_point,
41 int number_of_arguments) {
42 // interpreter specific
43 //
44 // Note: No need to save/restore bcp & locals (r13 & r14) pointer
45 // since these are callee saved registers and no blocking/
46 // GC can happen in leaf calls.
47 // Further Note: DO NOT save/restore bcp/locals. If a caller has
48 // already saved them so that it can use esi/edi as temporaries
49 // then a save/restore here will DESTROY the copy the caller
50 // saved! There used to be a save_bcp() that only happened in
51 // the ASSERT path (no restore_bcp). Which caused bizarre failures
52 // when jvm built with ASSERTs.
53 #ifdef ASSERT
54 {
55 Label L;
56 cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
57 jcc(Assembler::equal, L);
58 stop("InterpreterMacroAssembler::call_VM_leaf_base:"
59 " last_sp != NULL");
60 bind(L);
61 }
62 #endif
63 // super call
64 MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments);
65 // interpreter specific
66 // Used to ASSERT that r13/r14 were equal to frame's bcp/locals
67 // but since they may not have been saved (and we don't want to
68 // save thme here (see note above) the assert is invalid.
69 }
71 void InterpreterMacroAssembler::call_VM_base(Register oop_result,
72 Register java_thread,
73 Register last_java_sp,
74 address entry_point,
75 int number_of_arguments,
76 bool check_exceptions) {
77 // interpreter specific
78 //
79 // Note: Could avoid restoring locals ptr (callee saved) - however doesn't
80 // really make a difference for these runtime calls, since they are
81 // slow anyway. Btw., bcp must be saved/restored since it may change
82 // due to GC.
83 // assert(java_thread == noreg , "not expecting a precomputed java thread");
84 save_bcp();
85 #ifdef ASSERT
86 {
87 Label L;
88 cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
89 jcc(Assembler::equal, L);
90 stop("InterpreterMacroAssembler::call_VM_leaf_base:"
91 " last_sp != NULL");
92 bind(L);
93 }
94 #endif /* ASSERT */
95 // super call
96 MacroAssembler::call_VM_base(oop_result, noreg, last_java_sp,
97 entry_point, number_of_arguments,
98 check_exceptions);
99 // interpreter specific
100 restore_bcp();
101 restore_locals();
102 }
105 void InterpreterMacroAssembler::check_and_handle_popframe(Register java_thread) {
106 if (JvmtiExport::can_pop_frame()) {
107 Label L;
108 // Initiate popframe handling only if it is not already being
109 // processed. If the flag has the popframe_processing bit set, it
110 // means that this code is called *during* popframe handling - we
111 // don't want to reenter.
112 // This method is only called just after the call into the vm in
113 // call_VM_base, so the arg registers are available.
114 movl(c_rarg0, Address(r15_thread, JavaThread::popframe_condition_offset()));
115 testl(c_rarg0, JavaThread::popframe_pending_bit);
116 jcc(Assembler::zero, L);
117 testl(c_rarg0, JavaThread::popframe_processing_bit);
118 jcc(Assembler::notZero, L);
119 // Call Interpreter::remove_activation_preserving_args_entry() to get the
120 // address of the same-named entrypoint in the generated interpreter code.
121 call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry));
122 jmp(rax);
123 bind(L);
124 }
125 }
128 void InterpreterMacroAssembler::load_earlyret_value(TosState state) {
129 movptr(rcx, Address(r15_thread, JavaThread::jvmti_thread_state_offset()));
130 const Address tos_addr(rcx, JvmtiThreadState::earlyret_tos_offset());
131 const Address oop_addr(rcx, JvmtiThreadState::earlyret_oop_offset());
132 const Address val_addr(rcx, JvmtiThreadState::earlyret_value_offset());
133 switch (state) {
134 case atos: movptr(rax, oop_addr);
135 movptr(oop_addr, (int32_t)NULL_WORD);
136 verify_oop(rax, state); break;
137 case ltos: movptr(rax, val_addr); break;
138 case btos: // fall through
139 case ctos: // fall through
140 case stos: // fall through
141 case itos: movl(rax, val_addr); break;
142 case ftos: movflt(xmm0, val_addr); break;
143 case dtos: movdbl(xmm0, val_addr); break;
144 case vtos: /* nothing to do */ break;
145 default : ShouldNotReachHere();
146 }
147 // Clean up tos value in the thread object
148 movl(tos_addr, (int) ilgl);
149 movl(val_addr, (int32_t) NULL_WORD);
150 }
153 void InterpreterMacroAssembler::check_and_handle_earlyret(Register java_thread) {
154 if (JvmtiExport::can_force_early_return()) {
155 Label L;
156 movptr(c_rarg0, Address(r15_thread, JavaThread::jvmti_thread_state_offset()));
157 testptr(c_rarg0, c_rarg0);
158 jcc(Assembler::zero, L); // if (thread->jvmti_thread_state() == NULL) exit;
160 // Initiate earlyret handling only if it is not already being processed.
161 // If the flag has the earlyret_processing bit set, it means that this code
162 // is called *during* earlyret handling - we don't want to reenter.
163 movl(c_rarg0, Address(c_rarg0, JvmtiThreadState::earlyret_state_offset()));
164 cmpl(c_rarg0, JvmtiThreadState::earlyret_pending);
165 jcc(Assembler::notEqual, L);
167 // Call Interpreter::remove_activation_early_entry() to get the address of the
168 // same-named entrypoint in the generated interpreter code.
169 movptr(c_rarg0, Address(r15_thread, JavaThread::jvmti_thread_state_offset()));
170 movl(c_rarg0, Address(c_rarg0, JvmtiThreadState::earlyret_tos_offset()));
171 call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), c_rarg0);
172 jmp(rax);
173 bind(L);
174 }
175 }
178 void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp(
179 Register reg,
180 int bcp_offset) {
181 assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode");
182 movl(reg, Address(r13, bcp_offset));
183 bswapl(reg);
184 shrl(reg, 16);
185 }
188 void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache,
189 Register index,
190 int bcp_offset) {
191 assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
192 assert(cache != index, "must use different registers");
193 load_unsigned_short(index, Address(r13, bcp_offset));
194 movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize));
195 assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
196 // convert from field index to ConstantPoolCacheEntry index
197 shll(index, 2);
198 }
201 void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache,
202 Register tmp,
203 int bcp_offset) {
204 assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
205 assert(cache != tmp, "must use different register");
206 load_unsigned_short(tmp, Address(r13, bcp_offset));
207 assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
208 // convert from field index to ConstantPoolCacheEntry index
209 // and from word offset to byte offset
210 shll(tmp, 2 + LogBytesPerWord);
211 movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize));
212 // skip past the header
213 addptr(cache, in_bytes(constantPoolCacheOopDesc::base_offset()));
214 addptr(cache, tmp); // construct pointer to cache entry
215 }
218 // Generate a subtype check: branch to ok_is_subtype if sub_klass is a
219 // subtype of super_klass.
220 //
221 // Args:
222 // rax: superklass
223 // Rsub_klass: subklass
224 //
225 // Kills:
226 // rcx, rdi
227 void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass,
228 Label& ok_is_subtype) {
229 assert(Rsub_klass != rax, "rax holds superklass");
230 assert(Rsub_klass != r14, "r14 holds locals");
231 assert(Rsub_klass != r13, "r13 holds bcp");
232 assert(Rsub_klass != rcx, "rcx holds 2ndary super array length");
233 assert(Rsub_klass != rdi, "rdi holds 2ndary super array scan ptr");
235 // Profile the not-null value's klass.
236 profile_typecheck(rcx, Rsub_klass, rdi); // blows rcx, reloads rdi
238 // Do the check.
239 check_klass_subtype(Rsub_klass, rax, rcx, ok_is_subtype); // blows rcx
241 // Profile the failure of the check.
242 profile_typecheck_failed(rcx); // blows rcx
243 }
247 // Java Expression Stack
249 #ifdef ASSERT
250 // Verifies that the stack tag matches. Must be called before the stack
251 // value is popped off the stack.
252 void InterpreterMacroAssembler::verify_stack_tag(frame::Tag t) {
253 if (TaggedStackInterpreter) {
254 frame::Tag tag = t;
255 if (t == frame::TagCategory2) {
256 tag = frame::TagValue;
257 Label hokay;
258 cmpptr(Address(rsp, 3*wordSize), (int32_t)tag);
259 jcc(Assembler::equal, hokay);
260 stop("Java Expression stack tag high value is bad");
261 bind(hokay);
262 }
263 Label okay;
264 cmpptr(Address(rsp, wordSize), (int32_t)tag);
265 jcc(Assembler::equal, okay);
266 // Also compare if the stack value is zero, then the tag might
267 // not have been set coming from deopt.
268 cmpptr(Address(rsp, 0), 0);
269 jcc(Assembler::equal, okay);
270 stop("Java Expression stack tag value is bad");
271 bind(okay);
272 }
273 }
274 #endif // ASSERT
276 void InterpreterMacroAssembler::pop_ptr(Register r) {
277 debug_only(verify_stack_tag(frame::TagReference));
278 pop(r);
279 if (TaggedStackInterpreter) addptr(rsp, 1 * wordSize);
280 }
282 void InterpreterMacroAssembler::pop_ptr(Register r, Register tag) {
283 pop(r);
284 if (TaggedStackInterpreter) pop(tag);
285 }
287 void InterpreterMacroAssembler::pop_i(Register r) {
288 // XXX can't use pop currently, upper half non clean
289 debug_only(verify_stack_tag(frame::TagValue));
290 movl(r, Address(rsp, 0));
291 addptr(rsp, wordSize);
292 if (TaggedStackInterpreter) addptr(rsp, 1 * wordSize);
293 }
295 void InterpreterMacroAssembler::pop_l(Register r) {
296 debug_only(verify_stack_tag(frame::TagCategory2));
297 movq(r, Address(rsp, 0));
298 addptr(rsp, 2 * Interpreter::stackElementSize());
299 }
301 void InterpreterMacroAssembler::pop_f(XMMRegister r) {
302 debug_only(verify_stack_tag(frame::TagValue));
303 movflt(r, Address(rsp, 0));
304 addptr(rsp, wordSize);
305 if (TaggedStackInterpreter) addptr(rsp, 1 * wordSize);
306 }
308 void InterpreterMacroAssembler::pop_d(XMMRegister r) {
309 debug_only(verify_stack_tag(frame::TagCategory2));
310 movdbl(r, Address(rsp, 0));
311 addptr(rsp, 2 * Interpreter::stackElementSize());
312 }
314 void InterpreterMacroAssembler::push_ptr(Register r) {
315 if (TaggedStackInterpreter) push(frame::TagReference);
316 push(r);
317 }
319 void InterpreterMacroAssembler::push_ptr(Register r, Register tag) {
320 if (TaggedStackInterpreter) push(tag);
321 push(r);
322 }
324 void InterpreterMacroAssembler::push_i(Register r) {
325 if (TaggedStackInterpreter) push(frame::TagValue);
326 push(r);
327 }
329 void InterpreterMacroAssembler::push_l(Register r) {
330 if (TaggedStackInterpreter) {
331 push(frame::TagValue);
332 subptr(rsp, 1 * wordSize);
333 push(frame::TagValue);
334 subptr(rsp, 1 * wordSize);
335 } else {
336 subptr(rsp, 2 * wordSize);
337 }
338 movq(Address(rsp, 0), r);
339 }
341 void InterpreterMacroAssembler::push_f(XMMRegister r) {
342 if (TaggedStackInterpreter) push(frame::TagValue);
343 subptr(rsp, wordSize);
344 movflt(Address(rsp, 0), r);
345 }
347 void InterpreterMacroAssembler::push_d(XMMRegister r) {
348 if (TaggedStackInterpreter) {
349 push(frame::TagValue);
350 subptr(rsp, 1 * wordSize);
351 push(frame::TagValue);
352 subptr(rsp, 1 * wordSize);
353 } else {
354 subptr(rsp, 2 * wordSize);
355 }
356 movdbl(Address(rsp, 0), r);
357 }
359 void InterpreterMacroAssembler::pop(TosState state) {
360 switch (state) {
361 case atos: pop_ptr(); break;
362 case btos:
363 case ctos:
364 case stos:
365 case itos: pop_i(); break;
366 case ltos: pop_l(); break;
367 case ftos: pop_f(); break;
368 case dtos: pop_d(); break;
369 case vtos: /* nothing to do */ break;
370 default: ShouldNotReachHere();
371 }
372 verify_oop(rax, state);
373 }
375 void InterpreterMacroAssembler::push(TosState state) {
376 verify_oop(rax, state);
377 switch (state) {
378 case atos: push_ptr(); break;
379 case btos:
380 case ctos:
381 case stos:
382 case itos: push_i(); break;
383 case ltos: push_l(); break;
384 case ftos: push_f(); break;
385 case dtos: push_d(); break;
386 case vtos: /* nothing to do */ break;
387 default : ShouldNotReachHere();
388 }
389 }
394 // Tagged stack helpers for swap and dup
395 void InterpreterMacroAssembler::load_ptr_and_tag(int n, Register val,
396 Register tag) {
397 movptr(val, Address(rsp, Interpreter::expr_offset_in_bytes(n)));
398 if (TaggedStackInterpreter) {
399 movptr(tag, Address(rsp, Interpreter::expr_tag_offset_in_bytes(n)));
400 }
401 }
403 void InterpreterMacroAssembler::store_ptr_and_tag(int n, Register val,
404 Register tag) {
405 movptr(Address(rsp, Interpreter::expr_offset_in_bytes(n)), val);
406 if (TaggedStackInterpreter) {
407 movptr(Address(rsp, Interpreter::expr_tag_offset_in_bytes(n)), tag);
408 }
409 }
412 // Tagged local support
413 void InterpreterMacroAssembler::tag_local(frame::Tag tag, int n) {
414 if (TaggedStackInterpreter) {
415 if (tag == frame::TagCategory2) {
416 movptr(Address(r14, Interpreter::local_tag_offset_in_bytes(n+1)),
417 (int32_t)frame::TagValue);
418 movptr(Address(r14, Interpreter::local_tag_offset_in_bytes(n)),
419 (int32_t)frame::TagValue);
420 } else {
421 movptr(Address(r14, Interpreter::local_tag_offset_in_bytes(n)), (int32_t)tag);
422 }
423 }
424 }
426 void InterpreterMacroAssembler::tag_local(frame::Tag tag, Register idx) {
427 if (TaggedStackInterpreter) {
428 if (tag == frame::TagCategory2) {
429 movptr(Address(r14, idx, Address::times_8,
430 Interpreter::local_tag_offset_in_bytes(1)), (int32_t)frame::TagValue);
431 movptr(Address(r14, idx, Address::times_8,
432 Interpreter::local_tag_offset_in_bytes(0)), (int32_t)frame::TagValue);
433 } else {
434 movptr(Address(r14, idx, Address::times_8, Interpreter::local_tag_offset_in_bytes(0)),
435 (int32_t)tag);
436 }
437 }
438 }
440 void InterpreterMacroAssembler::tag_local(Register tag, Register idx) {
441 if (TaggedStackInterpreter) {
442 // can only be TagValue or TagReference
443 movptr(Address(r14, idx, Address::times_8, Interpreter::local_tag_offset_in_bytes(0)), tag);
444 }
445 }
448 void InterpreterMacroAssembler::tag_local(Register tag, int n) {
449 if (TaggedStackInterpreter) {
450 // can only be TagValue or TagReference
451 movptr(Address(r14, Interpreter::local_tag_offset_in_bytes(n)), tag);
452 }
453 }
455 #ifdef ASSERT
456 void InterpreterMacroAssembler::verify_local_tag(frame::Tag tag, int n) {
457 if (TaggedStackInterpreter) {
458 frame::Tag t = tag;
459 if (tag == frame::TagCategory2) {
460 Label nbl;
461 t = frame::TagValue; // change to what is stored in locals
462 cmpptr(Address(r14, Interpreter::local_tag_offset_in_bytes(n+1)), (int32_t)t);
463 jcc(Assembler::equal, nbl);
464 stop("Local tag is bad for long/double");
465 bind(nbl);
466 }
467 Label notBad;
468 cmpq(Address(r14, Interpreter::local_tag_offset_in_bytes(n)), (int32_t)t);
469 jcc(Assembler::equal, notBad);
470 // Also compare if the local value is zero, then the tag might
471 // not have been set coming from deopt.
472 cmpptr(Address(r14, Interpreter::local_offset_in_bytes(n)), 0);
473 jcc(Assembler::equal, notBad);
474 stop("Local tag is bad");
475 bind(notBad);
476 }
477 }
479 void InterpreterMacroAssembler::verify_local_tag(frame::Tag tag, Register idx) {
480 if (TaggedStackInterpreter) {
481 frame::Tag t = tag;
482 if (tag == frame::TagCategory2) {
483 Label nbl;
484 t = frame::TagValue; // change to what is stored in locals
485 cmpptr(Address(r14, idx, Address::times_8, Interpreter::local_tag_offset_in_bytes(1)), (int32_t)t);
486 jcc(Assembler::equal, nbl);
487 stop("Local tag is bad for long/double");
488 bind(nbl);
489 }
490 Label notBad;
491 cmpptr(Address(r14, idx, Address::times_8, Interpreter::local_tag_offset_in_bytes(0)), (int32_t)t);
492 jcc(Assembler::equal, notBad);
493 // Also compare if the local value is zero, then the tag might
494 // not have been set coming from deopt.
495 cmpptr(Address(r14, idx, Address::times_8, Interpreter::local_offset_in_bytes(0)), 0);
496 jcc(Assembler::equal, notBad);
497 stop("Local tag is bad");
498 bind(notBad);
499 }
500 }
501 #endif // ASSERT
504 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point) {
505 MacroAssembler::call_VM_leaf_base(entry_point, 0);
506 }
509 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point,
510 Register arg_1) {
511 if (c_rarg0 != arg_1) {
512 mov(c_rarg0, arg_1);
513 }
514 MacroAssembler::call_VM_leaf_base(entry_point, 1);
515 }
518 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point,
519 Register arg_1,
520 Register arg_2) {
521 assert(c_rarg0 != arg_2, "smashed argument");
522 assert(c_rarg1 != arg_1, "smashed argument");
523 if (c_rarg0 != arg_1) {
524 mov(c_rarg0, arg_1);
525 }
526 if (c_rarg1 != arg_2) {
527 mov(c_rarg1, arg_2);
528 }
529 MacroAssembler::call_VM_leaf_base(entry_point, 2);
530 }
532 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point,
533 Register arg_1,
534 Register arg_2,
535 Register arg_3) {
536 assert(c_rarg0 != arg_2, "smashed argument");
537 assert(c_rarg0 != arg_3, "smashed argument");
538 assert(c_rarg1 != arg_1, "smashed argument");
539 assert(c_rarg1 != arg_3, "smashed argument");
540 assert(c_rarg2 != arg_1, "smashed argument");
541 assert(c_rarg2 != arg_2, "smashed argument");
542 if (c_rarg0 != arg_1) {
543 mov(c_rarg0, arg_1);
544 }
545 if (c_rarg1 != arg_2) {
546 mov(c_rarg1, arg_2);
547 }
548 if (c_rarg2 != arg_3) {
549 mov(c_rarg2, arg_3);
550 }
551 MacroAssembler::call_VM_leaf_base(entry_point, 3);
552 }
554 // Jump to from_interpreted entry of a call unless single stepping is possible
555 // in this thread in which case we must call the i2i entry
556 void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) {
557 // set sender sp
558 lea(r13, Address(rsp, wordSize));
559 // record last_sp
560 movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), r13);
562 if (JvmtiExport::can_post_interpreter_events()) {
563 Label run_compiled_code;
564 // JVMTI events, such as single-stepping, are implemented partly by avoiding running
565 // compiled code in threads for which the event is enabled. Check here for
566 // interp_only_mode if these events CAN be enabled.
567 get_thread(temp);
568 // interp_only is an int, on little endian it is sufficient to test the byte only
569 // Is a cmpl faster (ce
570 cmpb(Address(temp, JavaThread::interp_only_mode_offset()), 0);
571 jcc(Assembler::zero, run_compiled_code);
572 jmp(Address(method, methodOopDesc::interpreter_entry_offset()));
573 bind(run_compiled_code);
574 }
576 jmp(Address(method, methodOopDesc::from_interpreted_offset()));
578 }
581 // The following two routines provide a hook so that an implementation
582 // can schedule the dispatch in two parts. amd64 does not do this.
583 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) {
584 // Nothing amd64 specific to be done here
585 }
587 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) {
588 dispatch_next(state, step);
589 }
591 void InterpreterMacroAssembler::dispatch_base(TosState state,
592 address* table,
593 bool verifyoop) {
594 verify_FPU(1, state);
595 if (VerifyActivationFrameSize) {
596 Label L;
597 mov(rcx, rbp);
598 subptr(rcx, rsp);
599 int32_t min_frame_size =
600 (frame::link_offset - frame::interpreter_frame_initial_sp_offset) *
601 wordSize;
602 cmpptr(rcx, (int32_t)min_frame_size);
603 jcc(Assembler::greaterEqual, L);
604 stop("broken stack frame");
605 bind(L);
606 }
607 if (verifyoop) {
608 verify_oop(rax, state);
609 }
610 lea(rscratch1, ExternalAddress((address)table));
611 jmp(Address(rscratch1, rbx, Address::times_8));
612 }
614 void InterpreterMacroAssembler::dispatch_only(TosState state) {
615 dispatch_base(state, Interpreter::dispatch_table(state));
616 }
618 void InterpreterMacroAssembler::dispatch_only_normal(TosState state) {
619 dispatch_base(state, Interpreter::normal_table(state));
620 }
622 void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) {
623 dispatch_base(state, Interpreter::normal_table(state), false);
624 }
627 void InterpreterMacroAssembler::dispatch_next(TosState state, int step) {
628 // load next bytecode (load before advancing r13 to prevent AGI)
629 load_unsigned_byte(rbx, Address(r13, step));
630 // advance r13
631 increment(r13, step);
632 dispatch_base(state, Interpreter::dispatch_table(state));
633 }
635 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
636 // load current bytecode
637 load_unsigned_byte(rbx, Address(r13, 0));
638 dispatch_base(state, table);
639 }
641 // remove activation
642 //
643 // Unlock the receiver if this is a synchronized method.
644 // Unlock any Java monitors from syncronized blocks.
645 // Remove the activation from the stack.
646 //
647 // If there are locked Java monitors
648 // If throw_monitor_exception
649 // throws IllegalMonitorStateException
650 // Else if install_monitor_exception
651 // installs IllegalMonitorStateException
652 // Else
653 // no error processing
654 void InterpreterMacroAssembler::remove_activation(
655 TosState state,
656 Register ret_addr,
657 bool throw_monitor_exception,
658 bool install_monitor_exception,
659 bool notify_jvmdi) {
660 // Note: Registers rdx xmm0 may be in use for the
661 // result check if synchronized method
662 Label unlocked, unlock, no_unlock;
664 // get the value of _do_not_unlock_if_synchronized into rdx
665 const Address do_not_unlock_if_synchronized(r15_thread,
666 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
667 movbool(rdx, do_not_unlock_if_synchronized);
668 movbool(do_not_unlock_if_synchronized, false); // reset the flag
670 // get method access flags
671 movptr(rbx, Address(rbp, frame::interpreter_frame_method_offset * wordSize));
672 movl(rcx, Address(rbx, methodOopDesc::access_flags_offset()));
673 testl(rcx, JVM_ACC_SYNCHRONIZED);
674 jcc(Assembler::zero, unlocked);
676 // Don't unlock anything if the _do_not_unlock_if_synchronized flag
677 // is set.
678 testbool(rdx);
679 jcc(Assembler::notZero, no_unlock);
681 // unlock monitor
682 push(state); // save result
684 // BasicObjectLock will be first in list, since this is a
685 // synchronized method. However, need to check that the object has
686 // not been unlocked by an explicit monitorexit bytecode.
687 const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset *
688 wordSize - (int) sizeof(BasicObjectLock));
689 // We use c_rarg1 so that if we go slow path it will be the correct
690 // register for unlock_object to pass to VM directly
691 lea(c_rarg1, monitor); // address of first monitor
693 movptr(rax, Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes()));
694 testptr(rax, rax);
695 jcc(Assembler::notZero, unlock);
697 pop(state);
698 if (throw_monitor_exception) {
699 // Entry already unlocked, need to throw exception
700 call_VM(noreg, CAST_FROM_FN_PTR(address,
701 InterpreterRuntime::throw_illegal_monitor_state_exception));
702 should_not_reach_here();
703 } else {
704 // Monitor already unlocked during a stack unroll. If requested,
705 // install an illegal_monitor_state_exception. Continue with
706 // stack unrolling.
707 if (install_monitor_exception) {
708 call_VM(noreg, CAST_FROM_FN_PTR(address,
709 InterpreterRuntime::new_illegal_monitor_state_exception));
710 }
711 jmp(unlocked);
712 }
714 bind(unlock);
715 unlock_object(c_rarg1);
716 pop(state);
718 // Check that for block-structured locking (i.e., that all locked
719 // objects has been unlocked)
720 bind(unlocked);
722 // rax: Might contain return value
724 // Check that all monitors are unlocked
725 {
726 Label loop, exception, entry, restart;
727 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
728 const Address monitor_block_top(
729 rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
730 const Address monitor_block_bot(
731 rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
733 bind(restart);
734 // We use c_rarg1 so that if we go slow path it will be the correct
735 // register for unlock_object to pass to VM directly
736 movptr(c_rarg1, monitor_block_top); // points to current entry, starting
737 // with top-most entry
738 lea(rbx, monitor_block_bot); // points to word before bottom of
739 // monitor block
740 jmp(entry);
742 // Entry already locked, need to throw exception
743 bind(exception);
745 if (throw_monitor_exception) {
746 // Throw exception
747 MacroAssembler::call_VM(noreg,
748 CAST_FROM_FN_PTR(address, InterpreterRuntime::
749 throw_illegal_monitor_state_exception));
750 should_not_reach_here();
751 } else {
752 // Stack unrolling. Unlock object and install illegal_monitor_exception.
753 // Unlock does not block, so don't have to worry about the frame.
754 // We don't have to preserve c_rarg1 since we are going to throw an exception.
756 push(state);
757 unlock_object(c_rarg1);
758 pop(state);
760 if (install_monitor_exception) {
761 call_VM(noreg, CAST_FROM_FN_PTR(address,
762 InterpreterRuntime::
763 new_illegal_monitor_state_exception));
764 }
766 jmp(restart);
767 }
769 bind(loop);
770 // check if current entry is used
771 cmpptr(Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes()), (int32_t) NULL);
772 jcc(Assembler::notEqual, exception);
774 addptr(c_rarg1, entry_size); // otherwise advance to next entry
775 bind(entry);
776 cmpptr(c_rarg1, rbx); // check if bottom reached
777 jcc(Assembler::notEqual, loop); // if not at bottom then check this entry
778 }
780 bind(no_unlock);
782 // jvmti support
783 if (notify_jvmdi) {
784 notify_method_exit(state, NotifyJVMTI); // preserve TOSCA
785 } else {
786 notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA
787 }
789 // remove activation
790 // get sender sp
791 movptr(rbx,
792 Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize));
793 leave(); // remove frame anchor
794 pop(ret_addr); // get return address
795 mov(rsp, rbx); // set sp to sender sp
796 }
798 #endif // C_INTERP
800 // Lock object
801 //
802 // Args:
803 // c_rarg1: BasicObjectLock to be used for locking
804 //
805 // Kills:
806 // rax
807 // c_rarg0, c_rarg1, c_rarg2, c_rarg3, .. (param regs)
808 // rscratch1, rscratch2 (scratch regs)
809 void InterpreterMacroAssembler::lock_object(Register lock_reg) {
810 assert(lock_reg == c_rarg1, "The argument is only for looks. It must be c_rarg1");
812 if (UseHeavyMonitors) {
813 call_VM(noreg,
814 CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
815 lock_reg);
816 } else {
817 Label done;
819 const Register swap_reg = rax; // Must use rax for cmpxchg instruction
820 const Register obj_reg = c_rarg3; // Will contain the oop
822 const int obj_offset = BasicObjectLock::obj_offset_in_bytes();
823 const int lock_offset = BasicObjectLock::lock_offset_in_bytes ();
824 const int mark_offset = lock_offset +
825 BasicLock::displaced_header_offset_in_bytes();
827 Label slow_case;
829 // Load object pointer into obj_reg %c_rarg3
830 movptr(obj_reg, Address(lock_reg, obj_offset));
832 if (UseBiasedLocking) {
833 biased_locking_enter(lock_reg, obj_reg, swap_reg, rscratch1, false, done, &slow_case);
834 }
836 // Load immediate 1 into swap_reg %rax
837 movl(swap_reg, 1);
839 // Load (object->mark() | 1) into swap_reg %rax
840 orptr(swap_reg, Address(obj_reg, 0));
842 // Save (object->mark() | 1) into BasicLock's displaced header
843 movptr(Address(lock_reg, mark_offset), swap_reg);
845 assert(lock_offset == 0,
846 "displached header must be first word in BasicObjectLock");
848 if (os::is_MP()) lock();
849 cmpxchgptr(lock_reg, Address(obj_reg, 0));
850 if (PrintBiasedLockingStatistics) {
851 cond_inc32(Assembler::zero,
852 ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr()));
853 }
854 jcc(Assembler::zero, done);
856 // Test if the oopMark is an obvious stack pointer, i.e.,
857 // 1) (mark & 7) == 0, and
858 // 2) rsp <= mark < mark + os::pagesize()
859 //
860 // These 3 tests can be done by evaluating the following
861 // expression: ((mark - rsp) & (7 - os::vm_page_size())),
862 // assuming both stack pointer and pagesize have their
863 // least significant 3 bits clear.
864 // NOTE: the oopMark is in swap_reg %rax as the result of cmpxchg
865 subptr(swap_reg, rsp);
866 andptr(swap_reg, 7 - os::vm_page_size());
868 // Save the test result, for recursive case, the result is zero
869 movptr(Address(lock_reg, mark_offset), swap_reg);
871 if (PrintBiasedLockingStatistics) {
872 cond_inc32(Assembler::zero,
873 ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr()));
874 }
875 jcc(Assembler::zero, done);
877 bind(slow_case);
879 // Call the runtime routine for slow case
880 call_VM(noreg,
881 CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
882 lock_reg);
884 bind(done);
885 }
886 }
889 // Unlocks an object. Used in monitorexit bytecode and
890 // remove_activation. Throws an IllegalMonitorException if object is
891 // not locked by current thread.
892 //
893 // Args:
894 // c_rarg1: BasicObjectLock for lock
895 //
896 // Kills:
897 // rax
898 // c_rarg0, c_rarg1, c_rarg2, c_rarg3, ... (param regs)
899 // rscratch1, rscratch2 (scratch regs)
900 void InterpreterMacroAssembler::unlock_object(Register lock_reg) {
901 assert(lock_reg == c_rarg1, "The argument is only for looks. It must be rarg1");
903 if (UseHeavyMonitors) {
904 call_VM(noreg,
905 CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
906 lock_reg);
907 } else {
908 Label done;
910 const Register swap_reg = rax; // Must use rax for cmpxchg instruction
911 const Register header_reg = c_rarg2; // Will contain the old oopMark
912 const Register obj_reg = c_rarg3; // Will contain the oop
914 save_bcp(); // Save in case of exception
916 // Convert from BasicObjectLock structure to object and BasicLock
917 // structure Store the BasicLock address into %rax
918 lea(swap_reg, Address(lock_reg, BasicObjectLock::lock_offset_in_bytes()));
920 // Load oop into obj_reg(%c_rarg3)
921 movptr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()));
923 // Free entry
924 movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), (int32_t)NULL_WORD);
926 if (UseBiasedLocking) {
927 biased_locking_exit(obj_reg, header_reg, done);
928 }
930 // Load the old header from BasicLock structure
931 movptr(header_reg, Address(swap_reg,
932 BasicLock::displaced_header_offset_in_bytes()));
934 // Test for recursion
935 testptr(header_reg, header_reg);
937 // zero for recursive case
938 jcc(Assembler::zero, done);
940 // Atomic swap back the old header
941 if (os::is_MP()) lock();
942 cmpxchgptr(header_reg, Address(obj_reg, 0));
944 // zero for recursive case
945 jcc(Assembler::zero, done);
947 // Call the runtime routine for slow case.
948 movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()),
949 obj_reg); // restore obj
950 call_VM(noreg,
951 CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
952 lock_reg);
954 bind(done);
956 restore_bcp();
957 }
958 }
960 #ifndef CC_INTERP
962 void InterpreterMacroAssembler::test_method_data_pointer(Register mdp,
963 Label& zero_continue) {
964 assert(ProfileInterpreter, "must be profiling interpreter");
965 movptr(mdp, Address(rbp, frame::interpreter_frame_mdx_offset * wordSize));
966 testptr(mdp, mdp);
967 jcc(Assembler::zero, zero_continue);
968 }
971 // Set the method data pointer for the current bcp.
972 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
973 assert(ProfileInterpreter, "must be profiling interpreter");
974 Label zero_continue;
975 push(rax);
976 push(rbx);
978 get_method(rbx);
979 // Test MDO to avoid the call if it is NULL.
980 movptr(rax, Address(rbx, in_bytes(methodOopDesc::method_data_offset())));
981 testptr(rax, rax);
982 jcc(Assembler::zero, zero_continue);
984 // rbx: method
985 // r13: bcp
986 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), rbx, r13);
987 // rax: mdi
989 movptr(rbx, Address(rbx, in_bytes(methodOopDesc::method_data_offset())));
990 testptr(rbx, rbx);
991 jcc(Assembler::zero, zero_continue);
992 addptr(rbx, in_bytes(methodDataOopDesc::data_offset()));
993 addptr(rbx, rax);
994 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), rbx);
996 bind(zero_continue);
997 pop(rbx);
998 pop(rax);
999 }
1001 void InterpreterMacroAssembler::verify_method_data_pointer() {
1002 assert(ProfileInterpreter, "must be profiling interpreter");
1003 #ifdef ASSERT
1004 Label verify_continue;
1005 push(rax);
1006 push(rbx);
1007 push(c_rarg3);
1008 push(c_rarg2);
1009 test_method_data_pointer(c_rarg3, verify_continue); // If mdp is zero, continue
1010 get_method(rbx);
1012 // If the mdp is valid, it will point to a DataLayout header which is
1013 // consistent with the bcp. The converse is highly probable also.
1014 load_unsigned_short(c_rarg2,
1015 Address(c_rarg3, in_bytes(DataLayout::bci_offset())));
1016 addptr(c_rarg2, Address(rbx, methodOopDesc::const_offset()));
1017 lea(c_rarg2, Address(c_rarg2, constMethodOopDesc::codes_offset()));
1018 cmpptr(c_rarg2, r13);
1019 jcc(Assembler::equal, verify_continue);
1020 // rbx: method
1021 // r13: bcp
1022 // c_rarg3: mdp
1023 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp),
1024 rbx, r13, c_rarg3);
1025 bind(verify_continue);
1026 pop(c_rarg2);
1027 pop(c_rarg3);
1028 pop(rbx);
1029 pop(rax);
1030 #endif // ASSERT
1031 }
1034 void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in,
1035 int constant,
1036 Register value) {
1037 assert(ProfileInterpreter, "must be profiling interpreter");
1038 Address data(mdp_in, constant);
1039 movptr(data, value);
1040 }
1043 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
1044 int constant,
1045 bool decrement) {
1046 // Counter address
1047 Address data(mdp_in, constant);
1049 increment_mdp_data_at(data, decrement);
1050 }
1052 void InterpreterMacroAssembler::increment_mdp_data_at(Address data,
1053 bool decrement) {
1054 assert(ProfileInterpreter, "must be profiling interpreter");
1055 // %%% this does 64bit counters at best it is wasting space
1056 // at worst it is a rare bug when counters overflow
1058 if (decrement) {
1059 // Decrement the register. Set condition codes.
1060 addptr(data, (int32_t) -DataLayout::counter_increment);
1061 // If the decrement causes the counter to overflow, stay negative
1062 Label L;
1063 jcc(Assembler::negative, L);
1064 addptr(data, (int32_t) DataLayout::counter_increment);
1065 bind(L);
1066 } else {
1067 assert(DataLayout::counter_increment == 1,
1068 "flow-free idiom only works with 1");
1069 // Increment the register. Set carry flag.
1070 addptr(data, DataLayout::counter_increment);
1071 // If the increment causes the counter to overflow, pull back by 1.
1072 sbbptr(data, (int32_t)0);
1073 }
1074 }
1077 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
1078 Register reg,
1079 int constant,
1080 bool decrement) {
1081 Address data(mdp_in, reg, Address::times_1, constant);
1083 increment_mdp_data_at(data, decrement);
1084 }
1086 void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in,
1087 int flag_byte_constant) {
1088 assert(ProfileInterpreter, "must be profiling interpreter");
1089 int header_offset = in_bytes(DataLayout::header_offset());
1090 int header_bits = DataLayout::flag_mask_to_header_mask(flag_byte_constant);
1091 // Set the flag
1092 orl(Address(mdp_in, header_offset), header_bits);
1093 }
1097 void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in,
1098 int offset,
1099 Register value,
1100 Register test_value_out,
1101 Label& not_equal_continue) {
1102 assert(ProfileInterpreter, "must be profiling interpreter");
1103 if (test_value_out == noreg) {
1104 cmpptr(value, Address(mdp_in, offset));
1105 } else {
1106 // Put the test value into a register, so caller can use it:
1107 movptr(test_value_out, Address(mdp_in, offset));
1108 cmpptr(test_value_out, value);
1109 }
1110 jcc(Assembler::notEqual, not_equal_continue);
1111 }
1114 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
1115 int offset_of_disp) {
1116 assert(ProfileInterpreter, "must be profiling interpreter");
1117 Address disp_address(mdp_in, offset_of_disp);
1118 addptr(mdp_in, disp_address);
1119 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
1120 }
1123 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
1124 Register reg,
1125 int offset_of_disp) {
1126 assert(ProfileInterpreter, "must be profiling interpreter");
1127 Address disp_address(mdp_in, reg, Address::times_1, offset_of_disp);
1128 addptr(mdp_in, disp_address);
1129 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
1130 }
1133 void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in,
1134 int constant) {
1135 assert(ProfileInterpreter, "must be profiling interpreter");
1136 addptr(mdp_in, constant);
1137 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
1138 }
1141 void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) {
1142 assert(ProfileInterpreter, "must be profiling interpreter");
1143 push(return_bci); // save/restore across call_VM
1144 call_VM(noreg,
1145 CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret),
1146 return_bci);
1147 pop(return_bci);
1148 }
1151 void InterpreterMacroAssembler::profile_taken_branch(Register mdp,
1152 Register bumped_count) {
1153 if (ProfileInterpreter) {
1154 Label profile_continue;
1156 // If no method data exists, go to profile_continue.
1157 // Otherwise, assign to mdp
1158 test_method_data_pointer(mdp, profile_continue);
1160 // We are taking a branch. Increment the taken count.
1161 // We inline increment_mdp_data_at to return bumped_count in a register
1162 //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
1163 Address data(mdp, in_bytes(JumpData::taken_offset()));
1164 movptr(bumped_count, data);
1165 assert(DataLayout::counter_increment == 1,
1166 "flow-free idiom only works with 1");
1167 addptr(bumped_count, DataLayout::counter_increment);
1168 sbbptr(bumped_count, 0);
1169 movptr(data, bumped_count); // Store back out
1171 // The method data pointer needs to be updated to reflect the new target.
1172 update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
1173 bind(profile_continue);
1174 }
1175 }
1178 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) {
1179 if (ProfileInterpreter) {
1180 Label profile_continue;
1182 // If no method data exists, go to profile_continue.
1183 test_method_data_pointer(mdp, profile_continue);
1185 // We are taking a branch. Increment the not taken count.
1186 increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
1188 // The method data pointer needs to be updated to correspond to
1189 // the next bytecode
1190 update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size()));
1191 bind(profile_continue);
1192 }
1193 }
1196 void InterpreterMacroAssembler::profile_call(Register mdp) {
1197 if (ProfileInterpreter) {
1198 Label profile_continue;
1200 // If no method data exists, go to profile_continue.
1201 test_method_data_pointer(mdp, profile_continue);
1203 // We are making a call. Increment the count.
1204 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1206 // The method data pointer needs to be updated to reflect the new target.
1207 update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
1208 bind(profile_continue);
1209 }
1210 }
1213 void InterpreterMacroAssembler::profile_final_call(Register mdp) {
1214 if (ProfileInterpreter) {
1215 Label profile_continue;
1217 // If no method data exists, go to profile_continue.
1218 test_method_data_pointer(mdp, profile_continue);
1220 // We are making a call. Increment the count.
1221 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1223 // The method data pointer needs to be updated to reflect the new target.
1224 update_mdp_by_constant(mdp,
1225 in_bytes(VirtualCallData::
1226 virtual_call_data_size()));
1227 bind(profile_continue);
1228 }
1229 }
1232 void InterpreterMacroAssembler::profile_virtual_call(Register receiver,
1233 Register mdp,
1234 Register reg2) {
1235 if (ProfileInterpreter) {
1236 Label profile_continue;
1238 // If no method data exists, go to profile_continue.
1239 test_method_data_pointer(mdp, profile_continue);
1241 // We are making a call. Increment the count.
1242 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1244 // Record the receiver type.
1245 record_klass_in_profile(receiver, mdp, reg2);
1247 // The method data pointer needs to be updated to reflect the new target.
1248 update_mdp_by_constant(mdp,
1249 in_bytes(VirtualCallData::
1250 virtual_call_data_size()));
1251 bind(profile_continue);
1252 }
1253 }
1255 // This routine creates a state machine for updating the multi-row
1256 // type profile at a virtual call site (or other type-sensitive bytecode).
1257 // The machine visits each row (of receiver/count) until the receiver type
1258 // is found, or until it runs out of rows. At the same time, it remembers
1259 // the location of the first empty row. (An empty row records null for its
1260 // receiver, and can be allocated for a newly-observed receiver type.)
1261 // Because there are two degrees of freedom in the state, a simple linear
1262 // search will not work; it must be a decision tree. Hence this helper
1263 // function is recursive, to generate the required tree structured code.
1264 // It's the interpreter, so we are trading off code space for speed.
1265 // See below for example code.
1266 void InterpreterMacroAssembler::record_klass_in_profile_helper(
1267 Register receiver, Register mdp,
1268 Register reg2,
1269 int start_row, Label& done) {
1270 int last_row = VirtualCallData::row_limit() - 1;
1271 assert(start_row <= last_row, "must be work left to do");
1272 // Test this row for both the receiver and for null.
1273 // Take any of three different outcomes:
1274 // 1. found receiver => increment count and goto done
1275 // 2. found null => keep looking for case 1, maybe allocate this cell
1276 // 3. found something else => keep looking for cases 1 and 2
1277 // Case 3 is handled by a recursive call.
1278 for (int row = start_row; row <= last_row; row++) {
1279 Label next_test;
1280 bool test_for_null_also = (row == start_row);
1282 // See if the receiver is receiver[n].
1283 int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row));
1284 test_mdp_data_at(mdp, recvr_offset, receiver,
1285 (test_for_null_also ? reg2 : noreg),
1286 next_test);
1287 // (Reg2 now contains the receiver from the CallData.)
1289 // The receiver is receiver[n]. Increment count[n].
1290 int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row));
1291 increment_mdp_data_at(mdp, count_offset);
1292 jmp(done);
1293 bind(next_test);
1295 if (test_for_null_also) {
1296 // Failed the equality check on receiver[n]... Test for null.
1297 testptr(reg2, reg2);
1298 if (start_row == last_row) {
1299 // The only thing left to do is handle the null case.
1300 jcc(Assembler::notZero, done);
1301 break;
1302 }
1303 // Since null is rare, make it be the branch-taken case.
1304 Label found_null;
1305 jcc(Assembler::zero, found_null);
1307 // Put all the "Case 3" tests here.
1308 record_klass_in_profile_helper(receiver, mdp, reg2, start_row + 1, done);
1310 // Found a null. Keep searching for a matching receiver,
1311 // but remember that this is an empty (unused) slot.
1312 bind(found_null);
1313 }
1314 }
1316 // In the fall-through case, we found no matching receiver, but we
1317 // observed the receiver[start_row] is NULL.
1319 // Fill in the receiver field and increment the count.
1320 int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row));
1321 set_mdp_data_at(mdp, recvr_offset, receiver);
1322 int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row));
1323 movl(reg2, DataLayout::counter_increment);
1324 set_mdp_data_at(mdp, count_offset, reg2);
1325 jmp(done);
1326 }
1328 // Example state machine code for three profile rows:
1329 // // main copy of decision tree, rooted at row[1]
1330 // if (row[0].rec == rec) { row[0].incr(); goto done; }
1331 // if (row[0].rec != NULL) {
1332 // // inner copy of decision tree, rooted at row[1]
1333 // if (row[1].rec == rec) { row[1].incr(); goto done; }
1334 // if (row[1].rec != NULL) {
1335 // // degenerate decision tree, rooted at row[2]
1336 // if (row[2].rec == rec) { row[2].incr(); goto done; }
1337 // if (row[2].rec != NULL) { goto done; } // overflow
1338 // row[2].init(rec); goto done;
1339 // } else {
1340 // // remember row[1] is empty
1341 // if (row[2].rec == rec) { row[2].incr(); goto done; }
1342 // row[1].init(rec); goto done;
1343 // }
1344 // } else {
1345 // // remember row[0] is empty
1346 // if (row[1].rec == rec) { row[1].incr(); goto done; }
1347 // if (row[2].rec == rec) { row[2].incr(); goto done; }
1348 // row[0].init(rec); goto done;
1349 // }
1351 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,
1352 Register mdp,
1353 Register reg2) {
1354 assert(ProfileInterpreter, "must be profiling");
1355 Label done;
1357 record_klass_in_profile_helper(receiver, mdp, reg2, 0, done);
1359 bind (done);
1360 }
1362 void InterpreterMacroAssembler::profile_ret(Register return_bci,
1363 Register mdp) {
1364 if (ProfileInterpreter) {
1365 Label profile_continue;
1366 uint row;
1368 // If no method data exists, go to profile_continue.
1369 test_method_data_pointer(mdp, profile_continue);
1371 // Update the total ret count.
1372 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1374 for (row = 0; row < RetData::row_limit(); row++) {
1375 Label next_test;
1377 // See if return_bci is equal to bci[n]:
1378 test_mdp_data_at(mdp,
1379 in_bytes(RetData::bci_offset(row)),
1380 return_bci, noreg,
1381 next_test);
1383 // return_bci is equal to bci[n]. Increment the count.
1384 increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row)));
1386 // The method data pointer needs to be updated to reflect the new target.
1387 update_mdp_by_offset(mdp,
1388 in_bytes(RetData::bci_displacement_offset(row)));
1389 jmp(profile_continue);
1390 bind(next_test);
1391 }
1393 update_mdp_for_ret(return_bci);
1395 bind(profile_continue);
1396 }
1397 }
1400 void InterpreterMacroAssembler::profile_null_seen(Register mdp) {
1401 if (ProfileInterpreter) {
1402 Label profile_continue;
1404 // If no method data exists, go to profile_continue.
1405 test_method_data_pointer(mdp, profile_continue);
1407 // The method data pointer needs to be updated.
1408 int mdp_delta = in_bytes(BitData::bit_data_size());
1409 if (TypeProfileCasts) {
1410 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1411 }
1412 update_mdp_by_constant(mdp, mdp_delta);
1414 bind(profile_continue);
1415 }
1416 }
1419 void InterpreterMacroAssembler::profile_typecheck_failed(Register mdp) {
1420 if (ProfileInterpreter && TypeProfileCasts) {
1421 Label profile_continue;
1423 // If no method data exists, go to profile_continue.
1424 test_method_data_pointer(mdp, profile_continue);
1426 int count_offset = in_bytes(CounterData::count_offset());
1427 // Back up the address, since we have already bumped the mdp.
1428 count_offset -= in_bytes(VirtualCallData::virtual_call_data_size());
1430 // *Decrement* the counter. We expect to see zero or small negatives.
1431 increment_mdp_data_at(mdp, count_offset, true);
1433 bind (profile_continue);
1434 }
1435 }
1438 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) {
1439 if (ProfileInterpreter) {
1440 Label profile_continue;
1442 // If no method data exists, go to profile_continue.
1443 test_method_data_pointer(mdp, profile_continue);
1445 // The method data pointer needs to be updated.
1446 int mdp_delta = in_bytes(BitData::bit_data_size());
1447 if (TypeProfileCasts) {
1448 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1450 // Record the object type.
1451 record_klass_in_profile(klass, mdp, reg2);
1452 }
1453 update_mdp_by_constant(mdp, mdp_delta);
1455 bind(profile_continue);
1456 }
1457 }
1460 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
1461 if (ProfileInterpreter) {
1462 Label profile_continue;
1464 // If no method data exists, go to profile_continue.
1465 test_method_data_pointer(mdp, profile_continue);
1467 // Update the default case count
1468 increment_mdp_data_at(mdp,
1469 in_bytes(MultiBranchData::default_count_offset()));
1471 // The method data pointer needs to be updated.
1472 update_mdp_by_offset(mdp,
1473 in_bytes(MultiBranchData::
1474 default_displacement_offset()));
1476 bind(profile_continue);
1477 }
1478 }
1481 void InterpreterMacroAssembler::profile_switch_case(Register index,
1482 Register mdp,
1483 Register reg2) {
1484 if (ProfileInterpreter) {
1485 Label profile_continue;
1487 // If no method data exists, go to profile_continue.
1488 test_method_data_pointer(mdp, profile_continue);
1490 // Build the base (index * per_case_size_in_bytes()) +
1491 // case_array_offset_in_bytes()
1492 movl(reg2, in_bytes(MultiBranchData::per_case_size()));
1493 imulptr(index, reg2); // XXX l ?
1494 addptr(index, in_bytes(MultiBranchData::case_array_offset())); // XXX l ?
1496 // Update the case count
1497 increment_mdp_data_at(mdp,
1498 index,
1499 in_bytes(MultiBranchData::relative_count_offset()));
1501 // The method data pointer needs to be updated.
1502 update_mdp_by_offset(mdp,
1503 index,
1504 in_bytes(MultiBranchData::
1505 relative_displacement_offset()));
1507 bind(profile_continue);
1508 }
1509 }
1513 void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) {
1514 if (state == atos) {
1515 MacroAssembler::verify_oop(reg);
1516 }
1517 }
1519 void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) {
1520 }
1521 #endif // !CC_INTERP
1524 void InterpreterMacroAssembler::notify_method_entry() {
1525 // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
1526 // track stack depth. If it is possible to enter interp_only_mode we add
1527 // the code to check if the event should be sent.
1528 if (JvmtiExport::can_post_interpreter_events()) {
1529 Label L;
1530 movl(rdx, Address(r15_thread, JavaThread::interp_only_mode_offset()));
1531 testl(rdx, rdx);
1532 jcc(Assembler::zero, L);
1533 call_VM(noreg, CAST_FROM_FN_PTR(address,
1534 InterpreterRuntime::post_method_entry));
1535 bind(L);
1536 }
1538 {
1539 SkipIfEqual skip(this, &DTraceMethodProbes, false);
1540 get_method(c_rarg1);
1541 call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
1542 r15_thread, c_rarg1);
1543 }
1545 // RedefineClasses() tracing support for obsolete method entry
1546 if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
1547 get_method(c_rarg1);
1548 call_VM_leaf(
1549 CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
1550 r15_thread, c_rarg1);
1551 }
1552 }
1555 void InterpreterMacroAssembler::notify_method_exit(
1556 TosState state, NotifyMethodExitMode mode) {
1557 // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
1558 // track stack depth. If it is possible to enter interp_only_mode we add
1559 // the code to check if the event should be sent.
1560 if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {
1561 Label L;
1562 // Note: frame::interpreter_frame_result has a dependency on how the
1563 // method result is saved across the call to post_method_exit. If this
1564 // is changed then the interpreter_frame_result implementation will
1565 // need to be updated too.
1567 // For c++ interpreter the result is always stored at a known location in the frame
1568 // template interpreter will leave it on the top of the stack.
1569 NOT_CC_INTERP(push(state);)
1570 movl(rdx, Address(r15_thread, JavaThread::interp_only_mode_offset()));
1571 testl(rdx, rdx);
1572 jcc(Assembler::zero, L);
1573 call_VM(noreg,
1574 CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit));
1575 bind(L);
1576 NOT_CC_INTERP(pop(state));
1577 }
1579 {
1580 SkipIfEqual skip(this, &DTraceMethodProbes, false);
1581 NOT_CC_INTERP(push(state));
1582 get_method(c_rarg1);
1583 call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
1584 r15_thread, c_rarg1);
1585 NOT_CC_INTERP(pop(state));
1586 }
1587 }