annotate src/cpu/x86/vm/interp_masm_x86_64.cpp @ 826:3f06f139ef53

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