Fri, 26 Jun 2009 07:26:10 -0700
5057225: Remove useless I2L conversions
Summary: The optimizer should be told to normalize (AndL (ConvI2L x) 0xFF) to (ConvI2L (AndI x 0xFF)), and then the existing matcher rule will work for free.
Reviewed-by: kvn
1 /*
2 * Copyright 1997-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_32.cpp.incl"
29 // Implementation of InterpreterMacroAssembler
30 #ifdef CC_INTERP
31 void InterpreterMacroAssembler::get_method(Register reg) {
32 movptr(reg, Address(rbp, -(sizeof(BytecodeInterpreter) + 2 * wordSize)));
33 movptr(reg, Address(reg, byte_offset_of(BytecodeInterpreter, _method)));
34 }
35 #endif // CC_INTERP
38 #ifndef CC_INTERP
39 void InterpreterMacroAssembler::call_VM_leaf_base(
40 address entry_point,
41 int number_of_arguments
42 ) {
43 // interpreter specific
44 //
45 // Note: No need to save/restore bcp & locals (rsi & rdi) pointer
46 // since these are callee saved registers and no blocking/
47 // GC can happen in leaf calls.
48 // Further Note: DO NOT save/restore bcp/locals. If a caller has
49 // already saved them so that it can use rsi/rdi as temporaries
50 // then a save/restore here will DESTROY the copy the caller
51 // saved! There used to be a save_bcp() that only happened in
52 // the ASSERT path (no restore_bcp). Which caused bizarre failures
53 // when jvm built with ASSERTs.
54 #ifdef ASSERT
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: last_sp != NULL");
59 bind(L);
60 }
61 #endif
62 // super call
63 MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments);
64 // interpreter specific
66 // Used to ASSERT that rsi/rdi were equal to frame's bcp/locals
67 // but since they may not have been saved (and we don't want to
68 // save them here (see note above) the assert is invalid.
69 }
72 void InterpreterMacroAssembler::call_VM_base(
73 Register oop_result,
74 Register java_thread,
75 Register last_java_sp,
76 address entry_point,
77 int number_of_arguments,
78 bool check_exceptions
79 ) {
80 #ifdef ASSERT
81 { Label L;
82 cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
83 jcc(Assembler::equal, L);
84 stop("InterpreterMacroAssembler::call_VM_base: last_sp != NULL");
85 bind(L);
86 }
87 #endif /* ASSERT */
88 // interpreter specific
89 //
90 // Note: Could avoid restoring locals ptr (callee saved) - however doesn't
91 // really make a difference for these runtime calls, since they are
92 // slow anyway. Btw., bcp must be saved/restored since it may change
93 // due to GC.
94 assert(java_thread == noreg , "not expecting a precomputed java thread");
95 save_bcp();
96 // super call
97 MacroAssembler::call_VM_base(oop_result, java_thread, last_java_sp, entry_point, number_of_arguments, check_exceptions);
98 // interpreter specific
99 restore_bcp();
100 restore_locals();
101 }
104 void InterpreterMacroAssembler::check_and_handle_popframe(Register java_thread) {
105 if (JvmtiExport::can_pop_frame()) {
106 Label L;
107 // Initiate popframe handling only if it is not already being processed. If the flag
108 // has the popframe_processing bit set, it means that this code is called *during* popframe
109 // handling - we don't want to reenter.
110 Register pop_cond = java_thread; // Not clear if any other register is available...
111 movl(pop_cond, Address(java_thread, JavaThread::popframe_condition_offset()));
112 testl(pop_cond, JavaThread::popframe_pending_bit);
113 jcc(Assembler::zero, L);
114 testl(pop_cond, JavaThread::popframe_processing_bit);
115 jcc(Assembler::notZero, L);
116 // Call Interpreter::remove_activation_preserving_args_entry() to get the
117 // address of the same-named entrypoint in the generated interpreter code.
118 call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry));
119 jmp(rax);
120 bind(L);
121 get_thread(java_thread);
122 }
123 }
126 void InterpreterMacroAssembler::load_earlyret_value(TosState state) {
127 get_thread(rcx);
128 movl(rcx, Address(rcx, JavaThread::jvmti_thread_state_offset()));
129 const Address tos_addr (rcx, JvmtiThreadState::earlyret_tos_offset());
130 const Address oop_addr (rcx, JvmtiThreadState::earlyret_oop_offset());
131 const Address val_addr (rcx, JvmtiThreadState::earlyret_value_offset());
132 const Address val_addr1(rcx, JvmtiThreadState::earlyret_value_offset()
133 + in_ByteSize(wordSize));
134 switch (state) {
135 case atos: movptr(rax, oop_addr);
136 movptr(oop_addr, NULL_WORD);
137 verify_oop(rax, state); break;
138 case ltos:
139 movl(rdx, val_addr1); // fall through
140 case btos: // fall through
141 case ctos: // fall through
142 case stos: // fall through
143 case itos: movl(rax, val_addr); break;
144 case ftos: fld_s(val_addr); break;
145 case dtos: fld_d(val_addr); break;
146 case vtos: /* nothing to do */ break;
147 default : ShouldNotReachHere();
148 }
149 // Clean up tos value in the thread object
150 movl(tos_addr, (int32_t) ilgl);
151 movptr(val_addr, NULL_WORD);
152 NOT_LP64(movptr(val_addr1, NULL_WORD));
153 }
156 void InterpreterMacroAssembler::check_and_handle_earlyret(Register java_thread) {
157 if (JvmtiExport::can_force_early_return()) {
158 Label L;
159 Register tmp = java_thread;
160 movptr(tmp, Address(tmp, JavaThread::jvmti_thread_state_offset()));
161 testptr(tmp, tmp);
162 jcc(Assembler::zero, L); // if (thread->jvmti_thread_state() == NULL) exit;
164 // Initiate earlyret handling only if it is not already being processed.
165 // If the flag has the earlyret_processing bit set, it means that this code
166 // is called *during* earlyret handling - we don't want to reenter.
167 movl(tmp, Address(tmp, JvmtiThreadState::earlyret_state_offset()));
168 cmpl(tmp, JvmtiThreadState::earlyret_pending);
169 jcc(Assembler::notEqual, L);
171 // Call Interpreter::remove_activation_early_entry() to get the address of the
172 // same-named entrypoint in the generated interpreter code.
173 get_thread(java_thread);
174 movptr(tmp, Address(java_thread, JavaThread::jvmti_thread_state_offset()));
175 pushl(Address(tmp, JvmtiThreadState::earlyret_tos_offset()));
176 call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), 1);
177 jmp(rax);
178 bind(L);
179 get_thread(java_thread);
180 }
181 }
184 void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp(Register reg, int bcp_offset) {
185 assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode");
186 movl(reg, Address(rsi, bcp_offset));
187 bswapl(reg);
188 shrl(reg, 16);
189 }
192 void InterpreterMacroAssembler::get_cache_index_at_bcp(Register reg, int bcp_offset, bool giant_index) {
193 assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
194 if (!giant_index) {
195 load_unsigned_short(reg, Address(rsi, bcp_offset));
196 } else {
197 assert(EnableInvokeDynamic, "giant index used only for EnableInvokeDynamic");
198 movl(reg, Address(rsi, bcp_offset));
199 assert(constantPoolCacheOopDesc::decode_secondary_index(~123) == 123, "else change next line");
200 notl(reg); // convert to plain index
201 }
202 }
205 void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache, Register index,
206 int bcp_offset, bool giant_index) {
207 assert(cache != index, "must use different registers");
208 get_cache_index_at_bcp(index, bcp_offset, giant_index);
209 movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize));
210 assert(sizeof(ConstantPoolCacheEntry) == 4*wordSize, "adjust code below");
211 shlptr(index, 2); // convert from field index to ConstantPoolCacheEntry index
212 }
215 void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache, Register tmp,
216 int bcp_offset, bool giant_index) {
217 assert(cache != tmp, "must use different register");
218 get_cache_index_at_bcp(tmp, bcp_offset, giant_index);
219 assert(sizeof(ConstantPoolCacheEntry) == 4*wordSize, "adjust code below");
220 // convert from field index to ConstantPoolCacheEntry index
221 // and from word offset to byte offset
222 shll(tmp, 2 + LogBytesPerWord);
223 movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize));
224 // skip past the header
225 addptr(cache, in_bytes(constantPoolCacheOopDesc::base_offset()));
226 addptr(cache, tmp); // construct pointer to cache entry
227 }
230 // Generate a subtype check: branch to ok_is_subtype if sub_klass is
231 // a subtype of super_klass. EAX holds the super_klass. Blows ECX.
232 // Resets EDI to locals. Register sub_klass cannot be any of the above.
233 void InterpreterMacroAssembler::gen_subtype_check( Register Rsub_klass, Label &ok_is_subtype ) {
234 assert( Rsub_klass != rax, "rax, holds superklass" );
235 assert( Rsub_klass != rcx, "used as a temp" );
236 assert( Rsub_klass != rdi, "used as a temp, restored from locals" );
238 // Profile the not-null value's klass.
239 profile_typecheck(rcx, Rsub_klass, rdi); // blows rcx, reloads rdi
241 // Do the check.
242 check_klass_subtype(Rsub_klass, rax, rcx, ok_is_subtype); // blows rcx
244 // Profile the failure of the check.
245 profile_typecheck_failed(rcx); // blows rcx
246 }
248 void InterpreterMacroAssembler::f2ieee() {
249 if (IEEEPrecision) {
250 fstp_s(Address(rsp, 0));
251 fld_s(Address(rsp, 0));
252 }
253 }
256 void InterpreterMacroAssembler::d2ieee() {
257 if (IEEEPrecision) {
258 fstp_d(Address(rsp, 0));
259 fld_d(Address(rsp, 0));
260 }
261 }
263 // Java Expression Stack
265 #ifdef ASSERT
266 void InterpreterMacroAssembler::verify_stack_tag(frame::Tag t) {
267 if (TaggedStackInterpreter) {
268 Label okay;
269 cmpptr(Address(rsp, wordSize), (int32_t)t);
270 jcc(Assembler::equal, okay);
271 // Also compare if the stack value is zero, then the tag might
272 // not have been set coming from deopt.
273 cmpptr(Address(rsp, 0), 0);
274 jcc(Assembler::equal, okay);
275 stop("Java Expression stack tag value is bad");
276 bind(okay);
277 }
278 }
279 #endif // ASSERT
281 void InterpreterMacroAssembler::pop_ptr(Register r) {
282 debug_only(verify_stack_tag(frame::TagReference));
283 pop(r);
284 if (TaggedStackInterpreter) addptr(rsp, 1 * wordSize);
285 }
287 void InterpreterMacroAssembler::pop_ptr(Register r, Register tag) {
288 pop(r);
289 // Tag may not be reference for jsr, can be returnAddress
290 if (TaggedStackInterpreter) pop(tag);
291 }
293 void InterpreterMacroAssembler::pop_i(Register r) {
294 debug_only(verify_stack_tag(frame::TagValue));
295 pop(r);
296 if (TaggedStackInterpreter) addptr(rsp, 1 * wordSize);
297 }
299 void InterpreterMacroAssembler::pop_l(Register lo, Register hi) {
300 debug_only(verify_stack_tag(frame::TagValue));
301 pop(lo);
302 if (TaggedStackInterpreter) addptr(rsp, 1 * wordSize);
303 debug_only(verify_stack_tag(frame::TagValue));
304 pop(hi);
305 if (TaggedStackInterpreter) addptr(rsp, 1 * wordSize);
306 }
308 void InterpreterMacroAssembler::pop_f() {
309 debug_only(verify_stack_tag(frame::TagValue));
310 fld_s(Address(rsp, 0));
311 addptr(rsp, 1 * wordSize);
312 if (TaggedStackInterpreter) addptr(rsp, 1 * wordSize);
313 }
315 void InterpreterMacroAssembler::pop_d() {
316 // Write double to stack contiguously and load into ST0
317 pop_dtos_to_rsp();
318 fld_d(Address(rsp, 0));
319 addptr(rsp, 2 * wordSize);
320 }
323 // Pop the top of the java expression stack to execution stack (which
324 // happens to be the same place).
325 void InterpreterMacroAssembler::pop_dtos_to_rsp() {
326 if (TaggedStackInterpreter) {
327 // Pop double value into scratch registers
328 debug_only(verify_stack_tag(frame::TagValue));
329 pop(rax);
330 addptr(rsp, 1* wordSize);
331 debug_only(verify_stack_tag(frame::TagValue));
332 pop(rdx);
333 addptr(rsp, 1* wordSize);
334 push(rdx);
335 push(rax);
336 }
337 }
339 void InterpreterMacroAssembler::pop_ftos_to_rsp() {
340 if (TaggedStackInterpreter) {
341 debug_only(verify_stack_tag(frame::TagValue));
342 pop(rax);
343 addptr(rsp, 1 * wordSize);
344 push(rax); // ftos is at rsp
345 }
346 }
348 void InterpreterMacroAssembler::pop(TosState state) {
349 switch (state) {
350 case atos: pop_ptr(rax); break;
351 case btos: // fall through
352 case ctos: // fall through
353 case stos: // fall through
354 case itos: pop_i(rax); break;
355 case ltos: pop_l(rax, rdx); break;
356 case ftos: pop_f(); break;
357 case dtos: pop_d(); break;
358 case vtos: /* nothing to do */ break;
359 default : ShouldNotReachHere();
360 }
361 verify_oop(rax, state);
362 }
364 void InterpreterMacroAssembler::push_ptr(Register r) {
365 if (TaggedStackInterpreter) push(frame::TagReference);
366 push(r);
367 }
369 void InterpreterMacroAssembler::push_ptr(Register r, Register tag) {
370 if (TaggedStackInterpreter) push(tag); // tag first
371 push(r);
372 }
374 void InterpreterMacroAssembler::push_i(Register r) {
375 if (TaggedStackInterpreter) push(frame::TagValue);
376 push(r);
377 }
379 void InterpreterMacroAssembler::push_l(Register lo, Register hi) {
380 if (TaggedStackInterpreter) push(frame::TagValue);
381 push(hi);
382 if (TaggedStackInterpreter) push(frame::TagValue);
383 push(lo);
384 }
386 void InterpreterMacroAssembler::push_f() {
387 if (TaggedStackInterpreter) push(frame::TagValue);
388 // Do not schedule for no AGI! Never write beyond rsp!
389 subptr(rsp, 1 * wordSize);
390 fstp_s(Address(rsp, 0));
391 }
393 void InterpreterMacroAssembler::push_d(Register r) {
394 if (TaggedStackInterpreter) {
395 // Double values are stored as:
396 // tag
397 // high
398 // tag
399 // low
400 push(frame::TagValue);
401 subptr(rsp, 3 * wordSize);
402 fstp_d(Address(rsp, 0));
403 // move high word up to slot n-1
404 movl(r, Address(rsp, 1*wordSize));
405 movl(Address(rsp, 2*wordSize), r);
406 // move tag
407 movl(Address(rsp, 1*wordSize), frame::TagValue);
408 } else {
409 // Do not schedule for no AGI! Never write beyond rsp!
410 subptr(rsp, 2 * wordSize);
411 fstp_d(Address(rsp, 0));
412 }
413 }
416 void InterpreterMacroAssembler::push(TosState state) {
417 verify_oop(rax, state);
418 switch (state) {
419 case atos: push_ptr(rax); break;
420 case btos: // fall through
421 case ctos: // fall through
422 case stos: // fall through
423 case itos: push_i(rax); break;
424 case ltos: push_l(rax, rdx); break;
425 case ftos: push_f(); break;
426 case dtos: push_d(rax); break;
427 case vtos: /* nothing to do */ break;
428 default : ShouldNotReachHere();
429 }
430 }
433 // Tagged stack helpers for swap and dup
434 void InterpreterMacroAssembler::load_ptr_and_tag(int n, Register val,
435 Register tag) {
436 movptr(val, Address(rsp, Interpreter::expr_offset_in_bytes(n)));
437 if (TaggedStackInterpreter) {
438 movptr(tag, Address(rsp, Interpreter::expr_tag_offset_in_bytes(n)));
439 }
440 }
442 void InterpreterMacroAssembler::store_ptr_and_tag(int n, Register val,
443 Register tag) {
444 movptr(Address(rsp, Interpreter::expr_offset_in_bytes(n)), val);
445 if (TaggedStackInterpreter) {
446 movptr(Address(rsp, Interpreter::expr_tag_offset_in_bytes(n)), tag);
447 }
448 }
451 // Tagged local support
452 void InterpreterMacroAssembler::tag_local(frame::Tag tag, int n) {
453 if (TaggedStackInterpreter) {
454 if (tag == frame::TagCategory2) {
455 movptr(Address(rdi, Interpreter::local_tag_offset_in_bytes(n+1)), (int32_t)frame::TagValue);
456 movptr(Address(rdi, Interpreter::local_tag_offset_in_bytes(n)), (int32_t)frame::TagValue);
457 } else {
458 movptr(Address(rdi, Interpreter::local_tag_offset_in_bytes(n)), (int32_t)tag);
459 }
460 }
461 }
463 void InterpreterMacroAssembler::tag_local(frame::Tag tag, Register idx) {
464 if (TaggedStackInterpreter) {
465 if (tag == frame::TagCategory2) {
466 movptr(Address(rdi, idx, Interpreter::stackElementScale(),
467 Interpreter::local_tag_offset_in_bytes(1)), (int32_t)frame::TagValue);
468 movptr(Address(rdi, idx, Interpreter::stackElementScale(),
469 Interpreter::local_tag_offset_in_bytes(0)), (int32_t)frame::TagValue);
470 } else {
471 movptr(Address(rdi, idx, Interpreter::stackElementScale(),
472 Interpreter::local_tag_offset_in_bytes(0)), (int32_t)tag);
473 }
474 }
475 }
477 void InterpreterMacroAssembler::tag_local(Register tag, Register idx) {
478 if (TaggedStackInterpreter) {
479 // can only be TagValue or TagReference
480 movptr(Address(rdi, idx, Interpreter::stackElementScale(),
481 Interpreter::local_tag_offset_in_bytes(0)), tag);
482 }
483 }
486 void InterpreterMacroAssembler::tag_local(Register tag, int n) {
487 if (TaggedStackInterpreter) {
488 // can only be TagValue or TagReference
489 movptr(Address(rdi, Interpreter::local_tag_offset_in_bytes(n)), tag);
490 }
491 }
493 #ifdef ASSERT
494 void InterpreterMacroAssembler::verify_local_tag(frame::Tag tag, int n) {
495 if (TaggedStackInterpreter) {
496 frame::Tag t = tag;
497 if (tag == frame::TagCategory2) {
498 Label nbl;
499 t = frame::TagValue; // change to what is stored in locals
500 cmpptr(Address(rdi, Interpreter::local_tag_offset_in_bytes(n+1)), (int32_t)t);
501 jcc(Assembler::equal, nbl);
502 stop("Local tag is bad for long/double");
503 bind(nbl);
504 }
505 Label notBad;
506 cmpptr(Address(rdi, Interpreter::local_tag_offset_in_bytes(n)), (int32_t)t);
507 jcc(Assembler::equal, notBad);
508 // Also compare if the local value is zero, then the tag might
509 // not have been set coming from deopt.
510 cmpptr(Address(rdi, Interpreter::local_offset_in_bytes(n)), 0);
511 jcc(Assembler::equal, notBad);
512 stop("Local tag is bad");
513 bind(notBad);
514 }
515 }
517 void InterpreterMacroAssembler::verify_local_tag(frame::Tag tag, Register idx) {
518 if (TaggedStackInterpreter) {
519 frame::Tag t = tag;
520 if (tag == frame::TagCategory2) {
521 Label nbl;
522 t = frame::TagValue; // change to what is stored in locals
523 cmpptr(Address(rdi, idx, Interpreter::stackElementScale(),
524 Interpreter::local_tag_offset_in_bytes(1)), (int32_t)t);
525 jcc(Assembler::equal, nbl);
526 stop("Local tag is bad for long/double");
527 bind(nbl);
528 }
529 Label notBad;
530 cmpl(Address(rdi, idx, Interpreter::stackElementScale(),
531 Interpreter::local_tag_offset_in_bytes(0)), (int32_t)t);
532 jcc(Assembler::equal, notBad);
533 // Also compare if the local value is zero, then the tag might
534 // not have been set coming from deopt.
535 cmpptr(Address(rdi, idx, Interpreter::stackElementScale(),
536 Interpreter::local_offset_in_bytes(0)), 0);
537 jcc(Assembler::equal, notBad);
538 stop("Local tag is bad");
539 bind(notBad);
541 }
542 }
543 #endif // ASSERT
545 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point) {
546 MacroAssembler::call_VM_leaf_base(entry_point, 0);
547 }
550 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point, Register arg_1) {
551 push(arg_1);
552 MacroAssembler::call_VM_leaf_base(entry_point, 1);
553 }
556 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point, Register arg_1, Register arg_2) {
557 push(arg_2);
558 push(arg_1);
559 MacroAssembler::call_VM_leaf_base(entry_point, 2);
560 }
563 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point, Register arg_1, Register arg_2, Register arg_3) {
564 push(arg_3);
565 push(arg_2);
566 push(arg_1);
567 MacroAssembler::call_VM_leaf_base(entry_point, 3);
568 }
571 void InterpreterMacroAssembler::prepare_to_jump_from_interpreted() {
572 // set sender sp
573 lea(rsi, Address(rsp, wordSize));
574 // record last_sp
575 movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), rsi);
576 }
579 // Jump to from_interpreted entry of a call unless single stepping is possible
580 // in this thread in which case we must call the i2i entry
581 void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) {
582 prepare_to_jump_from_interpreted();
584 if (JvmtiExport::can_post_interpreter_events()) {
585 Label run_compiled_code;
586 // JVMTI events, such as single-stepping, are implemented partly by avoiding running
587 // compiled code in threads for which the event is enabled. Check here for
588 // interp_only_mode if these events CAN be enabled.
589 get_thread(temp);
590 // interp_only is an int, on little endian it is sufficient to test the byte only
591 // Is a cmpl faster (ce
592 cmpb(Address(temp, JavaThread::interp_only_mode_offset()), 0);
593 jcc(Assembler::zero, run_compiled_code);
594 jmp(Address(method, methodOopDesc::interpreter_entry_offset()));
595 bind(run_compiled_code);
596 }
598 jmp(Address(method, methodOopDesc::from_interpreted_offset()));
600 }
603 // The following two routines provide a hook so that an implementation
604 // can schedule the dispatch in two parts. Intel does not do this.
605 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) {
606 // Nothing Intel-specific to be done here.
607 }
609 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) {
610 dispatch_next(state, step);
611 }
613 void InterpreterMacroAssembler::dispatch_base(TosState state, address* table,
614 bool verifyoop) {
615 verify_FPU(1, state);
616 if (VerifyActivationFrameSize) {
617 Label L;
618 mov(rcx, rbp);
619 subptr(rcx, rsp);
620 int min_frame_size = (frame::link_offset - frame::interpreter_frame_initial_sp_offset) * wordSize;
621 cmpptr(rcx, min_frame_size);
622 jcc(Assembler::greaterEqual, L);
623 stop("broken stack frame");
624 bind(L);
625 }
626 if (verifyoop) verify_oop(rax, state);
627 Address index(noreg, rbx, Address::times_ptr);
628 ExternalAddress tbl((address)table);
629 ArrayAddress dispatch(tbl, index);
630 jump(dispatch);
631 }
634 void InterpreterMacroAssembler::dispatch_only(TosState state) {
635 dispatch_base(state, Interpreter::dispatch_table(state));
636 }
639 void InterpreterMacroAssembler::dispatch_only_normal(TosState state) {
640 dispatch_base(state, Interpreter::normal_table(state));
641 }
643 void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) {
644 dispatch_base(state, Interpreter::normal_table(state), false);
645 }
648 void InterpreterMacroAssembler::dispatch_next(TosState state, int step) {
649 // load next bytecode (load before advancing rsi to prevent AGI)
650 load_unsigned_byte(rbx, Address(rsi, step));
651 // advance rsi
652 increment(rsi, step);
653 dispatch_base(state, Interpreter::dispatch_table(state));
654 }
657 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
658 // load current bytecode
659 load_unsigned_byte(rbx, Address(rsi, 0));
660 dispatch_base(state, table);
661 }
663 // remove activation
664 //
665 // Unlock the receiver if this is a synchronized method.
666 // Unlock any Java monitors from syncronized blocks.
667 // Remove the activation from the stack.
668 //
669 // If there are locked Java monitors
670 // If throw_monitor_exception
671 // throws IllegalMonitorStateException
672 // Else if install_monitor_exception
673 // installs IllegalMonitorStateException
674 // Else
675 // no error processing
676 void InterpreterMacroAssembler::remove_activation(TosState state, Register ret_addr,
677 bool throw_monitor_exception,
678 bool install_monitor_exception,
679 bool notify_jvmdi) {
680 // Note: Registers rax, rdx and FPU ST(0) may be in use for the result
681 // check if synchronized method
682 Label unlocked, unlock, no_unlock;
684 get_thread(rcx);
685 const Address do_not_unlock_if_synchronized(rcx,
686 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
688 movbool(rbx, do_not_unlock_if_synchronized);
689 mov(rdi,rbx);
690 movbool(do_not_unlock_if_synchronized, false); // reset the flag
692 movptr(rbx, Address(rbp, frame::interpreter_frame_method_offset * wordSize)); // get method access flags
693 movl(rcx, Address(rbx, methodOopDesc::access_flags_offset()));
695 testl(rcx, JVM_ACC_SYNCHRONIZED);
696 jcc(Assembler::zero, unlocked);
698 // Don't unlock anything if the _do_not_unlock_if_synchronized flag
699 // is set.
700 mov(rcx,rdi);
701 testbool(rcx);
702 jcc(Assembler::notZero, no_unlock);
704 // unlock monitor
705 push(state); // save result
707 // BasicObjectLock will be first in list, since this is a synchronized method. However, need
708 // to check that the object has not been unlocked by an explicit monitorexit bytecode.
709 const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset * wordSize - (int)sizeof(BasicObjectLock));
710 lea (rdx, monitor); // address of first monitor
712 movptr (rax, Address(rdx, BasicObjectLock::obj_offset_in_bytes()));
713 testptr(rax, rax);
714 jcc (Assembler::notZero, unlock);
716 pop(state);
717 if (throw_monitor_exception) {
718 empty_FPU_stack(); // remove possible return value from FPU-stack, otherwise stack could overflow
720 // Entry already unlocked, need to throw exception
721 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
722 should_not_reach_here();
723 } else {
724 // Monitor already unlocked during a stack unroll.
725 // If requested, install an illegal_monitor_state_exception.
726 // Continue with stack unrolling.
727 if (install_monitor_exception) {
728 empty_FPU_stack(); // remove possible return value from FPU-stack, otherwise stack could overflow
729 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception));
730 }
731 jmp(unlocked);
732 }
734 bind(unlock);
735 unlock_object(rdx);
736 pop(state);
738 // Check that for block-structured locking (i.e., that all locked objects has been unlocked)
739 bind(unlocked);
741 // rax, rdx: Might contain return value
743 // Check that all monitors are unlocked
744 {
745 Label loop, exception, entry, restart;
746 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
747 const Address monitor_block_top(rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
748 const Address monitor_block_bot(rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
750 bind(restart);
751 movptr(rcx, monitor_block_top); // points to current entry, starting with top-most entry
752 lea(rbx, monitor_block_bot); // points to word before bottom of monitor block
753 jmp(entry);
755 // Entry already locked, need to throw exception
756 bind(exception);
758 if (throw_monitor_exception) {
759 empty_FPU_stack(); // remove possible return value from FPU-stack, otherwise stack could overflow
761 // Throw exception
762 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
763 should_not_reach_here();
764 } else {
765 // Stack unrolling. Unlock object and install illegal_monitor_exception
766 // Unlock does not block, so don't have to worry about the frame
768 push(state);
769 mov(rdx, rcx);
770 unlock_object(rdx);
771 pop(state);
773 if (install_monitor_exception) {
774 empty_FPU_stack(); // remove possible return value from FPU-stack, otherwise stack could overflow
775 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception));
776 }
778 jmp(restart);
779 }
781 bind(loop);
782 cmpptr(Address(rcx, BasicObjectLock::obj_offset_in_bytes()), (int32_t)NULL_WORD); // check if current entry is used
783 jcc(Assembler::notEqual, exception);
785 addptr(rcx, entry_size); // otherwise advance to next entry
786 bind(entry);
787 cmpptr(rcx, rbx); // check if bottom reached
788 jcc(Assembler::notEqual, loop); // if not at bottom then check this entry
789 }
791 bind(no_unlock);
793 // jvmti support
794 if (notify_jvmdi) {
795 notify_method_exit(state, NotifyJVMTI); // preserve TOSCA
796 } else {
797 notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA
798 }
800 // remove activation
801 movptr(rbx, Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize)); // get sender sp
802 leave(); // remove frame anchor
803 pop(ret_addr); // get return address
804 mov(rsp, rbx); // set sp to sender sp
805 if (UseSSE) {
806 // float and double are returned in xmm register in SSE-mode
807 if (state == ftos && UseSSE >= 1) {
808 subptr(rsp, wordSize);
809 fstp_s(Address(rsp, 0));
810 movflt(xmm0, Address(rsp, 0));
811 addptr(rsp, wordSize);
812 } else if (state == dtos && UseSSE >= 2) {
813 subptr(rsp, 2*wordSize);
814 fstp_d(Address(rsp, 0));
815 movdbl(xmm0, Address(rsp, 0));
816 addptr(rsp, 2*wordSize);
817 }
818 }
819 }
821 #endif /* !CC_INTERP */
824 // Lock object
825 //
826 // Argument: rdx : Points to BasicObjectLock to be used for locking. Must
827 // be initialized with object to lock
828 void InterpreterMacroAssembler::lock_object(Register lock_reg) {
829 assert(lock_reg == rdx, "The argument is only for looks. It must be rdx");
831 if (UseHeavyMonitors) {
832 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), lock_reg);
833 } else {
835 Label done;
837 const Register swap_reg = rax; // Must use rax, for cmpxchg instruction
838 const Register obj_reg = rcx; // Will contain the oop
840 const int obj_offset = BasicObjectLock::obj_offset_in_bytes();
841 const int lock_offset = BasicObjectLock::lock_offset_in_bytes ();
842 const int mark_offset = lock_offset + BasicLock::displaced_header_offset_in_bytes();
844 Label slow_case;
846 // Load object pointer into obj_reg %rcx
847 movptr(obj_reg, Address(lock_reg, obj_offset));
849 if (UseBiasedLocking) {
850 // Note: we use noreg for the temporary register since it's hard
851 // to come up with a free register on all incoming code paths
852 biased_locking_enter(lock_reg, obj_reg, swap_reg, noreg, false, done, &slow_case);
853 }
855 // Load immediate 1 into swap_reg %rax,
856 movptr(swap_reg, (int32_t)1);
858 // Load (object->mark() | 1) into swap_reg %rax,
859 orptr(swap_reg, Address(obj_reg, 0));
861 // Save (object->mark() | 1) into BasicLock's displaced header
862 movptr(Address(lock_reg, mark_offset), swap_reg);
864 assert(lock_offset == 0, "displached header must be first word in BasicObjectLock");
865 if (os::is_MP()) {
866 lock();
867 }
868 cmpxchgptr(lock_reg, Address(obj_reg, 0));
869 if (PrintBiasedLockingStatistics) {
870 cond_inc32(Assembler::zero,
871 ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr()));
872 }
873 jcc(Assembler::zero, done);
875 // Test if the oopMark is an obvious stack pointer, i.e.,
876 // 1) (mark & 3) == 0, and
877 // 2) rsp <= mark < mark + os::pagesize()
878 //
879 // These 3 tests can be done by evaluating the following
880 // expression: ((mark - rsp) & (3 - os::vm_page_size())),
881 // assuming both stack pointer and pagesize have their
882 // least significant 2 bits clear.
883 // NOTE: the oopMark is in swap_reg %rax, as the result of cmpxchg
884 subptr(swap_reg, rsp);
885 andptr(swap_reg, 3 - os::vm_page_size());
887 // Save the test result, for recursive case, the result is zero
888 movptr(Address(lock_reg, mark_offset), swap_reg);
890 if (PrintBiasedLockingStatistics) {
891 cond_inc32(Assembler::zero,
892 ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr()));
893 }
894 jcc(Assembler::zero, done);
896 bind(slow_case);
898 // Call the runtime routine for slow case
899 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), lock_reg);
901 bind(done);
902 }
903 }
906 // Unlocks an object. Used in monitorexit bytecode and remove_activation.
907 //
908 // Argument: rdx : Points to BasicObjectLock structure for lock
909 // Throw an IllegalMonitorException if object is not locked by current thread
910 //
911 // Uses: rax, rbx, rcx, rdx
912 void InterpreterMacroAssembler::unlock_object(Register lock_reg) {
913 assert(lock_reg == rdx, "The argument is only for looks. It must be rdx");
915 if (UseHeavyMonitors) {
916 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
917 } else {
918 Label done;
920 const Register swap_reg = rax; // Must use rax, for cmpxchg instruction
921 const Register header_reg = rbx; // Will contain the old oopMark
922 const Register obj_reg = rcx; // Will contain the oop
924 save_bcp(); // Save in case of exception
926 // Convert from BasicObjectLock structure to object and BasicLock structure
927 // Store the BasicLock address into %rax,
928 lea(swap_reg, Address(lock_reg, BasicObjectLock::lock_offset_in_bytes()));
930 // Load oop into obj_reg(%rcx)
931 movptr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes ()));
933 // Free entry
934 movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), NULL_WORD);
936 if (UseBiasedLocking) {
937 biased_locking_exit(obj_reg, header_reg, done);
938 }
940 // Load the old header from BasicLock structure
941 movptr(header_reg, Address(swap_reg, BasicLock::displaced_header_offset_in_bytes()));
943 // Test for recursion
944 testptr(header_reg, header_reg);
946 // zero for recursive case
947 jcc(Assembler::zero, done);
949 // Atomic swap back the old header
950 if (os::is_MP()) lock();
951 cmpxchgptr(header_reg, Address(obj_reg, 0));
953 // zero for recursive case
954 jcc(Assembler::zero, done);
956 // Call the runtime routine for slow case.
957 movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), obj_reg); // restore obj
958 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
960 bind(done);
962 restore_bcp();
963 }
964 }
967 #ifndef CC_INTERP
969 // Test ImethodDataPtr. If it is null, continue at the specified label
970 void InterpreterMacroAssembler::test_method_data_pointer(Register mdp, Label& zero_continue) {
971 assert(ProfileInterpreter, "must be profiling interpreter");
972 movptr(mdp, Address(rbp, frame::interpreter_frame_mdx_offset * wordSize));
973 testptr(mdp, mdp);
974 jcc(Assembler::zero, zero_continue);
975 }
978 // Set the method data pointer for the current bcp.
979 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
980 assert(ProfileInterpreter, "must be profiling interpreter");
981 Label zero_continue;
982 push(rax);
983 push(rbx);
985 get_method(rbx);
986 // Test MDO to avoid the call if it is NULL.
987 movptr(rax, Address(rbx, in_bytes(methodOopDesc::method_data_offset())));
988 testptr(rax, rax);
989 jcc(Assembler::zero, zero_continue);
991 // rbx,: method
992 // rsi: bcp
993 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), rbx, rsi);
994 // rax,: mdi
996 movptr(rbx, Address(rbx, in_bytes(methodOopDesc::method_data_offset())));
997 testptr(rbx, rbx);
998 jcc(Assembler::zero, zero_continue);
999 addptr(rbx, in_bytes(methodDataOopDesc::data_offset()));
1000 addptr(rbx, rax);
1001 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), rbx);
1003 bind(zero_continue);
1004 pop(rbx);
1005 pop(rax);
1006 }
1008 void InterpreterMacroAssembler::verify_method_data_pointer() {
1009 assert(ProfileInterpreter, "must be profiling interpreter");
1010 #ifdef ASSERT
1011 Label verify_continue;
1012 push(rax);
1013 push(rbx);
1014 push(rcx);
1015 push(rdx);
1016 test_method_data_pointer(rcx, verify_continue); // If mdp is zero, continue
1017 get_method(rbx);
1019 // If the mdp is valid, it will point to a DataLayout header which is
1020 // consistent with the bcp. The converse is highly probable also.
1021 load_unsigned_short(rdx, Address(rcx, in_bytes(DataLayout::bci_offset())));
1022 addptr(rdx, Address(rbx, methodOopDesc::const_offset()));
1023 lea(rdx, Address(rdx, constMethodOopDesc::codes_offset()));
1024 cmpptr(rdx, rsi);
1025 jcc(Assembler::equal, verify_continue);
1026 // rbx,: method
1027 // rsi: bcp
1028 // rcx: mdp
1029 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp), rbx, rsi, rcx);
1030 bind(verify_continue);
1031 pop(rdx);
1032 pop(rcx);
1033 pop(rbx);
1034 pop(rax);
1035 #endif // ASSERT
1036 }
1039 void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in, int constant, Register value) {
1040 // %%% this seems to be used to store counter data which is surely 32bits
1041 // however 64bit side stores 64 bits which seems wrong
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 }
1058 void InterpreterMacroAssembler::increment_mdp_data_at(Address data,
1059 bool decrement) {
1061 assert( DataLayout::counter_increment==1, "flow-free idiom only works with 1" );
1062 assert(ProfileInterpreter, "must be profiling interpreter");
1064 // %%% 64bit treats this as 64 bit which seems unlikely
1065 if (decrement) {
1066 // Decrement the register. Set condition codes.
1067 addl(data, -DataLayout::counter_increment);
1068 // If the decrement causes the counter to overflow, stay negative
1069 Label L;
1070 jcc(Assembler::negative, L);
1071 addl(data, DataLayout::counter_increment);
1072 bind(L);
1073 } else {
1074 assert(DataLayout::counter_increment == 1,
1075 "flow-free idiom only works with 1");
1076 // Increment the register. Set carry flag.
1077 addl(data, DataLayout::counter_increment);
1078 // If the increment causes the counter to overflow, pull back by 1.
1079 sbbl(data, 0);
1080 }
1081 }
1084 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
1085 Register reg,
1086 int constant,
1087 bool decrement) {
1088 Address data(mdp_in, reg, Address::times_1, constant);
1090 increment_mdp_data_at(data, decrement);
1091 }
1094 void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in, int flag_byte_constant) {
1095 assert(ProfileInterpreter, "must be profiling interpreter");
1096 int header_offset = in_bytes(DataLayout::header_offset());
1097 int header_bits = DataLayout::flag_mask_to_header_mask(flag_byte_constant);
1098 // Set the flag
1099 orl(Address(mdp_in, header_offset), header_bits);
1100 }
1104 void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in,
1105 int offset,
1106 Register value,
1107 Register test_value_out,
1108 Label& not_equal_continue) {
1109 assert(ProfileInterpreter, "must be profiling interpreter");
1110 if (test_value_out == noreg) {
1111 cmpptr(value, Address(mdp_in, offset));
1112 } else {
1113 // Put the test value into a register, so caller can use it:
1114 movptr(test_value_out, Address(mdp_in, offset));
1115 cmpptr(test_value_out, value);
1116 }
1117 jcc(Assembler::notEqual, not_equal_continue);
1118 }
1121 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, int offset_of_disp) {
1122 assert(ProfileInterpreter, "must be profiling interpreter");
1123 Address disp_address(mdp_in, offset_of_disp);
1124 addptr(mdp_in,disp_address);
1125 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
1126 }
1129 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, Register reg, int offset_of_disp) {
1130 assert(ProfileInterpreter, "must be profiling interpreter");
1131 Address disp_address(mdp_in, reg, Address::times_1, offset_of_disp);
1132 addptr(mdp_in, disp_address);
1133 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
1134 }
1137 void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in, int constant) {
1138 assert(ProfileInterpreter, "must be profiling interpreter");
1139 addptr(mdp_in, constant);
1140 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
1141 }
1144 void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) {
1145 assert(ProfileInterpreter, "must be profiling interpreter");
1146 push(return_bci); // save/restore across call_VM
1147 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret), return_bci);
1148 pop(return_bci);
1149 }
1152 void InterpreterMacroAssembler::profile_taken_branch(Register mdp, 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()));
1165 // %%% 64bit treats these cells as 64 bit but they seem to be 32 bit
1166 movl(bumped_count,data);
1167 assert( DataLayout::counter_increment==1, "flow-free idiom only works with 1" );
1168 addl(bumped_count, DataLayout::counter_increment);
1169 sbbl(bumped_count, 0);
1170 movl(data,bumped_count); // Store back out
1172 // The method data pointer needs to be updated to reflect the new target.
1173 update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
1174 bind (profile_continue);
1175 }
1176 }
1179 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) {
1180 if (ProfileInterpreter) {
1181 Label profile_continue;
1183 // If no method data exists, go to profile_continue.
1184 test_method_data_pointer(mdp, profile_continue);
1186 // We are taking a branch. Increment the not taken count.
1187 increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
1189 // The method data pointer needs to be updated to correspond to 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, in_bytes(VirtualCallData::virtual_call_data_size()));
1225 bind (profile_continue);
1226 }
1227 }
1230 void InterpreterMacroAssembler::profile_virtual_call(Register receiver, Register mdp,
1231 Register reg2,
1232 bool receiver_can_be_null) {
1233 if (ProfileInterpreter) {
1234 Label profile_continue;
1236 // If no method data exists, go to profile_continue.
1237 test_method_data_pointer(mdp, profile_continue);
1239 // We are making a call. Increment the count.
1240 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1242 Label skip_receiver_profile;
1243 if (receiver_can_be_null) {
1244 testptr(receiver, receiver);
1245 jcc(Assembler::zero, skip_receiver_profile);
1246 }
1248 // Record the receiver type.
1249 record_klass_in_profile(receiver, mdp, reg2);
1250 bind(skip_receiver_profile);
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 }
1261 void InterpreterMacroAssembler::record_klass_in_profile_helper(
1262 Register receiver, Register mdp,
1263 Register reg2,
1264 int start_row, Label& done) {
1265 int last_row = VirtualCallData::row_limit() - 1;
1266 assert(start_row <= last_row, "must be work left to do");
1267 // Test this row for both the receiver and for null.
1268 // Take any of three different outcomes:
1269 // 1. found receiver => increment count and goto done
1270 // 2. found null => keep looking for case 1, maybe allocate this cell
1271 // 3. found something else => keep looking for cases 1 and 2
1272 // Case 3 is handled by a recursive call.
1273 for (int row = start_row; row <= last_row; row++) {
1274 Label next_test;
1275 bool test_for_null_also = (row == start_row);
1277 // See if the receiver is receiver[n].
1278 int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row));
1279 test_mdp_data_at(mdp, recvr_offset, receiver,
1280 (test_for_null_also ? reg2 : noreg),
1281 next_test);
1282 // (Reg2 now contains the receiver from the CallData.)
1284 // The receiver is receiver[n]. Increment count[n].
1285 int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row));
1286 increment_mdp_data_at(mdp, count_offset);
1287 jmp(done);
1288 bind(next_test);
1290 if (row == start_row) {
1291 // Failed the equality check on receiver[n]... Test for null.
1292 testptr(reg2, reg2);
1293 if (start_row == last_row) {
1294 // The only thing left to do is handle the null case.
1295 jcc(Assembler::notZero, done);
1296 break;
1297 }
1298 // Since null is rare, make it be the branch-taken case.
1299 Label found_null;
1300 jcc(Assembler::zero, found_null);
1302 // Put all the "Case 3" tests here.
1303 record_klass_in_profile_helper(receiver, mdp, reg2, start_row + 1, done);
1305 // Found a null. Keep searching for a matching receiver,
1306 // but remember that this is an empty (unused) slot.
1307 bind(found_null);
1308 }
1309 }
1311 // In the fall-through case, we found no matching receiver, but we
1312 // observed the receiver[start_row] is NULL.
1314 // Fill in the receiver field and increment the count.
1315 int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row));
1316 set_mdp_data_at(mdp, recvr_offset, receiver);
1317 int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row));
1318 movptr(reg2, (int32_t)DataLayout::counter_increment);
1319 set_mdp_data_at(mdp, count_offset, reg2);
1320 jmp(done);
1321 }
1323 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,
1324 Register mdp,
1325 Register reg2) {
1326 assert(ProfileInterpreter, "must be profiling");
1327 Label done;
1329 record_klass_in_profile_helper(receiver, mdp, reg2, 0, done);
1331 bind (done);
1332 }
1334 void InterpreterMacroAssembler::profile_ret(Register return_bci, Register mdp) {
1335 if (ProfileInterpreter) {
1336 Label profile_continue;
1337 uint row;
1339 // If no method data exists, go to profile_continue.
1340 test_method_data_pointer(mdp, profile_continue);
1342 // Update the total ret count.
1343 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1345 for (row = 0; row < RetData::row_limit(); row++) {
1346 Label next_test;
1348 // See if return_bci is equal to bci[n]:
1349 test_mdp_data_at(mdp, in_bytes(RetData::bci_offset(row)), return_bci,
1350 noreg, next_test);
1352 // return_bci is equal to bci[n]. Increment the count.
1353 increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row)));
1355 // The method data pointer needs to be updated to reflect the new target.
1356 update_mdp_by_offset(mdp, in_bytes(RetData::bci_displacement_offset(row)));
1357 jmp(profile_continue);
1358 bind(next_test);
1359 }
1361 update_mdp_for_ret(return_bci);
1363 bind (profile_continue);
1364 }
1365 }
1368 void InterpreterMacroAssembler::profile_null_seen(Register mdp) {
1369 if (ProfileInterpreter) {
1370 Label profile_continue;
1372 // If no method data exists, go to profile_continue.
1373 test_method_data_pointer(mdp, profile_continue);
1375 // The method data pointer needs to be updated.
1376 int mdp_delta = in_bytes(BitData::bit_data_size());
1377 if (TypeProfileCasts) {
1378 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1379 }
1380 update_mdp_by_constant(mdp, mdp_delta);
1382 bind (profile_continue);
1383 }
1384 }
1387 void InterpreterMacroAssembler::profile_typecheck_failed(Register mdp) {
1388 if (ProfileInterpreter && TypeProfileCasts) {
1389 Label profile_continue;
1391 // If no method data exists, go to profile_continue.
1392 test_method_data_pointer(mdp, profile_continue);
1394 int count_offset = in_bytes(CounterData::count_offset());
1395 // Back up the address, since we have already bumped the mdp.
1396 count_offset -= in_bytes(VirtualCallData::virtual_call_data_size());
1398 // *Decrement* the counter. We expect to see zero or small negatives.
1399 increment_mdp_data_at(mdp, count_offset, true);
1401 bind (profile_continue);
1402 }
1403 }
1406 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2)
1407 {
1408 if (ProfileInterpreter) {
1409 Label profile_continue;
1411 // If no method data exists, go to profile_continue.
1412 test_method_data_pointer(mdp, profile_continue);
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());
1419 // Record the object type.
1420 record_klass_in_profile(klass, mdp, reg2);
1421 assert(reg2 == rdi, "we know how to fix this blown reg");
1422 restore_locals(); // Restore EDI
1423 }
1424 update_mdp_by_constant(mdp, mdp_delta);
1426 bind(profile_continue);
1427 }
1428 }
1431 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
1432 if (ProfileInterpreter) {
1433 Label profile_continue;
1435 // If no method data exists, go to profile_continue.
1436 test_method_data_pointer(mdp, profile_continue);
1438 // Update the default case count
1439 increment_mdp_data_at(mdp, in_bytes(MultiBranchData::default_count_offset()));
1441 // The method data pointer needs to be updated.
1442 update_mdp_by_offset(mdp, in_bytes(MultiBranchData::default_displacement_offset()));
1444 bind (profile_continue);
1445 }
1446 }
1449 void InterpreterMacroAssembler::profile_switch_case(Register index, Register mdp, Register reg2) {
1450 if (ProfileInterpreter) {
1451 Label profile_continue;
1453 // If no method data exists, go to profile_continue.
1454 test_method_data_pointer(mdp, profile_continue);
1456 // Build the base (index * per_case_size_in_bytes()) + case_array_offset_in_bytes()
1457 movptr(reg2, (int32_t)in_bytes(MultiBranchData::per_case_size()));
1458 // index is positive and so should have correct value if this code were
1459 // used on 64bits
1460 imulptr(index, reg2);
1461 addptr(index, in_bytes(MultiBranchData::case_array_offset()));
1463 // Update the case count
1464 increment_mdp_data_at(mdp, index, in_bytes(MultiBranchData::relative_count_offset()));
1466 // The method data pointer needs to be updated.
1467 update_mdp_by_offset(mdp, index, in_bytes(MultiBranchData::relative_displacement_offset()));
1469 bind (profile_continue);
1470 }
1471 }
1473 #endif // !CC_INTERP
1477 void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) {
1478 if (state == atos) MacroAssembler::verify_oop(reg);
1479 }
1482 #ifndef CC_INTERP
1483 void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) {
1484 if (state == ftos || state == dtos) MacroAssembler::verify_FPU(stack_depth);
1485 }
1487 #endif /* CC_INTERP */
1490 void InterpreterMacroAssembler::notify_method_entry() {
1491 // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
1492 // track stack depth. If it is possible to enter interp_only_mode we add
1493 // the code to check if the event should be sent.
1494 if (JvmtiExport::can_post_interpreter_events()) {
1495 Label L;
1496 get_thread(rcx);
1497 movl(rcx, Address(rcx, JavaThread::interp_only_mode_offset()));
1498 testl(rcx,rcx);
1499 jcc(Assembler::zero, L);
1500 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_entry));
1501 bind(L);
1502 }
1504 {
1505 SkipIfEqual skip_if(this, &DTraceMethodProbes, 0);
1506 get_thread(rcx);
1507 get_method(rbx);
1508 call_VM_leaf(
1509 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), rcx, rbx);
1510 }
1512 // RedefineClasses() tracing support for obsolete method entry
1513 if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
1514 get_thread(rcx);
1515 get_method(rbx);
1516 call_VM_leaf(
1517 CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
1518 rcx, rbx);
1519 }
1520 }
1523 void InterpreterMacroAssembler::notify_method_exit(
1524 TosState state, NotifyMethodExitMode mode) {
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 (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {
1529 Label L;
1530 // Note: frame::interpreter_frame_result has a dependency on how the
1531 // method result is saved across the call to post_method_exit. If this
1532 // is changed then the interpreter_frame_result implementation will
1533 // need to be updated too.
1535 // For c++ interpreter the result is always stored at a known location in the frame
1536 // template interpreter will leave it on the top of the stack.
1537 NOT_CC_INTERP(push(state);)
1538 get_thread(rcx);
1539 movl(rcx, Address(rcx, JavaThread::interp_only_mode_offset()));
1540 testl(rcx,rcx);
1541 jcc(Assembler::zero, L);
1542 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit));
1543 bind(L);
1544 NOT_CC_INTERP(pop(state);)
1545 }
1547 {
1548 SkipIfEqual skip_if(this, &DTraceMethodProbes, 0);
1549 NOT_CC_INTERP(push(state));
1550 get_thread(rbx);
1551 get_method(rcx);
1552 call_VM_leaf(
1553 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
1554 rbx, rcx);
1555 NOT_CC_INTERP(pop(state));
1556 }
1557 }