annotate src/cpu/x86/vm/interp_masm_x86_64.cpp @ 0:a61af66fc99e

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