Fri, 26 Jun 2009 16:14:31 -0700
6851908: interpreter null check profiling broken causing extra compilation invalidation
Reviewed-by: kvn
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 void InterpreterMacroAssembler::prepare_to_jump_from_interpreted() {
555 // set sender sp
556 lea(r13, Address(rsp, wordSize));
557 // record last_sp
558 movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), r13);
559 }
562 // Jump to from_interpreted entry of a call unless single stepping is possible
563 // in this thread in which case we must call the i2i entry
564 void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) {
565 prepare_to_jump_from_interpreted();
567 if (JvmtiExport::can_post_interpreter_events()) {
568 Label run_compiled_code;
569 // JVMTI events, such as single-stepping, are implemented partly by avoiding running
570 // compiled code in threads for which the event is enabled. Check here for
571 // interp_only_mode if these events CAN be enabled.
572 get_thread(temp);
573 // interp_only is an int, on little endian it is sufficient to test the byte only
574 // Is a cmpl faster (ce
575 cmpb(Address(temp, JavaThread::interp_only_mode_offset()), 0);
576 jcc(Assembler::zero, run_compiled_code);
577 jmp(Address(method, methodOopDesc::interpreter_entry_offset()));
578 bind(run_compiled_code);
579 }
581 jmp(Address(method, methodOopDesc::from_interpreted_offset()));
583 }
586 // The following two routines provide a hook so that an implementation
587 // can schedule the dispatch in two parts. amd64 does not do this.
588 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) {
589 // Nothing amd64 specific to be done here
590 }
592 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) {
593 dispatch_next(state, step);
594 }
596 void InterpreterMacroAssembler::dispatch_base(TosState state,
597 address* table,
598 bool verifyoop) {
599 verify_FPU(1, state);
600 if (VerifyActivationFrameSize) {
601 Label L;
602 mov(rcx, rbp);
603 subptr(rcx, rsp);
604 int32_t min_frame_size =
605 (frame::link_offset - frame::interpreter_frame_initial_sp_offset) *
606 wordSize;
607 cmpptr(rcx, (int32_t)min_frame_size);
608 jcc(Assembler::greaterEqual, L);
609 stop("broken stack frame");
610 bind(L);
611 }
612 if (verifyoop) {
613 verify_oop(rax, state);
614 }
615 lea(rscratch1, ExternalAddress((address)table));
616 jmp(Address(rscratch1, rbx, Address::times_8));
617 }
619 void InterpreterMacroAssembler::dispatch_only(TosState state) {
620 dispatch_base(state, Interpreter::dispatch_table(state));
621 }
623 void InterpreterMacroAssembler::dispatch_only_normal(TosState state) {
624 dispatch_base(state, Interpreter::normal_table(state));
625 }
627 void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) {
628 dispatch_base(state, Interpreter::normal_table(state), false);
629 }
632 void InterpreterMacroAssembler::dispatch_next(TosState state, int step) {
633 // load next bytecode (load before advancing r13 to prevent AGI)
634 load_unsigned_byte(rbx, Address(r13, step));
635 // advance r13
636 increment(r13, step);
637 dispatch_base(state, Interpreter::dispatch_table(state));
638 }
640 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
641 // load current bytecode
642 load_unsigned_byte(rbx, Address(r13, 0));
643 dispatch_base(state, table);
644 }
646 // remove activation
647 //
648 // Unlock the receiver if this is a synchronized method.
649 // Unlock any Java monitors from syncronized blocks.
650 // Remove the activation from the stack.
651 //
652 // If there are locked Java monitors
653 // If throw_monitor_exception
654 // throws IllegalMonitorStateException
655 // Else if install_monitor_exception
656 // installs IllegalMonitorStateException
657 // Else
658 // no error processing
659 void InterpreterMacroAssembler::remove_activation(
660 TosState state,
661 Register ret_addr,
662 bool throw_monitor_exception,
663 bool install_monitor_exception,
664 bool notify_jvmdi) {
665 // Note: Registers rdx xmm0 may be in use for the
666 // result check if synchronized method
667 Label unlocked, unlock, no_unlock;
669 // get the value of _do_not_unlock_if_synchronized into rdx
670 const Address do_not_unlock_if_synchronized(r15_thread,
671 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
672 movbool(rdx, do_not_unlock_if_synchronized);
673 movbool(do_not_unlock_if_synchronized, false); // reset the flag
675 // get method access flags
676 movptr(rbx, Address(rbp, frame::interpreter_frame_method_offset * wordSize));
677 movl(rcx, Address(rbx, methodOopDesc::access_flags_offset()));
678 testl(rcx, JVM_ACC_SYNCHRONIZED);
679 jcc(Assembler::zero, unlocked);
681 // Don't unlock anything if the _do_not_unlock_if_synchronized flag
682 // is set.
683 testbool(rdx);
684 jcc(Assembler::notZero, no_unlock);
686 // unlock monitor
687 push(state); // save result
689 // BasicObjectLock will be first in list, since this is a
690 // synchronized method. However, need to check that the object has
691 // not been unlocked by an explicit monitorexit bytecode.
692 const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset *
693 wordSize - (int) sizeof(BasicObjectLock));
694 // We use c_rarg1 so that if we go slow path it will be the correct
695 // register for unlock_object to pass to VM directly
696 lea(c_rarg1, monitor); // address of first monitor
698 movptr(rax, Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes()));
699 testptr(rax, rax);
700 jcc(Assembler::notZero, unlock);
702 pop(state);
703 if (throw_monitor_exception) {
704 // Entry already unlocked, need to throw exception
705 call_VM(noreg, CAST_FROM_FN_PTR(address,
706 InterpreterRuntime::throw_illegal_monitor_state_exception));
707 should_not_reach_here();
708 } else {
709 // Monitor already unlocked during a stack unroll. If requested,
710 // install an illegal_monitor_state_exception. Continue with
711 // stack unrolling.
712 if (install_monitor_exception) {
713 call_VM(noreg, CAST_FROM_FN_PTR(address,
714 InterpreterRuntime::new_illegal_monitor_state_exception));
715 }
716 jmp(unlocked);
717 }
719 bind(unlock);
720 unlock_object(c_rarg1);
721 pop(state);
723 // Check that for block-structured locking (i.e., that all locked
724 // objects has been unlocked)
725 bind(unlocked);
727 // rax: Might contain return value
729 // Check that all monitors are unlocked
730 {
731 Label loop, exception, entry, restart;
732 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
733 const Address monitor_block_top(
734 rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
735 const Address monitor_block_bot(
736 rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
738 bind(restart);
739 // We use c_rarg1 so that if we go slow path it will be the correct
740 // register for unlock_object to pass to VM directly
741 movptr(c_rarg1, monitor_block_top); // points to current entry, starting
742 // with top-most entry
743 lea(rbx, monitor_block_bot); // points to word before bottom of
744 // monitor block
745 jmp(entry);
747 // Entry already locked, need to throw exception
748 bind(exception);
750 if (throw_monitor_exception) {
751 // Throw exception
752 MacroAssembler::call_VM(noreg,
753 CAST_FROM_FN_PTR(address, InterpreterRuntime::
754 throw_illegal_monitor_state_exception));
755 should_not_reach_here();
756 } else {
757 // Stack unrolling. Unlock object and install illegal_monitor_exception.
758 // Unlock does not block, so don't have to worry about the frame.
759 // We don't have to preserve c_rarg1 since we are going to throw an exception.
761 push(state);
762 unlock_object(c_rarg1);
763 pop(state);
765 if (install_monitor_exception) {
766 call_VM(noreg, CAST_FROM_FN_PTR(address,
767 InterpreterRuntime::
768 new_illegal_monitor_state_exception));
769 }
771 jmp(restart);
772 }
774 bind(loop);
775 // check if current entry is used
776 cmpptr(Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes()), (int32_t) NULL);
777 jcc(Assembler::notEqual, exception);
779 addptr(c_rarg1, entry_size); // otherwise advance to next entry
780 bind(entry);
781 cmpptr(c_rarg1, rbx); // check if bottom reached
782 jcc(Assembler::notEqual, loop); // if not at bottom then check this entry
783 }
785 bind(no_unlock);
787 // jvmti support
788 if (notify_jvmdi) {
789 notify_method_exit(state, NotifyJVMTI); // preserve TOSCA
790 } else {
791 notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA
792 }
794 // remove activation
795 // get sender sp
796 movptr(rbx,
797 Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize));
798 leave(); // remove frame anchor
799 pop(ret_addr); // get return address
800 mov(rsp, rbx); // set sp to sender sp
801 }
803 #endif // C_INTERP
805 // Lock object
806 //
807 // Args:
808 // c_rarg1: BasicObjectLock to be used for locking
809 //
810 // Kills:
811 // rax
812 // c_rarg0, c_rarg1, c_rarg2, c_rarg3, .. (param regs)
813 // rscratch1, rscratch2 (scratch regs)
814 void InterpreterMacroAssembler::lock_object(Register lock_reg) {
815 assert(lock_reg == c_rarg1, "The argument is only for looks. It must be c_rarg1");
817 if (UseHeavyMonitors) {
818 call_VM(noreg,
819 CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
820 lock_reg);
821 } else {
822 Label done;
824 const Register swap_reg = rax; // Must use rax for cmpxchg instruction
825 const Register obj_reg = c_rarg3; // Will contain the oop
827 const int obj_offset = BasicObjectLock::obj_offset_in_bytes();
828 const int lock_offset = BasicObjectLock::lock_offset_in_bytes ();
829 const int mark_offset = lock_offset +
830 BasicLock::displaced_header_offset_in_bytes();
832 Label slow_case;
834 // Load object pointer into obj_reg %c_rarg3
835 movptr(obj_reg, Address(lock_reg, obj_offset));
837 if (UseBiasedLocking) {
838 biased_locking_enter(lock_reg, obj_reg, swap_reg, rscratch1, false, done, &slow_case);
839 }
841 // Load immediate 1 into swap_reg %rax
842 movl(swap_reg, 1);
844 // Load (object->mark() | 1) into swap_reg %rax
845 orptr(swap_reg, Address(obj_reg, 0));
847 // Save (object->mark() | 1) into BasicLock's displaced header
848 movptr(Address(lock_reg, mark_offset), swap_reg);
850 assert(lock_offset == 0,
851 "displached header must be first word in BasicObjectLock");
853 if (os::is_MP()) lock();
854 cmpxchgptr(lock_reg, Address(obj_reg, 0));
855 if (PrintBiasedLockingStatistics) {
856 cond_inc32(Assembler::zero,
857 ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr()));
858 }
859 jcc(Assembler::zero, done);
861 // Test if the oopMark is an obvious stack pointer, i.e.,
862 // 1) (mark & 7) == 0, and
863 // 2) rsp <= mark < mark + os::pagesize()
864 //
865 // These 3 tests can be done by evaluating the following
866 // expression: ((mark - rsp) & (7 - os::vm_page_size())),
867 // assuming both stack pointer and pagesize have their
868 // least significant 3 bits clear.
869 // NOTE: the oopMark is in swap_reg %rax as the result of cmpxchg
870 subptr(swap_reg, rsp);
871 andptr(swap_reg, 7 - os::vm_page_size());
873 // Save the test result, for recursive case, the result is zero
874 movptr(Address(lock_reg, mark_offset), swap_reg);
876 if (PrintBiasedLockingStatistics) {
877 cond_inc32(Assembler::zero,
878 ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr()));
879 }
880 jcc(Assembler::zero, done);
882 bind(slow_case);
884 // Call the runtime routine for slow case
885 call_VM(noreg,
886 CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
887 lock_reg);
889 bind(done);
890 }
891 }
894 // Unlocks an object. Used in monitorexit bytecode and
895 // remove_activation. Throws an IllegalMonitorException if object is
896 // not locked by current thread.
897 //
898 // Args:
899 // c_rarg1: BasicObjectLock for lock
900 //
901 // Kills:
902 // rax
903 // c_rarg0, c_rarg1, c_rarg2, c_rarg3, ... (param regs)
904 // rscratch1, rscratch2 (scratch regs)
905 void InterpreterMacroAssembler::unlock_object(Register lock_reg) {
906 assert(lock_reg == c_rarg1, "The argument is only for looks. It must be rarg1");
908 if (UseHeavyMonitors) {
909 call_VM(noreg,
910 CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
911 lock_reg);
912 } else {
913 Label done;
915 const Register swap_reg = rax; // Must use rax for cmpxchg instruction
916 const Register header_reg = c_rarg2; // Will contain the old oopMark
917 const Register obj_reg = c_rarg3; // Will contain the oop
919 save_bcp(); // Save in case of exception
921 // Convert from BasicObjectLock structure to object and BasicLock
922 // structure Store the BasicLock address into %rax
923 lea(swap_reg, Address(lock_reg, BasicObjectLock::lock_offset_in_bytes()));
925 // Load oop into obj_reg(%c_rarg3)
926 movptr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()));
928 // Free entry
929 movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), (int32_t)NULL_WORD);
931 if (UseBiasedLocking) {
932 biased_locking_exit(obj_reg, header_reg, done);
933 }
935 // Load the old header from BasicLock structure
936 movptr(header_reg, Address(swap_reg,
937 BasicLock::displaced_header_offset_in_bytes()));
939 // Test for recursion
940 testptr(header_reg, header_reg);
942 // zero for recursive case
943 jcc(Assembler::zero, done);
945 // Atomic swap back the old header
946 if (os::is_MP()) lock();
947 cmpxchgptr(header_reg, Address(obj_reg, 0));
949 // zero for recursive case
950 jcc(Assembler::zero, done);
952 // Call the runtime routine for slow case.
953 movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()),
954 obj_reg); // restore obj
955 call_VM(noreg,
956 CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
957 lock_reg);
959 bind(done);
961 restore_bcp();
962 }
963 }
965 #ifndef CC_INTERP
967 void InterpreterMacroAssembler::test_method_data_pointer(Register mdp,
968 Label& zero_continue) {
969 assert(ProfileInterpreter, "must be profiling interpreter");
970 movptr(mdp, Address(rbp, frame::interpreter_frame_mdx_offset * wordSize));
971 testptr(mdp, mdp);
972 jcc(Assembler::zero, zero_continue);
973 }
976 // Set the method data pointer for the current bcp.
977 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
978 assert(ProfileInterpreter, "must be profiling interpreter");
979 Label zero_continue;
980 push(rax);
981 push(rbx);
983 get_method(rbx);
984 // Test MDO to avoid the call if it is NULL.
985 movptr(rax, Address(rbx, in_bytes(methodOopDesc::method_data_offset())));
986 testptr(rax, rax);
987 jcc(Assembler::zero, zero_continue);
989 // rbx: method
990 // r13: bcp
991 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), rbx, r13);
992 // rax: mdi
994 movptr(rbx, Address(rbx, in_bytes(methodOopDesc::method_data_offset())));
995 testptr(rbx, rbx);
996 jcc(Assembler::zero, zero_continue);
997 addptr(rbx, in_bytes(methodDataOopDesc::data_offset()));
998 addptr(rbx, rax);
999 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), rbx);
1001 bind(zero_continue);
1002 pop(rbx);
1003 pop(rax);
1004 }
1006 void InterpreterMacroAssembler::verify_method_data_pointer() {
1007 assert(ProfileInterpreter, "must be profiling interpreter");
1008 #ifdef ASSERT
1009 Label verify_continue;
1010 push(rax);
1011 push(rbx);
1012 push(c_rarg3);
1013 push(c_rarg2);
1014 test_method_data_pointer(c_rarg3, verify_continue); // If mdp is zero, continue
1015 get_method(rbx);
1017 // If the mdp is valid, it will point to a DataLayout header which is
1018 // consistent with the bcp. The converse is highly probable also.
1019 load_unsigned_short(c_rarg2,
1020 Address(c_rarg3, in_bytes(DataLayout::bci_offset())));
1021 addptr(c_rarg2, Address(rbx, methodOopDesc::const_offset()));
1022 lea(c_rarg2, Address(c_rarg2, constMethodOopDesc::codes_offset()));
1023 cmpptr(c_rarg2, r13);
1024 jcc(Assembler::equal, verify_continue);
1025 // rbx: method
1026 // r13: bcp
1027 // c_rarg3: mdp
1028 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp),
1029 rbx, r13, c_rarg3);
1030 bind(verify_continue);
1031 pop(c_rarg2);
1032 pop(c_rarg3);
1033 pop(rbx);
1034 pop(rax);
1035 #endif // ASSERT
1036 }
1039 void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in,
1040 int constant,
1041 Register value) {
1042 assert(ProfileInterpreter, "must be profiling interpreter");
1043 Address data(mdp_in, constant);
1044 movptr(data, value);
1045 }
1048 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
1049 int constant,
1050 bool decrement) {
1051 // Counter address
1052 Address data(mdp_in, constant);
1054 increment_mdp_data_at(data, decrement);
1055 }
1057 void InterpreterMacroAssembler::increment_mdp_data_at(Address data,
1058 bool decrement) {
1059 assert(ProfileInterpreter, "must be profiling interpreter");
1060 // %%% this does 64bit counters at best it is wasting space
1061 // at worst it is a rare bug when counters overflow
1063 if (decrement) {
1064 // Decrement the register. Set condition codes.
1065 addptr(data, (int32_t) -DataLayout::counter_increment);
1066 // If the decrement causes the counter to overflow, stay negative
1067 Label L;
1068 jcc(Assembler::negative, L);
1069 addptr(data, (int32_t) DataLayout::counter_increment);
1070 bind(L);
1071 } else {
1072 assert(DataLayout::counter_increment == 1,
1073 "flow-free idiom only works with 1");
1074 // Increment the register. Set carry flag.
1075 addptr(data, DataLayout::counter_increment);
1076 // If the increment causes the counter to overflow, pull back by 1.
1077 sbbptr(data, (int32_t)0);
1078 }
1079 }
1082 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
1083 Register reg,
1084 int constant,
1085 bool decrement) {
1086 Address data(mdp_in, reg, Address::times_1, constant);
1088 increment_mdp_data_at(data, decrement);
1089 }
1091 void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in,
1092 int flag_byte_constant) {
1093 assert(ProfileInterpreter, "must be profiling interpreter");
1094 int header_offset = in_bytes(DataLayout::header_offset());
1095 int header_bits = DataLayout::flag_mask_to_header_mask(flag_byte_constant);
1096 // Set the flag
1097 orl(Address(mdp_in, header_offset), header_bits);
1098 }
1102 void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in,
1103 int offset,
1104 Register value,
1105 Register test_value_out,
1106 Label& not_equal_continue) {
1107 assert(ProfileInterpreter, "must be profiling interpreter");
1108 if (test_value_out == noreg) {
1109 cmpptr(value, Address(mdp_in, offset));
1110 } else {
1111 // Put the test value into a register, so caller can use it:
1112 movptr(test_value_out, Address(mdp_in, offset));
1113 cmpptr(test_value_out, value);
1114 }
1115 jcc(Assembler::notEqual, not_equal_continue);
1116 }
1119 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
1120 int offset_of_disp) {
1121 assert(ProfileInterpreter, "must be profiling interpreter");
1122 Address disp_address(mdp_in, offset_of_disp);
1123 addptr(mdp_in, disp_address);
1124 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
1125 }
1128 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
1129 Register reg,
1130 int offset_of_disp) {
1131 assert(ProfileInterpreter, "must be profiling interpreter");
1132 Address disp_address(mdp_in, reg, Address::times_1, offset_of_disp);
1133 addptr(mdp_in, disp_address);
1134 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
1135 }
1138 void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in,
1139 int constant) {
1140 assert(ProfileInterpreter, "must be profiling interpreter");
1141 addptr(mdp_in, constant);
1142 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
1143 }
1146 void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) {
1147 assert(ProfileInterpreter, "must be profiling interpreter");
1148 push(return_bci); // save/restore across call_VM
1149 call_VM(noreg,
1150 CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret),
1151 return_bci);
1152 pop(return_bci);
1153 }
1156 void InterpreterMacroAssembler::profile_taken_branch(Register mdp,
1157 Register bumped_count) {
1158 if (ProfileInterpreter) {
1159 Label profile_continue;
1161 // If no method data exists, go to profile_continue.
1162 // Otherwise, assign to mdp
1163 test_method_data_pointer(mdp, profile_continue);
1165 // We are taking a branch. Increment the taken count.
1166 // We inline increment_mdp_data_at to return bumped_count in a register
1167 //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
1168 Address data(mdp, in_bytes(JumpData::taken_offset()));
1169 movptr(bumped_count, data);
1170 assert(DataLayout::counter_increment == 1,
1171 "flow-free idiom only works with 1");
1172 addptr(bumped_count, DataLayout::counter_increment);
1173 sbbptr(bumped_count, 0);
1174 movptr(data, bumped_count); // Store back out
1176 // The method data pointer needs to be updated to reflect the new target.
1177 update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
1178 bind(profile_continue);
1179 }
1180 }
1183 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) {
1184 if (ProfileInterpreter) {
1185 Label profile_continue;
1187 // If no method data exists, go to profile_continue.
1188 test_method_data_pointer(mdp, profile_continue);
1190 // We are taking a branch. Increment the not taken count.
1191 increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
1193 // The method data pointer needs to be updated to correspond to
1194 // the next bytecode
1195 update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size()));
1196 bind(profile_continue);
1197 }
1198 }
1201 void InterpreterMacroAssembler::profile_call(Register mdp) {
1202 if (ProfileInterpreter) {
1203 Label profile_continue;
1205 // If no method data exists, go to profile_continue.
1206 test_method_data_pointer(mdp, profile_continue);
1208 // We are making a call. Increment the count.
1209 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1211 // The method data pointer needs to be updated to reflect the new target.
1212 update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
1213 bind(profile_continue);
1214 }
1215 }
1218 void InterpreterMacroAssembler::profile_final_call(Register mdp) {
1219 if (ProfileInterpreter) {
1220 Label profile_continue;
1222 // If no method data exists, go to profile_continue.
1223 test_method_data_pointer(mdp, profile_continue);
1225 // We are making a call. Increment the count.
1226 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1228 // The method data pointer needs to be updated to reflect the new target.
1229 update_mdp_by_constant(mdp,
1230 in_bytes(VirtualCallData::
1231 virtual_call_data_size()));
1232 bind(profile_continue);
1233 }
1234 }
1237 void InterpreterMacroAssembler::profile_virtual_call(Register receiver,
1238 Register mdp,
1239 Register reg2) {
1240 if (ProfileInterpreter) {
1241 Label profile_continue;
1243 // If no method data exists, go to profile_continue.
1244 test_method_data_pointer(mdp, profile_continue);
1246 // We are making a call. Increment the count.
1247 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1249 // Record the receiver type.
1250 record_klass_in_profile(receiver, mdp, reg2);
1252 // The method data pointer needs to be updated to reflect the new target.
1253 update_mdp_by_constant(mdp,
1254 in_bytes(VirtualCallData::
1255 virtual_call_data_size()));
1256 bind(profile_continue);
1257 }
1258 }
1260 // This routine creates a state machine for updating the multi-row
1261 // type profile at a virtual call site (or other type-sensitive bytecode).
1262 // The machine visits each row (of receiver/count) until the receiver type
1263 // is found, or until it runs out of rows. At the same time, it remembers
1264 // the location of the first empty row. (An empty row records null for its
1265 // receiver, and can be allocated for a newly-observed receiver type.)
1266 // Because there are two degrees of freedom in the state, a simple linear
1267 // search will not work; it must be a decision tree. Hence this helper
1268 // function is recursive, to generate the required tree structured code.
1269 // It's the interpreter, so we are trading off code space for speed.
1270 // See below for example code.
1271 void InterpreterMacroAssembler::record_klass_in_profile_helper(
1272 Register receiver, Register mdp,
1273 Register reg2,
1274 int start_row, Label& done) {
1275 int last_row = VirtualCallData::row_limit() - 1;
1276 assert(start_row <= last_row, "must be work left to do");
1277 // Test this row for both the receiver and for null.
1278 // Take any of three different outcomes:
1279 // 1. found receiver => increment count and goto done
1280 // 2. found null => keep looking for case 1, maybe allocate this cell
1281 // 3. found something else => keep looking for cases 1 and 2
1282 // Case 3 is handled by a recursive call.
1283 for (int row = start_row; row <= last_row; row++) {
1284 Label next_test;
1285 bool test_for_null_also = (row == start_row);
1287 // See if the receiver is receiver[n].
1288 int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row));
1289 test_mdp_data_at(mdp, recvr_offset, receiver,
1290 (test_for_null_also ? reg2 : noreg),
1291 next_test);
1292 // (Reg2 now contains the receiver from the CallData.)
1294 // The receiver is receiver[n]. Increment count[n].
1295 int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row));
1296 increment_mdp_data_at(mdp, count_offset);
1297 jmp(done);
1298 bind(next_test);
1300 if (test_for_null_also) {
1301 // Failed the equality check on receiver[n]... Test for null.
1302 testptr(reg2, reg2);
1303 if (start_row == last_row) {
1304 // The only thing left to do is handle the null case.
1305 jcc(Assembler::notZero, done);
1306 break;
1307 }
1308 // Since null is rare, make it be the branch-taken case.
1309 Label found_null;
1310 jcc(Assembler::zero, found_null);
1312 // Put all the "Case 3" tests here.
1313 record_klass_in_profile_helper(receiver, mdp, reg2, start_row + 1, done);
1315 // Found a null. Keep searching for a matching receiver,
1316 // but remember that this is an empty (unused) slot.
1317 bind(found_null);
1318 }
1319 }
1321 // In the fall-through case, we found no matching receiver, but we
1322 // observed the receiver[start_row] is NULL.
1324 // Fill in the receiver field and increment the count.
1325 int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row));
1326 set_mdp_data_at(mdp, recvr_offset, receiver);
1327 int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row));
1328 movl(reg2, DataLayout::counter_increment);
1329 set_mdp_data_at(mdp, count_offset, reg2);
1330 jmp(done);
1331 }
1333 // Example state machine code for three profile rows:
1334 // // main copy of decision tree, rooted at row[1]
1335 // if (row[0].rec == rec) { row[0].incr(); goto done; }
1336 // if (row[0].rec != NULL) {
1337 // // inner copy of decision tree, rooted at row[1]
1338 // if (row[1].rec == rec) { row[1].incr(); goto done; }
1339 // if (row[1].rec != NULL) {
1340 // // degenerate decision tree, rooted at row[2]
1341 // if (row[2].rec == rec) { row[2].incr(); goto done; }
1342 // if (row[2].rec != NULL) { goto done; } // overflow
1343 // row[2].init(rec); goto done;
1344 // } else {
1345 // // remember row[1] is empty
1346 // if (row[2].rec == rec) { row[2].incr(); goto done; }
1347 // row[1].init(rec); goto done;
1348 // }
1349 // } else {
1350 // // remember row[0] is empty
1351 // if (row[1].rec == rec) { row[1].incr(); goto done; }
1352 // if (row[2].rec == rec) { row[2].incr(); goto done; }
1353 // row[0].init(rec); goto done;
1354 // }
1356 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,
1357 Register mdp,
1358 Register reg2) {
1359 assert(ProfileInterpreter, "must be profiling");
1360 Label done;
1362 record_klass_in_profile_helper(receiver, mdp, reg2, 0, done);
1364 bind (done);
1365 }
1367 void InterpreterMacroAssembler::profile_ret(Register return_bci,
1368 Register mdp) {
1369 if (ProfileInterpreter) {
1370 Label profile_continue;
1371 uint row;
1373 // If no method data exists, go to profile_continue.
1374 test_method_data_pointer(mdp, profile_continue);
1376 // Update the total ret count.
1377 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1379 for (row = 0; row < RetData::row_limit(); row++) {
1380 Label next_test;
1382 // See if return_bci is equal to bci[n]:
1383 test_mdp_data_at(mdp,
1384 in_bytes(RetData::bci_offset(row)),
1385 return_bci, noreg,
1386 next_test);
1388 // return_bci is equal to bci[n]. Increment the count.
1389 increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row)));
1391 // The method data pointer needs to be updated to reflect the new target.
1392 update_mdp_by_offset(mdp,
1393 in_bytes(RetData::bci_displacement_offset(row)));
1394 jmp(profile_continue);
1395 bind(next_test);
1396 }
1398 update_mdp_for_ret(return_bci);
1400 bind(profile_continue);
1401 }
1402 }
1405 void InterpreterMacroAssembler::profile_null_seen(Register mdp) {
1406 if (ProfileInterpreter) {
1407 Label profile_continue;
1409 // If no method data exists, go to profile_continue.
1410 test_method_data_pointer(mdp, profile_continue);
1412 set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
1414 // The method data pointer needs to be updated.
1415 int mdp_delta = in_bytes(BitData::bit_data_size());
1416 if (TypeProfileCasts) {
1417 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1418 }
1419 update_mdp_by_constant(mdp, mdp_delta);
1421 bind(profile_continue);
1422 }
1423 }
1426 void InterpreterMacroAssembler::profile_typecheck_failed(Register mdp) {
1427 if (ProfileInterpreter && TypeProfileCasts) {
1428 Label profile_continue;
1430 // If no method data exists, go to profile_continue.
1431 test_method_data_pointer(mdp, profile_continue);
1433 int count_offset = in_bytes(CounterData::count_offset());
1434 // Back up the address, since we have already bumped the mdp.
1435 count_offset -= in_bytes(VirtualCallData::virtual_call_data_size());
1437 // *Decrement* the counter. We expect to see zero or small negatives.
1438 increment_mdp_data_at(mdp, count_offset, true);
1440 bind (profile_continue);
1441 }
1442 }
1445 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) {
1446 if (ProfileInterpreter) {
1447 Label profile_continue;
1449 // If no method data exists, go to profile_continue.
1450 test_method_data_pointer(mdp, profile_continue);
1452 // The method data pointer needs to be updated.
1453 int mdp_delta = in_bytes(BitData::bit_data_size());
1454 if (TypeProfileCasts) {
1455 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1457 // Record the object type.
1458 record_klass_in_profile(klass, mdp, reg2);
1459 }
1460 update_mdp_by_constant(mdp, mdp_delta);
1462 bind(profile_continue);
1463 }
1464 }
1467 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
1468 if (ProfileInterpreter) {
1469 Label profile_continue;
1471 // If no method data exists, go to profile_continue.
1472 test_method_data_pointer(mdp, profile_continue);
1474 // Update the default case count
1475 increment_mdp_data_at(mdp,
1476 in_bytes(MultiBranchData::default_count_offset()));
1478 // The method data pointer needs to be updated.
1479 update_mdp_by_offset(mdp,
1480 in_bytes(MultiBranchData::
1481 default_displacement_offset()));
1483 bind(profile_continue);
1484 }
1485 }
1488 void InterpreterMacroAssembler::profile_switch_case(Register index,
1489 Register mdp,
1490 Register reg2) {
1491 if (ProfileInterpreter) {
1492 Label profile_continue;
1494 // If no method data exists, go to profile_continue.
1495 test_method_data_pointer(mdp, profile_continue);
1497 // Build the base (index * per_case_size_in_bytes()) +
1498 // case_array_offset_in_bytes()
1499 movl(reg2, in_bytes(MultiBranchData::per_case_size()));
1500 imulptr(index, reg2); // XXX l ?
1501 addptr(index, in_bytes(MultiBranchData::case_array_offset())); // XXX l ?
1503 // Update the case count
1504 increment_mdp_data_at(mdp,
1505 index,
1506 in_bytes(MultiBranchData::relative_count_offset()));
1508 // The method data pointer needs to be updated.
1509 update_mdp_by_offset(mdp,
1510 index,
1511 in_bytes(MultiBranchData::
1512 relative_displacement_offset()));
1514 bind(profile_continue);
1515 }
1516 }
1520 void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) {
1521 if (state == atos) {
1522 MacroAssembler::verify_oop(reg);
1523 }
1524 }
1526 void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) {
1527 }
1528 #endif // !CC_INTERP
1531 void InterpreterMacroAssembler::notify_method_entry() {
1532 // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
1533 // track stack depth. If it is possible to enter interp_only_mode we add
1534 // the code to check if the event should be sent.
1535 if (JvmtiExport::can_post_interpreter_events()) {
1536 Label L;
1537 movl(rdx, Address(r15_thread, JavaThread::interp_only_mode_offset()));
1538 testl(rdx, rdx);
1539 jcc(Assembler::zero, L);
1540 call_VM(noreg, CAST_FROM_FN_PTR(address,
1541 InterpreterRuntime::post_method_entry));
1542 bind(L);
1543 }
1545 {
1546 SkipIfEqual skip(this, &DTraceMethodProbes, false);
1547 get_method(c_rarg1);
1548 call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
1549 r15_thread, c_rarg1);
1550 }
1552 // RedefineClasses() tracing support for obsolete method entry
1553 if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
1554 get_method(c_rarg1);
1555 call_VM_leaf(
1556 CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
1557 r15_thread, c_rarg1);
1558 }
1559 }
1562 void InterpreterMacroAssembler::notify_method_exit(
1563 TosState state, NotifyMethodExitMode mode) {
1564 // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
1565 // track stack depth. If it is possible to enter interp_only_mode we add
1566 // the code to check if the event should be sent.
1567 if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {
1568 Label L;
1569 // Note: frame::interpreter_frame_result has a dependency on how the
1570 // method result is saved across the call to post_method_exit. If this
1571 // is changed then the interpreter_frame_result implementation will
1572 // need to be updated too.
1574 // For c++ interpreter the result is always stored at a known location in the frame
1575 // template interpreter will leave it on the top of the stack.
1576 NOT_CC_INTERP(push(state);)
1577 movl(rdx, Address(r15_thread, JavaThread::interp_only_mode_offset()));
1578 testl(rdx, rdx);
1579 jcc(Assembler::zero, L);
1580 call_VM(noreg,
1581 CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit));
1582 bind(L);
1583 NOT_CC_INTERP(pop(state));
1584 }
1586 {
1587 SkipIfEqual skip(this, &DTraceMethodProbes, false);
1588 NOT_CC_INTERP(push(state));
1589 get_method(c_rarg1);
1590 call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
1591 r15_thread, c_rarg1);
1592 NOT_CC_INTERP(pop(state));
1593 }
1594 }