Skip to content

Commit f334c51

Browse files
committed
Support cstack=vm/vmx on macOS
1 parent 87c5436 commit f334c51

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

src/profiler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,7 @@ Error Profiler::start(Arguments& args, bool reset) {
11681168
return Error("DWARF unwinding is not supported on this platform");
11691169
} else if (_cstack == CSTACK_LBR && _engine != &perf_events) {
11701170
return Error("Branch stack is supported only with PMU events");
1171-
} else if (_cstack >= CSTACK_VM && !(VMStructs::hasStackStructs() && OS::isLinux())) {
1171+
} else if (_cstack >= CSTACK_VM && !VMStructs::hasStackStructs()) {
11721172
return Error("VMStructs stack walking is not supported on this JVM/platform");
11731173
}
11741174

@@ -1329,7 +1329,7 @@ Error Profiler::check(Arguments& args) {
13291329
return Error("DWARF unwinding is not supported on this platform");
13301330
} else if (args._cstack == CSTACK_LBR && _engine != &perf_events) {
13311331
return Error("Branch stack is supported only with PMU events");
1332-
} else if (args._cstack >= CSTACK_VM && !(VMStructs::hasStackStructs() && OS::isLinux())) {
1332+
} else if (args._cstack >= CSTACK_VM && !VMStructs::hasStackStructs()) {
13331333
return Error("VMStructs stack walking is not supported on this JVM/platform");
13341334
}
13351335
}

src/stackWalker.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ static inline bool sameStack(void* hi, void* lo) {
3131
return (uintptr_t)hi - (uintptr_t)lo < SAME_STACK_DISTANCE;
3232
}
3333

34+
// AArch64: on Linux, frame link is stored at the top of the frame,
35+
// while on macOS, frame link is at the bottom.
36+
static inline uintptr_t defaultSenderSP(uintptr_t sp, uintptr_t fp) {
37+
#ifdef __APPLE__
38+
return sp + 2 * sizeof(void*);
39+
#else
40+
return fp;
41+
#endif
42+
}
43+
3444
static inline void fillFrame(ASGCT_CallFrame& frame, ASGCT_CallFrameType type, const char* name) {
3545
frame.bci = type;
3646
frame.method_id = (jmethodID)name;
@@ -176,7 +186,7 @@ int StackWalker::walkDwarf(void* ucontext, const void** callchain, int max_depth
176186
} else if (f->fp_off != DW_SAME_FP) {
177187
// AArch64 default_frame
178188
pc = stripPointer(SafeAccess::load((void**)(sp + f->pc_off)));
179-
sp = fp;
189+
sp = defaultSenderSP(sp, fp);
180190
} else if (depth <= 1) {
181191
pc = (const void*)frame.link();
182192
} else {
@@ -420,7 +430,7 @@ int StackWalker::walkVM(void* ucontext, ASGCT_CallFrame* frames, int max_depth,
420430
} else if (f->fp_off != DW_SAME_FP) {
421431
// AArch64 default_frame
422432
pc = stripPointer(*(void**)(sp + f->pc_off));
423-
sp = fp;
433+
sp = defaultSenderSP(sp, fp);
424434
} else if (depth <= 1) {
425435
pc = (const void*)frame.link();
426436
} else {

0 commit comments

Comments
 (0)