Thu, 08 Apr 2010 10:55:40 +0200
6941529: SharedRuntime::raw_exception_handler_for_return_address must reset thread MethodHandle flag
Summary: During testing a bug was hit when an exception returned to the interpreter and the SP was wrong.
Reviewed-by: kvn, never
1 /*
2 * Copyright 1997-2010 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 // Check if the secondary index definition is still ~x, otherwise
200 // we have to change the following assembler code to calculate the
201 // plain index.
202 assert(constantPoolCacheOopDesc::decode_secondary_index(~123) == 123, "else change next line");
203 notl(reg); // convert to plain index
204 }
205 }
208 void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache, Register index,
209 int bcp_offset, bool giant_index) {
210 assert(cache != index, "must use different registers");
211 get_cache_index_at_bcp(index, bcp_offset, giant_index);
212 movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize));
213 assert(sizeof(ConstantPoolCacheEntry) == 4*wordSize, "adjust code below");
214 shlptr(index, 2); // convert from field index to ConstantPoolCacheEntry index
215 }
218 void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache, Register tmp,
219 int bcp_offset, bool giant_index) {
220 assert(cache != tmp, "must use different register");
221 get_cache_index_at_bcp(tmp, bcp_offset, giant_index);
222 assert(sizeof(ConstantPoolCacheEntry) == 4*wordSize, "adjust code below");
223 // convert from field index to ConstantPoolCacheEntry index
224 // and from word offset to byte offset
225 shll(tmp, 2 + LogBytesPerWord);
226 movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize));
227 // skip past the header
228 addptr(cache, in_bytes(constantPoolCacheOopDesc::base_offset()));
229 addptr(cache, tmp); // construct pointer to cache entry
230 }
233 // Generate a subtype check: branch to ok_is_subtype if sub_klass is
234 // a subtype of super_klass. EAX holds the super_klass. Blows ECX.
235 // Resets EDI to locals. Register sub_klass cannot be any of the above.
236 void InterpreterMacroAssembler::gen_subtype_check( Register Rsub_klass, Label &ok_is_subtype ) {
237 assert( Rsub_klass != rax, "rax, holds superklass" );
238 assert( Rsub_klass != rcx, "used as a temp" );
239 assert( Rsub_klass != rdi, "used as a temp, restored from locals" );
241 // Profile the not-null value's klass.
242 profile_typecheck(rcx, Rsub_klass, rdi); // blows rcx, reloads rdi
244 // Do the check.
245 check_klass_subtype(Rsub_klass, rax, rcx, ok_is_subtype); // blows rcx
247 // Profile the failure of the check.
248 profile_typecheck_failed(rcx); // blows rcx
249 }
251 void InterpreterMacroAssembler::f2ieee() {
252 if (IEEEPrecision) {
253 fstp_s(Address(rsp, 0));
254 fld_s(Address(rsp, 0));
255 }
256 }
259 void InterpreterMacroAssembler::d2ieee() {
260 if (IEEEPrecision) {
261 fstp_d(Address(rsp, 0));
262 fld_d(Address(rsp, 0));
263 }
264 }
266 // Java Expression Stack
268 #ifdef ASSERT
269 void InterpreterMacroAssembler::verify_stack_tag(frame::Tag t) {
270 if (TaggedStackInterpreter) {
271 Label okay;
272 cmpptr(Address(rsp, wordSize), (int32_t)t);
273 jcc(Assembler::equal, okay);
274 // Also compare if the stack value is zero, then the tag might
275 // not have been set coming from deopt.
276 cmpptr(Address(rsp, 0), 0);
277 jcc(Assembler::equal, okay);
278 stop("Java Expression stack tag value is bad");
279 bind(okay);
280 }
281 }
282 #endif // ASSERT
284 void InterpreterMacroAssembler::pop_ptr(Register r) {
285 debug_only(verify_stack_tag(frame::TagReference));
286 pop(r);
287 if (TaggedStackInterpreter) addptr(rsp, 1 * wordSize);
288 }
290 void InterpreterMacroAssembler::pop_ptr(Register r, Register tag) {
291 pop(r);
292 // Tag may not be reference for jsr, can be returnAddress
293 if (TaggedStackInterpreter) pop(tag);
294 }
296 void InterpreterMacroAssembler::pop_i(Register r) {
297 debug_only(verify_stack_tag(frame::TagValue));
298 pop(r);
299 if (TaggedStackInterpreter) addptr(rsp, 1 * wordSize);
300 }
302 void InterpreterMacroAssembler::pop_l(Register lo, Register hi) {
303 debug_only(verify_stack_tag(frame::TagValue));
304 pop(lo);
305 if (TaggedStackInterpreter) addptr(rsp, 1 * wordSize);
306 debug_only(verify_stack_tag(frame::TagValue));
307 pop(hi);
308 if (TaggedStackInterpreter) addptr(rsp, 1 * wordSize);
309 }
311 void InterpreterMacroAssembler::pop_f() {
312 debug_only(verify_stack_tag(frame::TagValue));
313 fld_s(Address(rsp, 0));
314 addptr(rsp, 1 * wordSize);
315 if (TaggedStackInterpreter) addptr(rsp, 1 * wordSize);
316 }
318 void InterpreterMacroAssembler::pop_d() {
319 // Write double to stack contiguously and load into ST0
320 pop_dtos_to_rsp();
321 fld_d(Address(rsp, 0));
322 addptr(rsp, 2 * wordSize);
323 }
326 // Pop the top of the java expression stack to execution stack (which
327 // happens to be the same place).
328 void InterpreterMacroAssembler::pop_dtos_to_rsp() {
329 if (TaggedStackInterpreter) {
330 // Pop double value into scratch registers
331 debug_only(verify_stack_tag(frame::TagValue));
332 pop(rax);
333 addptr(rsp, 1* wordSize);
334 debug_only(verify_stack_tag(frame::TagValue));
335 pop(rdx);
336 addptr(rsp, 1* wordSize);
337 push(rdx);
338 push(rax);
339 }
340 }
342 void InterpreterMacroAssembler::pop_ftos_to_rsp() {
343 if (TaggedStackInterpreter) {
344 debug_only(verify_stack_tag(frame::TagValue));
345 pop(rax);
346 addptr(rsp, 1 * wordSize);
347 push(rax); // ftos is at rsp
348 }
349 }
351 void InterpreterMacroAssembler::pop(TosState state) {
352 switch (state) {
353 case atos: pop_ptr(rax); break;
354 case btos: // fall through
355 case ctos: // fall through
356 case stos: // fall through
357 case itos: pop_i(rax); break;
358 case ltos: pop_l(rax, rdx); break;
359 case ftos: pop_f(); break;
360 case dtos: pop_d(); break;
361 case vtos: /* nothing to do */ break;
362 default : ShouldNotReachHere();
363 }
364 verify_oop(rax, state);
365 }
367 void InterpreterMacroAssembler::push_ptr(Register r) {
368 if (TaggedStackInterpreter) push(frame::TagReference);
369 push(r);
370 }
372 void InterpreterMacroAssembler::push_ptr(Register r, Register tag) {
373 if (TaggedStackInterpreter) push(tag); // tag first
374 push(r);
375 }
377 void InterpreterMacroAssembler::push_i(Register r) {
378 if (TaggedStackInterpreter) push(frame::TagValue);
379 push(r);
380 }
382 void InterpreterMacroAssembler::push_l(Register lo, Register hi) {
383 if (TaggedStackInterpreter) push(frame::TagValue);
384 push(hi);
385 if (TaggedStackInterpreter) push(frame::TagValue);
386 push(lo);
387 }
389 void InterpreterMacroAssembler::push_f() {
390 if (TaggedStackInterpreter) push(frame::TagValue);
391 // Do not schedule for no AGI! Never write beyond rsp!
392 subptr(rsp, 1 * wordSize);
393 fstp_s(Address(rsp, 0));
394 }
396 void InterpreterMacroAssembler::push_d(Register r) {
397 if (TaggedStackInterpreter) {
398 // Double values are stored as:
399 // tag
400 // high
401 // tag
402 // low
403 push(frame::TagValue);
404 subptr(rsp, 3 * wordSize);
405 fstp_d(Address(rsp, 0));
406 // move high word up to slot n-1
407 movl(r, Address(rsp, 1*wordSize));
408 movl(Address(rsp, 2*wordSize), r);
409 // move tag
410 movl(Address(rsp, 1*wordSize), frame::TagValue);
411 } else {
412 // Do not schedule for no AGI! Never write beyond rsp!
413 subptr(rsp, 2 * wordSize);
414 fstp_d(Address(rsp, 0));
415 }
416 }
419 void InterpreterMacroAssembler::push(TosState state) {
420 verify_oop(rax, state);
421 switch (state) {
422 case atos: push_ptr(rax); break;
423 case btos: // fall through
424 case ctos: // fall through
425 case stos: // fall through
426 case itos: push_i(rax); break;
427 case ltos: push_l(rax, rdx); break;
428 case ftos: push_f(); break;
429 case dtos: push_d(rax); break;
430 case vtos: /* nothing to do */ break;
431 default : ShouldNotReachHere();
432 }
433 }
436 // Tagged stack helpers for swap and dup
437 void InterpreterMacroAssembler::load_ptr_and_tag(int n, Register val,
438 Register tag) {
439 movptr(val, Address(rsp, Interpreter::expr_offset_in_bytes(n)));
440 if (TaggedStackInterpreter) {
441 movptr(tag, Address(rsp, Interpreter::expr_tag_offset_in_bytes(n)));
442 }
443 }
445 void InterpreterMacroAssembler::store_ptr_and_tag(int n, Register val,
446 Register tag) {
447 movptr(Address(rsp, Interpreter::expr_offset_in_bytes(n)), val);
448 if (TaggedStackInterpreter) {
449 movptr(Address(rsp, Interpreter::expr_tag_offset_in_bytes(n)), tag);
450 }
451 }
454 // Tagged local support
455 void InterpreterMacroAssembler::tag_local(frame::Tag tag, int n) {
456 if (TaggedStackInterpreter) {
457 if (tag == frame::TagCategory2) {
458 movptr(Address(rdi, Interpreter::local_tag_offset_in_bytes(n+1)), (int32_t)frame::TagValue);
459 movptr(Address(rdi, Interpreter::local_tag_offset_in_bytes(n)), (int32_t)frame::TagValue);
460 } else {
461 movptr(Address(rdi, Interpreter::local_tag_offset_in_bytes(n)), (int32_t)tag);
462 }
463 }
464 }
466 void InterpreterMacroAssembler::tag_local(frame::Tag tag, Register idx) {
467 if (TaggedStackInterpreter) {
468 if (tag == frame::TagCategory2) {
469 movptr(Address(rdi, idx, Interpreter::stackElementScale(),
470 Interpreter::local_tag_offset_in_bytes(1)), (int32_t)frame::TagValue);
471 movptr(Address(rdi, idx, Interpreter::stackElementScale(),
472 Interpreter::local_tag_offset_in_bytes(0)), (int32_t)frame::TagValue);
473 } else {
474 movptr(Address(rdi, idx, Interpreter::stackElementScale(),
475 Interpreter::local_tag_offset_in_bytes(0)), (int32_t)tag);
476 }
477 }
478 }
480 void InterpreterMacroAssembler::tag_local(Register tag, Register idx) {
481 if (TaggedStackInterpreter) {
482 // can only be TagValue or TagReference
483 movptr(Address(rdi, idx, Interpreter::stackElementScale(),
484 Interpreter::local_tag_offset_in_bytes(0)), tag);
485 }
486 }
489 void InterpreterMacroAssembler::tag_local(Register tag, int n) {
490 if (TaggedStackInterpreter) {
491 // can only be TagValue or TagReference
492 movptr(Address(rdi, Interpreter::local_tag_offset_in_bytes(n)), tag);
493 }
494 }
496 #ifdef ASSERT
497 void InterpreterMacroAssembler::verify_local_tag(frame::Tag tag, int n) {
498 if (TaggedStackInterpreter) {
499 frame::Tag t = tag;
500 if (tag == frame::TagCategory2) {
501 Label nbl;
502 t = frame::TagValue; // change to what is stored in locals
503 cmpptr(Address(rdi, Interpreter::local_tag_offset_in_bytes(n+1)), (int32_t)t);
504 jcc(Assembler::equal, nbl);
505 stop("Local tag is bad for long/double");
506 bind(nbl);
507 }
508 Label notBad;
509 cmpptr(Address(rdi, Interpreter::local_tag_offset_in_bytes(n)), (int32_t)t);
510 jcc(Assembler::equal, notBad);
511 // Also compare if the local value is zero, then the tag might
512 // not have been set coming from deopt.
513 cmpptr(Address(rdi, Interpreter::local_offset_in_bytes(n)), 0);
514 jcc(Assembler::equal, notBad);
515 stop("Local tag is bad");
516 bind(notBad);
517 }
518 }
520 void InterpreterMacroAssembler::verify_local_tag(frame::Tag tag, Register idx) {
521 if (TaggedStackInterpreter) {
522 frame::Tag t = tag;
523 if (tag == frame::TagCategory2) {
524 Label nbl;
525 t = frame::TagValue; // change to what is stored in locals
526 cmpptr(Address(rdi, idx, Interpreter::stackElementScale(),
527 Interpreter::local_tag_offset_in_bytes(1)), (int32_t)t);
528 jcc(Assembler::equal, nbl);
529 stop("Local tag is bad for long/double");
530 bind(nbl);
531 }
532 Label notBad;
533 cmpl(Address(rdi, idx, Interpreter::stackElementScale(),
534 Interpreter::local_tag_offset_in_bytes(0)), (int32_t)t);
535 jcc(Assembler::equal, notBad);
536 // Also compare if the local value is zero, then the tag might
537 // not have been set coming from deopt.
538 cmpptr(Address(rdi, idx, Interpreter::stackElementScale(),
539 Interpreter::local_offset_in_bytes(0)), 0);
540 jcc(Assembler::equal, notBad);
541 stop("Local tag is bad");
542 bind(notBad);
544 }
545 }
546 #endif // ASSERT
548 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point) {
549 MacroAssembler::call_VM_leaf_base(entry_point, 0);
550 }
553 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point, Register arg_1) {
554 push(arg_1);
555 MacroAssembler::call_VM_leaf_base(entry_point, 1);
556 }
559 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point, Register arg_1, Register arg_2) {
560 push(arg_2);
561 push(arg_1);
562 MacroAssembler::call_VM_leaf_base(entry_point, 2);
563 }
566 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point, Register arg_1, Register arg_2, Register arg_3) {
567 push(arg_3);
568 push(arg_2);
569 push(arg_1);
570 MacroAssembler::call_VM_leaf_base(entry_point, 3);
571 }
574 void InterpreterMacroAssembler::prepare_to_jump_from_interpreted() {
575 // set sender sp
576 lea(rsi, Address(rsp, wordSize));
577 // record last_sp
578 movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), rsi);
579 }
582 // Jump to from_interpreted entry of a call unless single stepping is possible
583 // in this thread in which case we must call the i2i entry
584 void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) {
585 prepare_to_jump_from_interpreted();
587 if (JvmtiExport::can_post_interpreter_events()) {
588 Label run_compiled_code;
589 // JVMTI events, such as single-stepping, are implemented partly by avoiding running
590 // compiled code in threads for which the event is enabled. Check here for
591 // interp_only_mode if these events CAN be enabled.
592 get_thread(temp);
593 // interp_only is an int, on little endian it is sufficient to test the byte only
594 // Is a cmpl faster (ce
595 cmpb(Address(temp, JavaThread::interp_only_mode_offset()), 0);
596 jcc(Assembler::zero, run_compiled_code);
597 jmp(Address(method, methodOopDesc::interpreter_entry_offset()));
598 bind(run_compiled_code);
599 }
601 jmp(Address(method, methodOopDesc::from_interpreted_offset()));
603 }
606 // The following two routines provide a hook so that an implementation
607 // can schedule the dispatch in two parts. Intel does not do this.
608 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) {
609 // Nothing Intel-specific to be done here.
610 }
612 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) {
613 dispatch_next(state, step);
614 }
616 void InterpreterMacroAssembler::dispatch_base(TosState state, address* table,
617 bool verifyoop) {
618 verify_FPU(1, state);
619 if (VerifyActivationFrameSize) {
620 Label L;
621 mov(rcx, rbp);
622 subptr(rcx, rsp);
623 int min_frame_size = (frame::link_offset - frame::interpreter_frame_initial_sp_offset) * wordSize;
624 cmpptr(rcx, min_frame_size);
625 jcc(Assembler::greaterEqual, L);
626 stop("broken stack frame");
627 bind(L);
628 }
629 if (verifyoop) verify_oop(rax, state);
630 Address index(noreg, rbx, Address::times_ptr);
631 ExternalAddress tbl((address)table);
632 ArrayAddress dispatch(tbl, index);
633 jump(dispatch);
634 }
637 void InterpreterMacroAssembler::dispatch_only(TosState state) {
638 dispatch_base(state, Interpreter::dispatch_table(state));
639 }
642 void InterpreterMacroAssembler::dispatch_only_normal(TosState state) {
643 dispatch_base(state, Interpreter::normal_table(state));
644 }
646 void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) {
647 dispatch_base(state, Interpreter::normal_table(state), false);
648 }
651 void InterpreterMacroAssembler::dispatch_next(TosState state, int step) {
652 // load next bytecode (load before advancing rsi to prevent AGI)
653 load_unsigned_byte(rbx, Address(rsi, step));
654 // advance rsi
655 increment(rsi, step);
656 dispatch_base(state, Interpreter::dispatch_table(state));
657 }
660 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
661 // load current bytecode
662 load_unsigned_byte(rbx, Address(rsi, 0));
663 dispatch_base(state, table);
664 }
666 // remove activation
667 //
668 // Unlock the receiver if this is a synchronized method.
669 // Unlock any Java monitors from syncronized blocks.
670 // Remove the activation from the stack.
671 //
672 // If there are locked Java monitors
673 // If throw_monitor_exception
674 // throws IllegalMonitorStateException
675 // Else if install_monitor_exception
676 // installs IllegalMonitorStateException
677 // Else
678 // no error processing
679 void InterpreterMacroAssembler::remove_activation(TosState state, Register ret_addr,
680 bool throw_monitor_exception,
681 bool install_monitor_exception,
682 bool notify_jvmdi) {
683 // Note: Registers rax, rdx and FPU ST(0) may be in use for the result
684 // check if synchronized method
685 Label unlocked, unlock, no_unlock;
687 get_thread(rcx);
688 const Address do_not_unlock_if_synchronized(rcx,
689 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
691 movbool(rbx, do_not_unlock_if_synchronized);
692 mov(rdi,rbx);
693 movbool(do_not_unlock_if_synchronized, false); // reset the flag
695 movptr(rbx, Address(rbp, frame::interpreter_frame_method_offset * wordSize)); // get method access flags
696 movl(rcx, Address(rbx, methodOopDesc::access_flags_offset()));
698 testl(rcx, JVM_ACC_SYNCHRONIZED);
699 jcc(Assembler::zero, unlocked);
701 // Don't unlock anything if the _do_not_unlock_if_synchronized flag
702 // is set.
703 mov(rcx,rdi);
704 testbool(rcx);
705 jcc(Assembler::notZero, no_unlock);
707 // unlock monitor
708 push(state); // save result
710 // BasicObjectLock will be first in list, since this is a synchronized method. However, need
711 // to check that the object has not been unlocked by an explicit monitorexit bytecode.
712 const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset * wordSize - (int)sizeof(BasicObjectLock));
713 lea (rdx, monitor); // address of first monitor
715 movptr (rax, Address(rdx, BasicObjectLock::obj_offset_in_bytes()));
716 testptr(rax, rax);
717 jcc (Assembler::notZero, unlock);
719 pop(state);
720 if (throw_monitor_exception) {
721 empty_FPU_stack(); // remove possible return value from FPU-stack, otherwise stack could overflow
723 // Entry already unlocked, need to throw exception
724 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
725 should_not_reach_here();
726 } else {
727 // Monitor already unlocked during a stack unroll.
728 // If requested, install an illegal_monitor_state_exception.
729 // Continue with stack unrolling.
730 if (install_monitor_exception) {
731 empty_FPU_stack(); // remove possible return value from FPU-stack, otherwise stack could overflow
732 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception));
733 }
734 jmp(unlocked);
735 }
737 bind(unlock);
738 unlock_object(rdx);
739 pop(state);
741 // Check that for block-structured locking (i.e., that all locked objects has been unlocked)
742 bind(unlocked);
744 // rax, rdx: Might contain return value
746 // Check that all monitors are unlocked
747 {
748 Label loop, exception, entry, restart;
749 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
750 const Address monitor_block_top(rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
751 const Address monitor_block_bot(rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
753 bind(restart);
754 movptr(rcx, monitor_block_top); // points to current entry, starting with top-most entry
755 lea(rbx, monitor_block_bot); // points to word before bottom of monitor block
756 jmp(entry);
758 // Entry already locked, need to throw exception
759 bind(exception);
761 if (throw_monitor_exception) {
762 empty_FPU_stack(); // remove possible return value from FPU-stack, otherwise stack could overflow
764 // Throw exception
765 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
766 should_not_reach_here();
767 } else {
768 // Stack unrolling. Unlock object and install illegal_monitor_exception
769 // Unlock does not block, so don't have to worry about the frame
771 push(state);
772 mov(rdx, rcx);
773 unlock_object(rdx);
774 pop(state);
776 if (install_monitor_exception) {
777 empty_FPU_stack(); // remove possible return value from FPU-stack, otherwise stack could overflow
778 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception));
779 }
781 jmp(restart);
782 }
784 bind(loop);
785 cmpptr(Address(rcx, BasicObjectLock::obj_offset_in_bytes()), (int32_t)NULL_WORD); // check if current entry is used
786 jcc(Assembler::notEqual, exception);
788 addptr(rcx, entry_size); // otherwise advance to next entry
789 bind(entry);
790 cmpptr(rcx, rbx); // check if bottom reached
791 jcc(Assembler::notEqual, loop); // if not at bottom then check this entry
792 }
794 bind(no_unlock);
796 // jvmti support
797 if (notify_jvmdi) {
798 notify_method_exit(state, NotifyJVMTI); // preserve TOSCA
799 } else {
800 notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA
801 }
803 // remove activation
804 movptr(rbx, Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize)); // get sender sp
805 leave(); // remove frame anchor
806 pop(ret_addr); // get return address
807 mov(rsp, rbx); // set sp to sender sp
808 if (UseSSE) {
809 // float and double are returned in xmm register in SSE-mode
810 if (state == ftos && UseSSE >= 1) {
811 subptr(rsp, wordSize);
812 fstp_s(Address(rsp, 0));
813 movflt(xmm0, Address(rsp, 0));
814 addptr(rsp, wordSize);
815 } else if (state == dtos && UseSSE >= 2) {
816 subptr(rsp, 2*wordSize);
817 fstp_d(Address(rsp, 0));
818 movdbl(xmm0, Address(rsp, 0));
819 addptr(rsp, 2*wordSize);
820 }
821 }
822 }
824 #endif /* !CC_INTERP */
827 // Lock object
828 //
829 // Argument: rdx : Points to BasicObjectLock to be used for locking. Must
830 // be initialized with object to lock
831 void InterpreterMacroAssembler::lock_object(Register lock_reg) {
832 assert(lock_reg == rdx, "The argument is only for looks. It must be rdx");
834 if (UseHeavyMonitors) {
835 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), lock_reg);
836 } else {
838 Label done;
840 const Register swap_reg = rax; // Must use rax, for cmpxchg instruction
841 const Register obj_reg = rcx; // Will contain the oop
843 const int obj_offset = BasicObjectLock::obj_offset_in_bytes();
844 const int lock_offset = BasicObjectLock::lock_offset_in_bytes ();
845 const int mark_offset = lock_offset + BasicLock::displaced_header_offset_in_bytes();
847 Label slow_case;
849 // Load object pointer into obj_reg %rcx
850 movptr(obj_reg, Address(lock_reg, obj_offset));
852 if (UseBiasedLocking) {
853 // Note: we use noreg for the temporary register since it's hard
854 // to come up with a free register on all incoming code paths
855 biased_locking_enter(lock_reg, obj_reg, swap_reg, noreg, false, done, &slow_case);
856 }
858 // Load immediate 1 into swap_reg %rax,
859 movptr(swap_reg, (int32_t)1);
861 // Load (object->mark() | 1) into swap_reg %rax,
862 orptr(swap_reg, Address(obj_reg, 0));
864 // Save (object->mark() | 1) into BasicLock's displaced header
865 movptr(Address(lock_reg, mark_offset), swap_reg);
867 assert(lock_offset == 0, "displached header must be first word in BasicObjectLock");
868 if (os::is_MP()) {
869 lock();
870 }
871 cmpxchgptr(lock_reg, Address(obj_reg, 0));
872 if (PrintBiasedLockingStatistics) {
873 cond_inc32(Assembler::zero,
874 ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr()));
875 }
876 jcc(Assembler::zero, done);
878 // Test if the oopMark is an obvious stack pointer, i.e.,
879 // 1) (mark & 3) == 0, and
880 // 2) rsp <= mark < mark + os::pagesize()
881 //
882 // These 3 tests can be done by evaluating the following
883 // expression: ((mark - rsp) & (3 - os::vm_page_size())),
884 // assuming both stack pointer and pagesize have their
885 // least significant 2 bits clear.
886 // NOTE: the oopMark is in swap_reg %rax, as the result of cmpxchg
887 subptr(swap_reg, rsp);
888 andptr(swap_reg, 3 - os::vm_page_size());
890 // Save the test result, for recursive case, the result is zero
891 movptr(Address(lock_reg, mark_offset), swap_reg);
893 if (PrintBiasedLockingStatistics) {
894 cond_inc32(Assembler::zero,
895 ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr()));
896 }
897 jcc(Assembler::zero, done);
899 bind(slow_case);
901 // Call the runtime routine for slow case
902 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), lock_reg);
904 bind(done);
905 }
906 }
909 // Unlocks an object. Used in monitorexit bytecode and remove_activation.
910 //
911 // Argument: rdx : Points to BasicObjectLock structure for lock
912 // Throw an IllegalMonitorException if object is not locked by current thread
913 //
914 // Uses: rax, rbx, rcx, rdx
915 void InterpreterMacroAssembler::unlock_object(Register lock_reg) {
916 assert(lock_reg == rdx, "The argument is only for looks. It must be rdx");
918 if (UseHeavyMonitors) {
919 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
920 } else {
921 Label done;
923 const Register swap_reg = rax; // Must use rax, for cmpxchg instruction
924 const Register header_reg = rbx; // Will contain the old oopMark
925 const Register obj_reg = rcx; // Will contain the oop
927 save_bcp(); // Save in case of exception
929 // Convert from BasicObjectLock structure to object and BasicLock structure
930 // Store the BasicLock address into %rax,
931 lea(swap_reg, Address(lock_reg, BasicObjectLock::lock_offset_in_bytes()));
933 // Load oop into obj_reg(%rcx)
934 movptr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes ()));
936 // Free entry
937 movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), NULL_WORD);
939 if (UseBiasedLocking) {
940 biased_locking_exit(obj_reg, header_reg, done);
941 }
943 // Load the old header from BasicLock structure
944 movptr(header_reg, Address(swap_reg, BasicLock::displaced_header_offset_in_bytes()));
946 // Test for recursion
947 testptr(header_reg, header_reg);
949 // zero for recursive case
950 jcc(Assembler::zero, done);
952 // Atomic swap back the old header
953 if (os::is_MP()) lock();
954 cmpxchgptr(header_reg, Address(obj_reg, 0));
956 // zero for recursive case
957 jcc(Assembler::zero, done);
959 // Call the runtime routine for slow case.
960 movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), obj_reg); // restore obj
961 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
963 bind(done);
965 restore_bcp();
966 }
967 }
970 #ifndef CC_INTERP
972 // Test ImethodDataPtr. If it is null, continue at the specified label
973 void InterpreterMacroAssembler::test_method_data_pointer(Register mdp, Label& zero_continue) {
974 assert(ProfileInterpreter, "must be profiling interpreter");
975 movptr(mdp, Address(rbp, frame::interpreter_frame_mdx_offset * wordSize));
976 testptr(mdp, mdp);
977 jcc(Assembler::zero, zero_continue);
978 }
981 // Set the method data pointer for the current bcp.
982 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
983 assert(ProfileInterpreter, "must be profiling interpreter");
984 Label zero_continue;
985 push(rax);
986 push(rbx);
988 get_method(rbx);
989 // Test MDO to avoid the call if it is NULL.
990 movptr(rax, Address(rbx, in_bytes(methodOopDesc::method_data_offset())));
991 testptr(rax, rax);
992 jcc(Assembler::zero, zero_continue);
994 // rbx,: method
995 // rsi: bcp
996 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), rbx, rsi);
997 // rax,: mdi
999 movptr(rbx, Address(rbx, in_bytes(methodOopDesc::method_data_offset())));
1000 testptr(rbx, rbx);
1001 jcc(Assembler::zero, zero_continue);
1002 addptr(rbx, in_bytes(methodDataOopDesc::data_offset()));
1003 addptr(rbx, rax);
1004 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), rbx);
1006 bind(zero_continue);
1007 pop(rbx);
1008 pop(rax);
1009 }
1011 void InterpreterMacroAssembler::verify_method_data_pointer() {
1012 assert(ProfileInterpreter, "must be profiling interpreter");
1013 #ifdef ASSERT
1014 Label verify_continue;
1015 push(rax);
1016 push(rbx);
1017 push(rcx);
1018 push(rdx);
1019 test_method_data_pointer(rcx, verify_continue); // If mdp is zero, continue
1020 get_method(rbx);
1022 // If the mdp is valid, it will point to a DataLayout header which is
1023 // consistent with the bcp. The converse is highly probable also.
1024 load_unsigned_short(rdx, Address(rcx, in_bytes(DataLayout::bci_offset())));
1025 addptr(rdx, Address(rbx, methodOopDesc::const_offset()));
1026 lea(rdx, Address(rdx, constMethodOopDesc::codes_offset()));
1027 cmpptr(rdx, rsi);
1028 jcc(Assembler::equal, verify_continue);
1029 // rbx,: method
1030 // rsi: bcp
1031 // rcx: mdp
1032 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp), rbx, rsi, rcx);
1033 bind(verify_continue);
1034 pop(rdx);
1035 pop(rcx);
1036 pop(rbx);
1037 pop(rax);
1038 #endif // ASSERT
1039 }
1042 void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in, int constant, Register value) {
1043 // %%% this seems to be used to store counter data which is surely 32bits
1044 // however 64bit side stores 64 bits which seems wrong
1045 assert(ProfileInterpreter, "must be profiling interpreter");
1046 Address data(mdp_in, constant);
1047 movptr(data, value);
1048 }
1051 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
1052 int constant,
1053 bool decrement) {
1054 // Counter address
1055 Address data(mdp_in, constant);
1057 increment_mdp_data_at(data, decrement);
1058 }
1061 void InterpreterMacroAssembler::increment_mdp_data_at(Address data,
1062 bool decrement) {
1064 assert( DataLayout::counter_increment==1, "flow-free idiom only works with 1" );
1065 assert(ProfileInterpreter, "must be profiling interpreter");
1067 // %%% 64bit treats this as 64 bit which seems unlikely
1068 if (decrement) {
1069 // Decrement the register. Set condition codes.
1070 addl(data, -DataLayout::counter_increment);
1071 // If the decrement causes the counter to overflow, stay negative
1072 Label L;
1073 jcc(Assembler::negative, L);
1074 addl(data, DataLayout::counter_increment);
1075 bind(L);
1076 } else {
1077 assert(DataLayout::counter_increment == 1,
1078 "flow-free idiom only works with 1");
1079 // Increment the register. Set carry flag.
1080 addl(data, DataLayout::counter_increment);
1081 // If the increment causes the counter to overflow, pull back by 1.
1082 sbbl(data, 0);
1083 }
1084 }
1087 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
1088 Register reg,
1089 int constant,
1090 bool decrement) {
1091 Address data(mdp_in, reg, Address::times_1, constant);
1093 increment_mdp_data_at(data, decrement);
1094 }
1097 void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in, int flag_byte_constant) {
1098 assert(ProfileInterpreter, "must be profiling interpreter");
1099 int header_offset = in_bytes(DataLayout::header_offset());
1100 int header_bits = DataLayout::flag_mask_to_header_mask(flag_byte_constant);
1101 // Set the flag
1102 orl(Address(mdp_in, header_offset), header_bits);
1103 }
1107 void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in,
1108 int offset,
1109 Register value,
1110 Register test_value_out,
1111 Label& not_equal_continue) {
1112 assert(ProfileInterpreter, "must be profiling interpreter");
1113 if (test_value_out == noreg) {
1114 cmpptr(value, Address(mdp_in, offset));
1115 } else {
1116 // Put the test value into a register, so caller can use it:
1117 movptr(test_value_out, Address(mdp_in, offset));
1118 cmpptr(test_value_out, value);
1119 }
1120 jcc(Assembler::notEqual, not_equal_continue);
1121 }
1124 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, int offset_of_disp) {
1125 assert(ProfileInterpreter, "must be profiling interpreter");
1126 Address disp_address(mdp_in, offset_of_disp);
1127 addptr(mdp_in,disp_address);
1128 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
1129 }
1132 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, Register reg, int offset_of_disp) {
1133 assert(ProfileInterpreter, "must be profiling interpreter");
1134 Address disp_address(mdp_in, reg, Address::times_1, offset_of_disp);
1135 addptr(mdp_in, disp_address);
1136 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
1137 }
1140 void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in, int constant) {
1141 assert(ProfileInterpreter, "must be profiling interpreter");
1142 addptr(mdp_in, constant);
1143 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
1144 }
1147 void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) {
1148 assert(ProfileInterpreter, "must be profiling interpreter");
1149 push(return_bci); // save/restore across call_VM
1150 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret), return_bci);
1151 pop(return_bci);
1152 }
1155 void InterpreterMacroAssembler::profile_taken_branch(Register mdp, Register bumped_count) {
1156 if (ProfileInterpreter) {
1157 Label profile_continue;
1159 // If no method data exists, go to profile_continue.
1160 // Otherwise, assign to mdp
1161 test_method_data_pointer(mdp, profile_continue);
1163 // We are taking a branch. Increment the taken count.
1164 // We inline increment_mdp_data_at to return bumped_count in a register
1165 //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
1166 Address data(mdp, in_bytes(JumpData::taken_offset()));
1168 // %%% 64bit treats these cells as 64 bit but they seem to be 32 bit
1169 movl(bumped_count,data);
1170 assert( DataLayout::counter_increment==1, "flow-free idiom only works with 1" );
1171 addl(bumped_count, DataLayout::counter_increment);
1172 sbbl(bumped_count, 0);
1173 movl(data,bumped_count); // Store back out
1175 // The method data pointer needs to be updated to reflect the new target.
1176 update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
1177 bind (profile_continue);
1178 }
1179 }
1182 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) {
1183 if (ProfileInterpreter) {
1184 Label profile_continue;
1186 // If no method data exists, go to profile_continue.
1187 test_method_data_pointer(mdp, profile_continue);
1189 // We are taking a branch. Increment the not taken count.
1190 increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
1192 // The method data pointer needs to be updated to correspond to the next bytecode
1193 update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size()));
1194 bind (profile_continue);
1195 }
1196 }
1199 void InterpreterMacroAssembler::profile_call(Register mdp) {
1200 if (ProfileInterpreter) {
1201 Label profile_continue;
1203 // If no method data exists, go to profile_continue.
1204 test_method_data_pointer(mdp, profile_continue);
1206 // We are making a call. Increment the count.
1207 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1209 // The method data pointer needs to be updated to reflect the new target.
1210 update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
1211 bind (profile_continue);
1212 }
1213 }
1216 void InterpreterMacroAssembler::profile_final_call(Register mdp) {
1217 if (ProfileInterpreter) {
1218 Label profile_continue;
1220 // If no method data exists, go to profile_continue.
1221 test_method_data_pointer(mdp, profile_continue);
1223 // We are making a call. Increment the count.
1224 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1226 // The method data pointer needs to be updated to reflect the new target.
1227 update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size()));
1228 bind (profile_continue);
1229 }
1230 }
1233 void InterpreterMacroAssembler::profile_virtual_call(Register receiver, Register mdp,
1234 Register reg2,
1235 bool receiver_can_be_null) {
1236 if (ProfileInterpreter) {
1237 Label profile_continue;
1239 // If no method data exists, go to profile_continue.
1240 test_method_data_pointer(mdp, profile_continue);
1242 Label skip_receiver_profile;
1243 if (receiver_can_be_null) {
1244 Label not_null;
1245 testptr(receiver, receiver);
1246 jccb(Assembler::notZero, not_null);
1247 // We are making a call. Increment the count for null receiver.
1248 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1249 jmp(skip_receiver_profile);
1250 bind(not_null);
1251 }
1253 // Record the receiver type.
1254 record_klass_in_profile(receiver, mdp, reg2, true);
1255 bind(skip_receiver_profile);
1257 // The method data pointer needs to be updated to reflect the new target.
1258 update_mdp_by_constant(mdp,
1259 in_bytes(VirtualCallData::
1260 virtual_call_data_size()));
1261 bind(profile_continue);
1262 }
1263 }
1266 void InterpreterMacroAssembler::record_klass_in_profile_helper(
1267 Register receiver, Register mdp,
1268 Register reg2, int start_row,
1269 Label& done, bool is_virtual_call) {
1270 if (TypeProfileWidth == 0) {
1271 if (is_virtual_call) {
1272 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1273 }
1274 return;
1275 }
1277 int last_row = VirtualCallData::row_limit() - 1;
1278 assert(start_row <= last_row, "must be work left to do");
1279 // Test this row for both the receiver and for null.
1280 // Take any of three different outcomes:
1281 // 1. found receiver => increment count and goto done
1282 // 2. found null => keep looking for case 1, maybe allocate this cell
1283 // 3. found something else => keep looking for cases 1 and 2
1284 // Case 3 is handled by a recursive call.
1285 for (int row = start_row; row <= last_row; row++) {
1286 Label next_test;
1287 bool test_for_null_also = (row == start_row);
1289 // See if the receiver is receiver[n].
1290 int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row));
1291 test_mdp_data_at(mdp, recvr_offset, receiver,
1292 (test_for_null_also ? reg2 : noreg),
1293 next_test);
1294 // (Reg2 now contains the receiver from the CallData.)
1296 // The receiver is receiver[n]. Increment count[n].
1297 int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row));
1298 increment_mdp_data_at(mdp, count_offset);
1299 jmp(done);
1300 bind(next_test);
1302 if (row == start_row) {
1303 Label found_null;
1304 // Failed the equality check on receiver[n]... Test for null.
1305 testptr(reg2, reg2);
1306 if (start_row == last_row) {
1307 // The only thing left to do is handle the null case.
1308 if (is_virtual_call) {
1309 jccb(Assembler::zero, found_null);
1310 // Receiver did not match any saved receiver and there is no empty row for it.
1311 // Increment total counter to indicate polymorphic case.
1312 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1313 jmp(done);
1314 bind(found_null);
1315 } else {
1316 jcc(Assembler::notZero, done);
1317 }
1318 break;
1319 }
1320 // Since null is rare, make it be the branch-taken case.
1321 jcc(Assembler::zero, found_null);
1323 // Put all the "Case 3" tests here.
1324 record_klass_in_profile_helper(receiver, mdp, reg2, start_row + 1, done, is_virtual_call);
1326 // Found a null. Keep searching for a matching receiver,
1327 // but remember that this is an empty (unused) slot.
1328 bind(found_null);
1329 }
1330 }
1332 // In the fall-through case, we found no matching receiver, but we
1333 // observed the receiver[start_row] is NULL.
1335 // Fill in the receiver field and increment the count.
1336 int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row));
1337 set_mdp_data_at(mdp, recvr_offset, receiver);
1338 int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row));
1339 movptr(reg2, (int32_t)DataLayout::counter_increment);
1340 set_mdp_data_at(mdp, count_offset, reg2);
1341 if (start_row > 0) {
1342 jmp(done);
1343 }
1344 }
1346 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,
1347 Register mdp, Register reg2,
1348 bool is_virtual_call) {
1349 assert(ProfileInterpreter, "must be profiling");
1350 Label done;
1352 record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call);
1354 bind (done);
1355 }
1357 void InterpreterMacroAssembler::profile_ret(Register return_bci, Register mdp) {
1358 if (ProfileInterpreter) {
1359 Label profile_continue;
1360 uint row;
1362 // If no method data exists, go to profile_continue.
1363 test_method_data_pointer(mdp, profile_continue);
1365 // Update the total ret count.
1366 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1368 for (row = 0; row < RetData::row_limit(); row++) {
1369 Label next_test;
1371 // See if return_bci is equal to bci[n]:
1372 test_mdp_data_at(mdp, in_bytes(RetData::bci_offset(row)), return_bci,
1373 noreg, next_test);
1375 // return_bci is equal to bci[n]. Increment the count.
1376 increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row)));
1378 // The method data pointer needs to be updated to reflect the new target.
1379 update_mdp_by_offset(mdp, in_bytes(RetData::bci_displacement_offset(row)));
1380 jmp(profile_continue);
1381 bind(next_test);
1382 }
1384 update_mdp_for_ret(return_bci);
1386 bind (profile_continue);
1387 }
1388 }
1391 void InterpreterMacroAssembler::profile_null_seen(Register mdp) {
1392 if (ProfileInterpreter) {
1393 Label profile_continue;
1395 // If no method data exists, go to profile_continue.
1396 test_method_data_pointer(mdp, profile_continue);
1398 set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
1400 // The method data pointer needs to be updated.
1401 int mdp_delta = in_bytes(BitData::bit_data_size());
1402 if (TypeProfileCasts) {
1403 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1404 }
1405 update_mdp_by_constant(mdp, mdp_delta);
1407 bind (profile_continue);
1408 }
1409 }
1412 void InterpreterMacroAssembler::profile_typecheck_failed(Register mdp) {
1413 if (ProfileInterpreter && TypeProfileCasts) {
1414 Label profile_continue;
1416 // If no method data exists, go to profile_continue.
1417 test_method_data_pointer(mdp, profile_continue);
1419 int count_offset = in_bytes(CounterData::count_offset());
1420 // Back up the address, since we have already bumped the mdp.
1421 count_offset -= in_bytes(VirtualCallData::virtual_call_data_size());
1423 // *Decrement* the counter. We expect to see zero or small negatives.
1424 increment_mdp_data_at(mdp, count_offset, true);
1426 bind (profile_continue);
1427 }
1428 }
1431 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2)
1432 {
1433 if (ProfileInterpreter) {
1434 Label profile_continue;
1436 // If no method data exists, go to profile_continue.
1437 test_method_data_pointer(mdp, profile_continue);
1439 // The method data pointer needs to be updated.
1440 int mdp_delta = in_bytes(BitData::bit_data_size());
1441 if (TypeProfileCasts) {
1442 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1444 // Record the object type.
1445 record_klass_in_profile(klass, mdp, reg2, false);
1446 assert(reg2 == rdi, "we know how to fix this blown reg");
1447 restore_locals(); // Restore EDI
1448 }
1449 update_mdp_by_constant(mdp, mdp_delta);
1451 bind(profile_continue);
1452 }
1453 }
1456 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
1457 if (ProfileInterpreter) {
1458 Label profile_continue;
1460 // If no method data exists, go to profile_continue.
1461 test_method_data_pointer(mdp, profile_continue);
1463 // Update the default case count
1464 increment_mdp_data_at(mdp, in_bytes(MultiBranchData::default_count_offset()));
1466 // The method data pointer needs to be updated.
1467 update_mdp_by_offset(mdp, in_bytes(MultiBranchData::default_displacement_offset()));
1469 bind (profile_continue);
1470 }
1471 }
1474 void InterpreterMacroAssembler::profile_switch_case(Register index, Register mdp, Register reg2) {
1475 if (ProfileInterpreter) {
1476 Label profile_continue;
1478 // If no method data exists, go to profile_continue.
1479 test_method_data_pointer(mdp, profile_continue);
1481 // Build the base (index * per_case_size_in_bytes()) + case_array_offset_in_bytes()
1482 movptr(reg2, (int32_t)in_bytes(MultiBranchData::per_case_size()));
1483 // index is positive and so should have correct value if this code were
1484 // used on 64bits
1485 imulptr(index, reg2);
1486 addptr(index, in_bytes(MultiBranchData::case_array_offset()));
1488 // Update the case count
1489 increment_mdp_data_at(mdp, index, in_bytes(MultiBranchData::relative_count_offset()));
1491 // The method data pointer needs to be updated.
1492 update_mdp_by_offset(mdp, index, in_bytes(MultiBranchData::relative_displacement_offset()));
1494 bind (profile_continue);
1495 }
1496 }
1498 #endif // !CC_INTERP
1502 void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) {
1503 if (state == atos) MacroAssembler::verify_oop(reg);
1504 }
1507 #ifndef CC_INTERP
1508 void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) {
1509 if (state == ftos || state == dtos) MacroAssembler::verify_FPU(stack_depth);
1510 }
1512 #endif /* CC_INTERP */
1515 void InterpreterMacroAssembler::notify_method_entry() {
1516 // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
1517 // track stack depth. If it is possible to enter interp_only_mode we add
1518 // the code to check if the event should be sent.
1519 if (JvmtiExport::can_post_interpreter_events()) {
1520 Label L;
1521 get_thread(rcx);
1522 movl(rcx, Address(rcx, JavaThread::interp_only_mode_offset()));
1523 testl(rcx,rcx);
1524 jcc(Assembler::zero, L);
1525 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_entry));
1526 bind(L);
1527 }
1529 {
1530 SkipIfEqual skip_if(this, &DTraceMethodProbes, 0);
1531 get_thread(rcx);
1532 get_method(rbx);
1533 call_VM_leaf(
1534 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), rcx, rbx);
1535 }
1537 // RedefineClasses() tracing support for obsolete method entry
1538 if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
1539 get_thread(rcx);
1540 get_method(rbx);
1541 call_VM_leaf(
1542 CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
1543 rcx, rbx);
1544 }
1545 }
1548 void InterpreterMacroAssembler::notify_method_exit(
1549 TosState state, NotifyMethodExitMode mode) {
1550 // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
1551 // track stack depth. If it is possible to enter interp_only_mode we add
1552 // the code to check if the event should be sent.
1553 if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {
1554 Label L;
1555 // Note: frame::interpreter_frame_result has a dependency on how the
1556 // method result is saved across the call to post_method_exit. If this
1557 // is changed then the interpreter_frame_result implementation will
1558 // need to be updated too.
1560 // For c++ interpreter the result is always stored at a known location in the frame
1561 // template interpreter will leave it on the top of the stack.
1562 NOT_CC_INTERP(push(state);)
1563 get_thread(rcx);
1564 movl(rcx, Address(rcx, JavaThread::interp_only_mode_offset()));
1565 testl(rcx,rcx);
1566 jcc(Assembler::zero, L);
1567 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit));
1568 bind(L);
1569 NOT_CC_INTERP(pop(state);)
1570 }
1572 {
1573 SkipIfEqual skip_if(this, &DTraceMethodProbes, 0);
1574 NOT_CC_INTERP(push(state));
1575 get_thread(rbx);
1576 get_method(rcx);
1577 call_VM_leaf(
1578 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
1579 rbx, rcx);
1580 NOT_CC_INTERP(pop(state));
1581 }
1582 }