1.1 --- a/src/cpu/x86/vm/assembler_x86.cpp Mon Jul 23 13:04:59 2012 -0700 1.2 +++ b/src/cpu/x86/vm/assembler_x86.cpp Tue Jul 24 10:51:00 2012 -0700 1.3 @@ -41,6 +41,15 @@ 1.4 #include "gc_implementation/g1/heapRegion.hpp" 1.5 #endif 1.6 1.7 +#ifdef PRODUCT 1.8 +#define BLOCK_COMMENT(str) /* nothing */ 1.9 +#define STOP(error) stop(error) 1.10 +#else 1.11 +#define BLOCK_COMMENT(str) block_comment(str) 1.12 +#define STOP(error) block_comment(error); stop(error) 1.13 +#endif 1.14 + 1.15 +#define BIND(label) bind(label); BLOCK_COMMENT(#label ":") 1.16 // Implementation of AddressLiteral 1.17 1.18 AddressLiteral::AddressLiteral(address target, relocInfo::relocType rtype) { 1.19 @@ -5508,23 +5517,7 @@ 1.20 // To see where a verify_oop failed, get $ebx+40/X for this frame. 1.21 // This is the value of eip which points to where verify_oop will return. 1.22 if (os::message_box(msg, "Execution stopped, print registers?")) { 1.23 - ttyLocker ttyl; 1.24 - tty->print_cr("eip = 0x%08x", eip); 1.25 -#ifndef PRODUCT 1.26 - if ((WizardMode || Verbose) && PrintMiscellaneous) { 1.27 - tty->cr(); 1.28 - findpc(eip); 1.29 - tty->cr(); 1.30 - } 1.31 -#endif 1.32 - tty->print_cr("rax = 0x%08x", rax); 1.33 - tty->print_cr("rbx = 0x%08x", rbx); 1.34 - tty->print_cr("rcx = 0x%08x", rcx); 1.35 - tty->print_cr("rdx = 0x%08x", rdx); 1.36 - tty->print_cr("rdi = 0x%08x", rdi); 1.37 - tty->print_cr("rsi = 0x%08x", rsi); 1.38 - tty->print_cr("rbp = 0x%08x", rbp); 1.39 - tty->print_cr("rsp = 0x%08x", rsp); 1.40 + print_state32(rdi, rsi, rbp, rsp, rbx, rdx, rcx, rax, eip); 1.41 BREAKPOINT; 1.42 assert(false, "start up GDB"); 1.43 } 1.44 @@ -5536,12 +5529,53 @@ 1.45 ThreadStateTransition::transition(thread, _thread_in_vm, saved_state); 1.46 } 1.47 1.48 +void MacroAssembler::print_state32(int rdi, int rsi, int rbp, int rsp, int rbx, int rdx, int rcx, int rax, int eip) { 1.49 + ttyLocker ttyl; 1.50 + FlagSetting fs(Debugging, true); 1.51 + tty->print_cr("eip = 0x%08x", eip); 1.52 +#ifndef PRODUCT 1.53 + if ((WizardMode || Verbose) && PrintMiscellaneous) { 1.54 + tty->cr(); 1.55 + findpc(eip); 1.56 + tty->cr(); 1.57 + } 1.58 +#endif 1.59 +#define PRINT_REG(rax) \ 1.60 + { tty->print("%s = ", #rax); os::print_location(tty, rax); } 1.61 + PRINT_REG(rax); 1.62 + PRINT_REG(rbx); 1.63 + PRINT_REG(rcx); 1.64 + PRINT_REG(rdx); 1.65 + PRINT_REG(rdi); 1.66 + PRINT_REG(rsi); 1.67 + PRINT_REG(rbp); 1.68 + PRINT_REG(rsp); 1.69 +#undef PRINT_REG 1.70 + // Print some words near top of staack. 1.71 + int* dump_sp = (int*) rsp; 1.72 + for (int col1 = 0; col1 < 8; col1++) { 1.73 + tty->print("(rsp+0x%03x) 0x%08x: ", (int)((intptr_t)dump_sp - (intptr_t)rsp), (intptr_t)dump_sp); 1.74 + os::print_location(tty, *dump_sp++); 1.75 + } 1.76 + for (int row = 0; row < 16; row++) { 1.77 + tty->print("(rsp+0x%03x) 0x%08x: ", (int)((intptr_t)dump_sp - (intptr_t)rsp), (intptr_t)dump_sp); 1.78 + for (int col = 0; col < 8; col++) { 1.79 + tty->print(" 0x%08x", *dump_sp++); 1.80 + } 1.81 + tty->cr(); 1.82 + } 1.83 + // Print some instructions around pc: 1.84 + Disassembler::decode((address)eip-64, (address)eip); 1.85 + tty->print_cr("--------"); 1.86 + Disassembler::decode((address)eip, (address)eip+32); 1.87 +} 1.88 + 1.89 void MacroAssembler::stop(const char* msg) { 1.90 ExternalAddress message((address)msg); 1.91 // push address of message 1.92 pushptr(message.addr()); 1.93 { Label L; call(L, relocInfo::none); bind(L); } // push eip 1.94 - pusha(); // push registers 1.95 + pusha(); // push registers 1.96 call(RuntimeAddress(CAST_FROM_FN_PTR(address, MacroAssembler::debug32))); 1.97 hlt(); 1.98 } 1.99 @@ -5558,6 +5592,18 @@ 1.100 pop_CPU_state(); 1.101 } 1.102 1.103 +void MacroAssembler::print_state() { 1.104 + { Label L; call(L, relocInfo::none); bind(L); } // push eip 1.105 + pusha(); // push registers 1.106 + 1.107 + push_CPU_state(); 1.108 + call(RuntimeAddress(CAST_FROM_FN_PTR(address, MacroAssembler::print_state32))); 1.109 + pop_CPU_state(); 1.110 + 1.111 + popa(); 1.112 + addl(rsp, wordSize); 1.113 +} 1.114 + 1.115 #else // _LP64 1.116 1.117 // 64 bit versions 1.118 @@ -6023,14 +6069,33 @@ 1.119 } 1.120 1.121 void MacroAssembler::warn(const char* msg) { 1.122 - push(rsp); 1.123 + push(rbp); 1.124 + movq(rbp, rsp); 1.125 andq(rsp, -16); // align stack as required by push_CPU_state and call 1.126 - 1.127 push_CPU_state(); // keeps alignment at 16 bytes 1.128 lea(c_rarg0, ExternalAddress((address) msg)); 1.129 call_VM_leaf(CAST_FROM_FN_PTR(address, warning), c_rarg0); 1.130 pop_CPU_state(); 1.131 - pop(rsp); 1.132 + mov(rsp, rbp); 1.133 + pop(rbp); 1.134 +} 1.135 + 1.136 +void MacroAssembler::print_state() { 1.137 + address rip = pc(); 1.138 + pusha(); // get regs on stack 1.139 + push(rbp); 1.140 + movq(rbp, rsp); 1.141 + andq(rsp, -16); // align stack as required by push_CPU_state and call 1.142 + push_CPU_state(); // keeps alignment at 16 bytes 1.143 + 1.144 + lea(c_rarg0, InternalAddress(rip)); 1.145 + lea(c_rarg1, Address(rbp, wordSize)); // pass pointer to regs array 1.146 + call_VM_leaf(CAST_FROM_FN_PTR(address, MacroAssembler::print_state64), c_rarg0, c_rarg1); 1.147 + 1.148 + pop_CPU_state(); 1.149 + mov(rsp, rbp); 1.150 + pop(rbp); 1.151 + popa(); 1.152 } 1.153 1.154 #ifndef PRODUCT 1.155 @@ -6039,7 +6104,7 @@ 1.156 1.157 void MacroAssembler::debug64(char* msg, int64_t pc, int64_t regs[]) { 1.158 // In order to get locks to work, we need to fake a in_VM state 1.159 - if (ShowMessageBoxOnError ) { 1.160 + if (ShowMessageBoxOnError) { 1.161 JavaThread* thread = JavaThread::current(); 1.162 JavaThreadState saved_state = thread->thread_state(); 1.163 thread->set_thread_state(_thread_in_vm); 1.164 @@ -6053,30 +6118,9 @@ 1.165 // XXX correct this offset for amd64 1.166 // This is the value of eip which points to where verify_oop will return. 1.167 if (os::message_box(msg, "Execution stopped, print registers?")) { 1.168 - ttyLocker ttyl; 1.169 - tty->print_cr("rip = 0x%016lx", pc); 1.170 -#ifndef PRODUCT 1.171 - tty->cr(); 1.172 - findpc(pc); 1.173 - tty->cr(); 1.174 -#endif 1.175 - tty->print_cr("rax = 0x%016lx", regs[15]); 1.176 - tty->print_cr("rbx = 0x%016lx", regs[12]); 1.177 - tty->print_cr("rcx = 0x%016lx", regs[14]); 1.178 - tty->print_cr("rdx = 0x%016lx", regs[13]); 1.179 - tty->print_cr("rdi = 0x%016lx", regs[8]); 1.180 - tty->print_cr("rsi = 0x%016lx", regs[9]); 1.181 - tty->print_cr("rbp = 0x%016lx", regs[10]); 1.182 - tty->print_cr("rsp = 0x%016lx", regs[11]); 1.183 - tty->print_cr("r8 = 0x%016lx", regs[7]); 1.184 - tty->print_cr("r9 = 0x%016lx", regs[6]); 1.185 - tty->print_cr("r10 = 0x%016lx", regs[5]); 1.186 - tty->print_cr("r11 = 0x%016lx", regs[4]); 1.187 - tty->print_cr("r12 = 0x%016lx", regs[3]); 1.188 - tty->print_cr("r13 = 0x%016lx", regs[2]); 1.189 - tty->print_cr("r14 = 0x%016lx", regs[1]); 1.190 - tty->print_cr("r15 = 0x%016lx", regs[0]); 1.191 + print_state64(pc, regs); 1.192 BREAKPOINT; 1.193 + assert(false, "start up GDB"); 1.194 } 1.195 ThreadStateTransition::transition(thread, _thread_in_vm, saved_state); 1.196 } else { 1.197 @@ -6087,6 +6131,54 @@ 1.198 } 1.199 } 1.200 1.201 +void MacroAssembler::print_state64(int64_t pc, int64_t regs[]) { 1.202 + ttyLocker ttyl; 1.203 + FlagSetting fs(Debugging, true); 1.204 + tty->print_cr("rip = 0x%016lx", pc); 1.205 +#ifndef PRODUCT 1.206 + tty->cr(); 1.207 + findpc(pc); 1.208 + tty->cr(); 1.209 +#endif 1.210 +#define PRINT_REG(rax, value) \ 1.211 + { tty->print("%s = ", #rax); os::print_location(tty, value); } 1.212 + PRINT_REG(rax, regs[15]); 1.213 + PRINT_REG(rbx, regs[12]); 1.214 + PRINT_REG(rcx, regs[14]); 1.215 + PRINT_REG(rdx, regs[13]); 1.216 + PRINT_REG(rdi, regs[8]); 1.217 + PRINT_REG(rsi, regs[9]); 1.218 + PRINT_REG(rbp, regs[10]); 1.219 + PRINT_REG(rsp, regs[11]); 1.220 + PRINT_REG(r8 , regs[7]); 1.221 + PRINT_REG(r9 , regs[6]); 1.222 + PRINT_REG(r10, regs[5]); 1.223 + PRINT_REG(r11, regs[4]); 1.224 + PRINT_REG(r12, regs[3]); 1.225 + PRINT_REG(r13, regs[2]); 1.226 + PRINT_REG(r14, regs[1]); 1.227 + PRINT_REG(r15, regs[0]); 1.228 +#undef PRINT_REG 1.229 + // Print some words near top of staack. 1.230 + int64_t* rsp = (int64_t*) regs[11]; 1.231 + int64_t* dump_sp = rsp; 1.232 + for (int col1 = 0; col1 < 8; col1++) { 1.233 + tty->print("(rsp+0x%03x) 0x%016lx: ", (int)((intptr_t)dump_sp - (intptr_t)rsp), (int64_t)dump_sp); 1.234 + os::print_location(tty, *dump_sp++); 1.235 + } 1.236 + for (int row = 0; row < 25; row++) { 1.237 + tty->print("(rsp+0x%03x) 0x%016lx: ", (int)((intptr_t)dump_sp - (intptr_t)rsp), (int64_t)dump_sp); 1.238 + for (int col = 0; col < 4; col++) { 1.239 + tty->print(" 0x%016lx", *dump_sp++); 1.240 + } 1.241 + tty->cr(); 1.242 + } 1.243 + // Print some instructions around pc: 1.244 + Disassembler::decode((address)pc-64, (address)pc); 1.245 + tty->print_cr("--------"); 1.246 + Disassembler::decode((address)pc, (address)pc+32); 1.247 +} 1.248 + 1.249 #endif // _LP64 1.250 1.251 // Now versions that are common to 32/64 bit 1.252 @@ -6456,7 +6548,7 @@ 1.253 get_thread(rax); 1.254 cmpptr(java_thread, rax); 1.255 jcc(Assembler::equal, L); 1.256 - stop("MacroAssembler::call_VM_base: rdi not callee saved?"); 1.257 + STOP("MacroAssembler::call_VM_base: rdi not callee saved?"); 1.258 bind(L); 1.259 } 1.260 pop(rax); 1.261 @@ -7196,7 +7288,7 @@ 1.262 jcc(Assembler::notZero, integer); 1.263 cmpl(tmp3, 0x80000000); 1.264 jcc(Assembler::notZero, integer); 1.265 - stop("integer indefinite value shouldn't be seen here"); 1.266 + STOP("integer indefinite value shouldn't be seen here"); 1.267 bind(integer); 1.268 } 1.269 #else 1.270 @@ -7206,7 +7298,7 @@ 1.271 shlq(tmp3, 1); 1.272 jcc(Assembler::carryClear, integer); 1.273 jcc(Assembler::notZero, integer); 1.274 - stop("integer indefinite value shouldn't be seen here"); 1.275 + STOP("integer indefinite value shouldn't be seen here"); 1.276 bind(integer); 1.277 } 1.278 #endif 1.279 @@ -8388,7 +8480,7 @@ 1.280 shlptr(tsize, LogHeapWordSize); 1.281 cmpptr(t1, tsize); 1.282 jcc(Assembler::equal, ok); 1.283 - stop("assert(t1 != tlab size)"); 1.284 + STOP("assert(t1 != tlab size)"); 1.285 should_not_reach_here(); 1.286 1.287 bind(ok); 1.288 @@ -8727,6 +8819,19 @@ 1.289 } 1.290 1.291 1.292 +// virtual method calling 1.293 +void MacroAssembler::lookup_virtual_method(Register recv_klass, 1.294 + RegisterOrConstant vtable_index, 1.295 + Register method_result) { 1.296 + const int base = instanceKlass::vtable_start_offset() * wordSize; 1.297 + assert(vtableEntry::size() * wordSize == wordSize, "else adjust the scaling in the code below"); 1.298 + Address vtable_entry_addr(recv_klass, 1.299 + vtable_index, Address::times_ptr, 1.300 + base + vtableEntry::method_offset_in_bytes()); 1.301 + movptr(method_result, vtable_entry_addr); 1.302 +} 1.303 + 1.304 + 1.305 void MacroAssembler::check_klass_subtype(Register sub_klass, 1.306 Register super_klass, 1.307 Register temp_reg, 1.308 @@ -8976,6 +9081,7 @@ 1.309 // Pass register number to verify_oop_subroutine 1.310 char* b = new char[strlen(s) + 50]; 1.311 sprintf(b, "verify_oop: %s: %s", reg->name(), s); 1.312 + BLOCK_COMMENT("verify_oop {"); 1.313 #ifdef _LP64 1.314 push(rscratch1); // save r10, trashed by movptr() 1.315 #endif 1.316 @@ -8990,6 +9096,7 @@ 1.317 movptr(rax, ExternalAddress(StubRoutines::verify_oop_subroutine_entry_address())); 1.318 call(rax); 1.319 // Caller pops the arguments (oop, message) and restores rax, r10 1.320 + BLOCK_COMMENT("} verify_oop"); 1.321 } 1.322 1.323 1.324 @@ -9010,7 +9117,7 @@ 1.325 jcc(Assembler::notZero, L); 1.326 char* buf = new char[40]; 1.327 sprintf(buf, "DelayedValue="INTPTR_FORMAT, delayed_value_addr[1]); 1.328 - stop(buf); 1.329 + STOP(buf); 1.330 } else { 1.331 jccb(Assembler::notZero, L); 1.332 hlt(); 1.333 @@ -9026,60 +9133,6 @@ 1.334 } 1.335 1.336 1.337 -// registers on entry: 1.338 -// - rax ('check' register): required MethodType 1.339 -// - rcx: method handle 1.340 -// - rdx, rsi, or ?: killable temp 1.341 -void MacroAssembler::check_method_handle_type(Register mtype_reg, Register mh_reg, 1.342 - Register temp_reg, 1.343 - Label& wrong_method_type) { 1.344 - Address type_addr(mh_reg, delayed_value(java_lang_invoke_MethodHandle::type_offset_in_bytes, temp_reg)); 1.345 - // compare method type against that of the receiver 1.346 - if (UseCompressedOops) { 1.347 - load_heap_oop(temp_reg, type_addr); 1.348 - cmpptr(mtype_reg, temp_reg); 1.349 - } else { 1.350 - cmpptr(mtype_reg, type_addr); 1.351 - } 1.352 - jcc(Assembler::notEqual, wrong_method_type); 1.353 -} 1.354 - 1.355 - 1.356 -// A method handle has a "vmslots" field which gives the size of its 1.357 -// argument list in JVM stack slots. This field is either located directly 1.358 -// in every method handle, or else is indirectly accessed through the 1.359 -// method handle's MethodType. This macro hides the distinction. 1.360 -void MacroAssembler::load_method_handle_vmslots(Register vmslots_reg, Register mh_reg, 1.361 - Register temp_reg) { 1.362 - assert_different_registers(vmslots_reg, mh_reg, temp_reg); 1.363 - // load mh.type.form.vmslots 1.364 - Register temp2_reg = vmslots_reg; 1.365 - load_heap_oop(temp2_reg, Address(mh_reg, delayed_value(java_lang_invoke_MethodHandle::type_offset_in_bytes, temp_reg))); 1.366 - load_heap_oop(temp2_reg, Address(temp2_reg, delayed_value(java_lang_invoke_MethodType::form_offset_in_bytes, temp_reg))); 1.367 - movl(vmslots_reg, Address(temp2_reg, delayed_value(java_lang_invoke_MethodTypeForm::vmslots_offset_in_bytes, temp_reg))); 1.368 -} 1.369 - 1.370 - 1.371 -// registers on entry: 1.372 -// - rcx: method handle 1.373 -// - rdx: killable temp (interpreted only) 1.374 -// - rax: killable temp (compiled only) 1.375 -void MacroAssembler::jump_to_method_handle_entry(Register mh_reg, Register temp_reg) { 1.376 - assert(mh_reg == rcx, "caller must put MH object in rcx"); 1.377 - assert_different_registers(mh_reg, temp_reg); 1.378 - 1.379 - // pick out the interpreted side of the handler 1.380 - // NOTE: vmentry is not an oop! 1.381 - movptr(temp_reg, Address(mh_reg, delayed_value(java_lang_invoke_MethodHandle::vmentry_offset_in_bytes, temp_reg))); 1.382 - 1.383 - // off we go... 1.384 - jmp(Address(temp_reg, MethodHandleEntry::from_interpreted_entry_offset_in_bytes())); 1.385 - 1.386 - // for the various stubs which take control at this point, 1.387 - // see MethodHandles::generate_method_handle_stub 1.388 -} 1.389 - 1.390 - 1.391 Address MacroAssembler::argument_address(RegisterOrConstant arg_slot, 1.392 int extra_slot_offset) { 1.393 // cf. TemplateTable::prepare_invoke(), if (load_receiver). 1.394 @@ -9152,14 +9205,14 @@ 1.395 movptr(t1, Address(thread_reg, in_bytes(JavaThread::tlab_top_offset()))); 1.396 cmpptr(t1, Address(thread_reg, in_bytes(JavaThread::tlab_start_offset()))); 1.397 jcc(Assembler::aboveEqual, next); 1.398 - stop("assert(top >= start)"); 1.399 + STOP("assert(top >= start)"); 1.400 should_not_reach_here(); 1.401 1.402 bind(next); 1.403 movptr(t1, Address(thread_reg, in_bytes(JavaThread::tlab_end_offset()))); 1.404 cmpptr(t1, Address(thread_reg, in_bytes(JavaThread::tlab_top_offset()))); 1.405 jcc(Assembler::aboveEqual, ok); 1.406 - stop("assert(top <= end)"); 1.407 + STOP("assert(top <= end)"); 1.408 should_not_reach_here(); 1.409 1.410 bind(ok); 1.411 @@ -9592,6 +9645,25 @@ 1.412 movptr(dst, src); 1.413 } 1.414 1.415 +void MacroAssembler::cmp_heap_oop(Register src1, Address src2, Register tmp) { 1.416 + assert_different_registers(src1, tmp); 1.417 +#ifdef _LP64 1.418 + if (UseCompressedOops) { 1.419 + bool did_push = false; 1.420 + if (tmp == noreg) { 1.421 + tmp = rax; 1.422 + push(tmp); 1.423 + did_push = true; 1.424 + assert(!src2.uses(rsp), "can't push"); 1.425 + } 1.426 + load_heap_oop(tmp, src2); 1.427 + cmpptr(src1, tmp); 1.428 + if (did_push) pop(tmp); 1.429 + } else 1.430 +#endif 1.431 + cmpptr(src1, src2); 1.432 +} 1.433 + 1.434 // Used for storing NULLs. 1.435 void MacroAssembler::store_heap_oop_null(Address dst) { 1.436 #ifdef _LP64 1.437 @@ -9622,7 +9694,7 @@ 1.438 push(rscratch1); // cmpptr trashes rscratch1 1.439 cmpptr(r12_heapbase, ExternalAddress((address)Universe::narrow_oop_base_addr())); 1.440 jcc(Assembler::equal, ok); 1.441 - stop(msg); 1.442 + STOP(msg); 1.443 bind(ok); 1.444 pop(rscratch1); 1.445 } 1.446 @@ -9655,7 +9727,7 @@ 1.447 Label ok; 1.448 testq(r, r); 1.449 jcc(Assembler::notEqual, ok); 1.450 - stop("null oop passed to encode_heap_oop_not_null"); 1.451 + STOP("null oop passed to encode_heap_oop_not_null"); 1.452 bind(ok); 1.453 } 1.454 #endif 1.455 @@ -9676,7 +9748,7 @@ 1.456 Label ok; 1.457 testq(src, src); 1.458 jcc(Assembler::notEqual, ok); 1.459 - stop("null oop passed to encode_heap_oop_not_null2"); 1.460 + STOP("null oop passed to encode_heap_oop_not_null2"); 1.461 bind(ok); 1.462 } 1.463 #endif 1.464 @@ -9867,7 +9939,7 @@ 1.465 cmpptr(rax, StackAlignmentInBytes-wordSize); 1.466 pop(rax); 1.467 jcc(Assembler::equal, L); 1.468 - stop("Stack is not properly aligned!"); 1.469 + STOP("Stack is not properly aligned!"); 1.470 bind(L); 1.471 } 1.472 #endif 1.473 @@ -10541,13 +10613,6 @@ 1.474 bind(DONE); 1.475 } 1.476 1.477 -#ifdef PRODUCT 1.478 -#define BLOCK_COMMENT(str) /* nothing */ 1.479 -#else 1.480 -#define BLOCK_COMMENT(str) block_comment(str) 1.481 -#endif 1.482 - 1.483 -#define BIND(label) bind(label); BLOCK_COMMENT(#label ":") 1.484 void MacroAssembler::generate_fill(BasicType t, bool aligned, 1.485 Register to, Register value, Register count, 1.486 Register rtmp, XMMRegister xtmp) {