Skip to content

Commit d756726

Browse files
apanginr1viollet
authored andcommitted
#893: Fix [no_Java_frame] on ARM64
1 parent 397f8c2 commit d756726

File tree

7 files changed

+37
-2
lines changed

7 files changed

+37
-2
lines changed

ddprof-lib/src/main/cpp/stackFrame.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class StackFrame {
7474
bool unwindStub(instruction_t *entry, const char *name, uintptr_t &pc,
7575
uintptr_t &sp, uintptr_t &fp);
7676
bool unwindCompiled(NMethod *nm, uintptr_t &pc, uintptr_t &sp, uintptr_t &fp);
77+
bool unwindAtomicStub(const void*& pc);
7778

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

ddprof-lib/src/main/cpp/stackFrame_aarch64.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,19 @@ bool StackFrame::unwindCompiled(NMethod *nm, uintptr_t &pc, uintptr_t &sp,
136136
return true;
137137
}
138138

139+
bool StackFrame::unwindAtomicStub(const void*& pc) {
140+
// VM threads may call generated atomic stubs, which are not normally walkable
141+
const void* lr = (const void*)link();
142+
if (VMStructs::libjvm()->contains(lr)) {
143+
NMethod* nm = CodeHeap::findNMethod(pc);
144+
if (nm != NULL && strncmp(nm->name(), "Stub", 4) == 0) {
145+
pc = lr;
146+
return true;
147+
}
148+
}
149+
return false;
150+
}
151+
139152
void StackFrame::adjustSP(const void *entry, const void *pc, uintptr_t &sp) {
140153
instruction_t *ip = (instruction_t *)pc;
141154
if (ip > entry && (ip[-1] == 0xa9bf27ff ||

ddprof-lib/src/main/cpp/stackFrame_arm.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ void StackFrame::adjustSP(const void *entry, const void *pc, uintptr_t &sp) {
112112
// Not needed
113113
}
114114

115+
bool StackFrame::unwindAtomicStub(const void*& pc) {
116+
// Not needed
117+
return false;
118+
}
119+
115120
bool StackFrame::skipFaultInstruction() { return false; }
116121

117122
bool StackFrame::checkInterruptedSyscall() {

ddprof-lib/src/main/cpp/stackFrame_i386.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ void StackFrame::adjustSP(const void *entry, const void *pc, uintptr_t &sp) {
119119
// Not needed
120120
}
121121

122+
bool StackFrame::unwindAtomicStub(const void*& pc) {
123+
// Not needed
124+
return false;
125+
}
126+
122127
bool StackFrame::skipFaultInstruction() { return false; }
123128

124129
bool StackFrame::checkInterruptedSyscall() {

ddprof-lib/src/main/cpp/stackFrame_ppc64.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ void StackFrame::adjustSP(const void *entry, const void *pc, uintptr_t &sp) {
147147
// Not needed
148148
}
149149

150+
bool StackFrame::unwindAtomicStub(const void*& pc) {
151+
// Not needed
152+
return false;
153+
}
154+
150155
bool StackFrame::skipFaultInstruction() { return false; }
151156

152157
bool StackFrame::checkInterruptedSyscall() {

ddprof-lib/src/main/cpp/stackFrame_x64.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ void StackFrame::adjustSP(const void *entry, const void *pc, uintptr_t &sp) {
145145
// Not needed
146146
}
147147

148+
bool StackFrame::unwindAtomicStub(const void*& pc) {
149+
// Not needed
150+
return false;
151+
}
152+
148153
// Skip failed MOV instruction by writing 0 to destination register
149154
bool StackFrame::skipFaultInstruction() {
150155
unsigned int insn = *(unsigned int *)pc();

ddprof-lib/src/main/cpp/stackWalker.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ int StackWalker::walkFP(void *ucontext, const void **callchain, int max_depth,
7171
uintptr_t sp;
7272
uintptr_t bottom = (uintptr_t)&sp + MAX_WALK_SIZE;
7373

74+
StackFrame frame(ucontext);
7475
if (ucontext == NULL) {
7576
pc = __builtin_return_address(0);
7677
fp = (uintptr_t)__builtin_frame_address(1);
@@ -92,7 +93,7 @@ int StackWalker::walkFP(void *ucontext, const void **callchain, int max_depth,
9293
*truncated = true;
9394
break;
9495
}
95-
if (CodeHeap::contains(pc)) {
96+
if (CodeHeap::contains(pc) && !(depth == 0 && frame.unwindAtomicStub(pc))) {
9697
java_ctx->set(pc, sp, fp);
9798
break;
9899
}
@@ -154,7 +155,7 @@ int StackWalker::walkDwarf(void *ucontext, const void **callchain,
154155
*truncated = true;
155156
break;
156157
}
157-
if (CodeHeap::contains(pc)) {
158+
if (CodeHeap::contains(pc) && !(depth == 0 && frame.unwindAtomicStub(pc))) {
158159
const void* page_start = (const void*)((uintptr_t)pc & ~0xfffUL);
159160
frame.adjustSP(page_start, pc, sp);
160161
java_ctx->set(pc, sp, fp);

0 commit comments

Comments
 (0)