Skip to content

Commit 6cc1c0a

Browse files
author
Jatin Bhateja
committed
8347422: Crash during safepoint handler execution with -XX:+UseAPX
Reviewed-by: kvn, sviswanathan, thartmann
1 parent baca7da commit 6cc1c0a

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/hotspot/cpu/x86/sharedRuntime_x86_64.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3020,7 +3020,7 @@ SafepointBlob* SharedRuntime::generate_handler_blob(SharedStubId id, address cal
30203020

30213021
// Allocate space for the code. Setup code generation tools.
30223022
const char* name = SharedRuntime::stub_name(id);
3023-
CodeBuffer buffer(name, 2348, 1024);
3023+
CodeBuffer buffer(name, 2548, 1024);
30243024
MacroAssembler* masm = new MacroAssembler(&buffer);
30253025

30263026
address start = __ pc();
@@ -3086,11 +3086,11 @@ SafepointBlob* SharedRuntime::generate_handler_blob(SharedStubId id, address cal
30863086
Label bail;
30873087
#endif
30883088
if (!cause_return) {
3089-
Label no_prefix, not_special;
3089+
Label no_prefix, not_special, check_rex_prefix;
30903090

30913091
// If our stashed return pc was modified by the runtime we avoid touching it
30923092
__ cmpptr(rbx, Address(rbp, wordSize));
3093-
__ jccb(Assembler::notEqual, no_adjust);
3093+
__ jcc(Assembler::notEqual, no_adjust);
30943094

30953095
// Skip over the poll instruction.
30963096
// See NativeInstruction::is_safepoint_poll()
@@ -3113,9 +3113,29 @@ SafepointBlob* SharedRuntime::generate_handler_blob(SharedStubId id, address cal
31133113
// 41 85 04 24 test %eax,(%r12)
31143114
// 85 45 00 test %eax,0x0(%rbp)
31153115
// 41 85 45 00 test %eax,0x0(%r13)
3116-
3116+
//
3117+
// Notes:
3118+
// Format of legacy MAP0 test instruction:-
3119+
// [REX/REX2] [OPCODE] [ModRM] [SIB] [DISP] [IMM32]
3120+
// o For safepoint polling instruction "test %eax,(%rax)", encoding of first register
3121+
// operand and base register of memory operand is b/w [0-8), hence we do not require
3122+
// additional REX prefix where REX.B bit stores MSB bit of register encoding, which
3123+
// is why two bytes encoding is sufficient here.
3124+
// o For safepoint polling instruction like "test %eax,(%r8)", register encoding of BASE
3125+
// register of memory operand is 1000, thus we need additional REX prefix in this case,
3126+
// there by adding additional byte to instruction encoding.
3127+
// o In case BASE register is one of the 32 extended GPR registers available only on targets
3128+
// supporting Intel APX extension, then we need to emit two bytes REX2 prefix to hold
3129+
// most significant two bits of 5 bit register encoding.
3130+
3131+
if (VM_Version::supports_apx_f()) {
3132+
__ cmpb(Address(rbx, 0), Assembler::REX2);
3133+
__ jccb(Assembler::notEqual, check_rex_prefix);
3134+
__ addptr(rbx, 2);
3135+
__ bind(check_rex_prefix);
3136+
}
31173137
__ cmpb(Address(rbx, 0), NativeTstRegMem::instruction_rex_b_prefix);
3118-
__ jcc(Assembler::notEqual, no_prefix);
3138+
__ jccb(Assembler::notEqual, no_prefix);
31193139
__ addptr(rbx, 1);
31203140
__ bind(no_prefix);
31213141
#ifdef ASSERT
@@ -3128,7 +3148,7 @@ SafepointBlob* SharedRuntime::generate_handler_blob(SharedStubId id, address cal
31283148
__ andptr(rcx, 0x07); // looking for 0x04 .. 0x05
31293149
__ subptr(rcx, 4); // looking for 0x00 .. 0x01
31303150
__ cmpptr(rcx, 1);
3131-
__ jcc(Assembler::above, not_special);
3151+
__ jccb(Assembler::above, not_special);
31323152
__ addptr(rbx, 1);
31333153
__ bind(not_special);
31343154
#ifdef ASSERT

0 commit comments

Comments
 (0)