src/cpu/x86/vm/interp_masm_x86_64.cpp

Mon, 09 Mar 2009 13:28:46 -0700

author
xdono
date
Mon, 09 Mar 2009 13:28:46 -0700
changeset 1014
0fbdb4381b99
parent 955
52a431267315
child 1063
7bb995fbd3c0
permissions
-rw-r--r--

6814575: Update copyright year
Summary: Update copyright for files that have been modified in 2009, up to 03/09
Reviewed-by: katleman, tbell, ohair

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

mercurial