Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into jarlauncher
Browse files Browse the repository at this point in the history
  • Loading branch information
apangin committed Mar 11, 2024
2 parents 48409ca + cbecc6f commit acc05a4
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/stackFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class StackFrame {

bool unwindStub(instruction_t* entry, const char* name, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp);
bool unwindCompiled(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp);
bool unwindAtomicStub(const void*& pc);

void adjustSP(const void* entry, const void* pc, uintptr_t& sp);

Expand Down
13 changes: 13 additions & 0 deletions src/stackFrame_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,19 @@ bool StackFrame::unwindCompiled(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintp
return true;
}

bool StackFrame::unwindAtomicStub(const void*& pc) {
// VM threads may call generated atomic stubs, which are not normally walkable
const void* lr = (const void*)link();
if (VMStructs::libjvm()->contains(lr)) {
NMethod* nm = CodeHeap::findNMethod(pc);
if (nm != NULL && strncmp(nm->name(), "Stub", 4) == 0) {
pc = lr;
return true;
}
}
return false;
}

void StackFrame::adjustSP(const void* entry, const void* pc, uintptr_t& sp) {
instruction_t* ip = (instruction_t*)pc;
if (ip > entry && (ip[-1] == 0xa9bf27ff || (ip[-1] == 0xd63f0100 && ip[-2] == 0xa9bf27ff))) {
Expand Down
5 changes: 5 additions & 0 deletions src/stackFrame_arm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ bool StackFrame::unwindCompiled(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintp
return true;
}

bool StackFrame::unwindAtomicStub(const void*& pc) {
// Not needed
return false;
}

void StackFrame::adjustSP(const void* entry, const void* pc, uintptr_t& sp) {
// Not needed
}
Expand Down
5 changes: 5 additions & 0 deletions src/stackFrame_i386.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ bool StackFrame::unwindCompiled(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintp
return false;
}

bool StackFrame::unwindAtomicStub(const void*& pc) {
// Not needed
return false;
}

void StackFrame::adjustSP(const void* entry, const void* pc, uintptr_t& sp) {
// Not needed
}
Expand Down
5 changes: 5 additions & 0 deletions src/stackFrame_loongarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ bool StackFrame::unwindCompiled(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintp
return false;
}

bool StackFrame::unwindAtomicStub(const void*& pc) {
// Not needed
return false;
}

void StackFrame::adjustSP(const void* entry, const void* pc, uintptr_t& sp) {
// Not yet implemented
}
Expand Down
5 changes: 5 additions & 0 deletions src/stackFrame_ppc64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ bool StackFrame::unwindCompiled(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintp
return true;
}

bool StackFrame::unwindAtomicStub(const void*& pc) {
// Not needed
return false;
}

void StackFrame::adjustSP(const void* entry, const void* pc, uintptr_t& sp) {
// Not needed
}
Expand Down
5 changes: 5 additions & 0 deletions src/stackFrame_riscv64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ bool StackFrame::unwindCompiled(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintp
return false;
}

bool StackFrame::unwindAtomicStub(const void*& pc) {
// Not needed
return false;
}

void StackFrame::adjustSP(const void* entry, const void* pc, uintptr_t& sp) {
// Not yet implemented
}
Expand Down
5 changes: 5 additions & 0 deletions src/stackFrame_x64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ bool StackFrame::unwindCompiled(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintp
return false;
}

bool StackFrame::unwindAtomicStub(const void*& pc) {
// Not needed
return false;
}

void StackFrame::adjustSP(const void* entry, const void* pc, uintptr_t& sp) {
// Not needed
}
Expand Down
6 changes: 3 additions & 3 deletions src/stackWalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ int StackWalker::walkFP(void* ucontext, const void** callchain, int max_depth, S
uintptr_t sp;
uintptr_t bottom = (uintptr_t)&sp + MAX_WALK_SIZE;

StackFrame frame(ucontext);
if (ucontext == NULL) {
pc = __builtin_return_address(0);
fp = (uintptr_t)__builtin_frame_address(1);
sp = (uintptr_t)__builtin_frame_address(0);
} else {
StackFrame frame(ucontext);
pc = (const void*)frame.pc();
fp = frame.fp();
sp = frame.sp();
Expand All @@ -73,7 +73,7 @@ int StackWalker::walkFP(void* ucontext, const void** callchain, int max_depth, S

// Walk until the bottom of the stack or until the first Java frame
while (depth < max_depth) {
if (CodeHeap::contains(pc)) {
if (CodeHeap::contains(pc) && !(depth == 0 && frame.unwindAtomicStub(pc))) {
java_ctx->set(pc, sp, fp);
break;
}
Expand Down Expand Up @@ -124,7 +124,7 @@ int StackWalker::walkDwarf(void* ucontext, const void** callchain, int max_depth

// Walk until the bottom of the stack or until the first Java frame
while (depth < max_depth) {
if (CodeHeap::contains(pc)) {
if (CodeHeap::contains(pc) && !(depth == 0 && frame.unwindAtomicStub(pc))) {
const void* page_start = (const void*)((uintptr_t)pc & ~0xfffUL);
frame.adjustSP(page_start, pc, sp);
java_ctx->set(pc, sp, fp);
Expand Down

0 comments on commit acc05a4

Please sign in to comment.