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