Skip to content

Commit

Permalink
async-profiler#747: Workaround for JDK-8307549
Browse files Browse the repository at this point in the history
  • Loading branch information
apangin committed Aug 2, 2023
1 parent eb28799 commit a852bdd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,14 +800,22 @@ void Profiler::trapHandler(int signo, siginfo_t* siginfo, void* ucontext) {
void Profiler::segvHandler(int signo, siginfo_t* siginfo, void* ucontext) {
StackFrame frame(ucontext);

uintptr_t length = SafeAccess::skipFaultInstruction(frame.pc());
uintptr_t length = SafeAccess::skipLoad(frame.pc());
if (length > 0) {
// Skip the fault instruction, as if it successfully loaded NULL
frame.pc() += length;
frame.retval() = 0;
return;
}

length = SafeAccess::skipLoad32(frame.pc());
if (length > 0) {
// Act as if the load returned default_value argument
frame.pc() += length;
frame.retval() = frame.arg1();
return;
}

if (WX_MEMORY && Trap::isFaultInstruction(frame.pc())) {
return;
}
Expand Down
14 changes: 13 additions & 1 deletion src/safeAccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ class SafeAccess {
return *ptr;
}

static uintptr_t skipFaultInstruction(uintptr_t pc) {
NOINLINE __attribute__((aligned(16)))
static u32 load32(u32* ptr, u32 default_value) {
return *ptr;
}

static uintptr_t skipLoad(uintptr_t pc) {
if ((pc - (uintptr_t)load) < 16) {
#if defined(__x86_64__)
return *(u16*)pc == 0x8b48 ? 3 : 0; // mov rax, [reg]
Expand All @@ -51,6 +56,13 @@ class SafeAccess {
}
return 0;
}

static uintptr_t skipLoad32(uintptr_t pc) {
if (WX_MEMORY && (pc - (uintptr_t)load32) < 16) {
return 4;
}
return 0;
}
};

#endif // _SAFEACCESS_H
8 changes: 8 additions & 0 deletions src/vmEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ void VM::ready() {

Profiler::setupSignalHandlers();

if (WX_MEMORY && hotspot_version() == 17) {
// Workaround for JDK-8307549
void** entry = (void**)VMStructs::libjvm()->findSymbol("_ZN12StubRoutines18_safefetch32_entryE");
if (entry != NULL) {
*entry = (void*)SafeAccess::load32;
}
}

_libjava = getLibraryHandle("libjava.so");

// Make sure we reload method IDs upon class retransformation
Expand Down

0 comments on commit a852bdd

Please sign in to comment.