mirror of
https://github.com/async-profiler/async-profiler.git
synced 2026-04-28 10:53:49 +00:00
More AGCT cleanup after removal of recovery tricks (#1683)
This commit is contained in:
@@ -124,9 +124,8 @@ void CpuEngine::signalHandlerJ9(int signo, siginfo_t* siginfo, void* ucontext) {
|
||||
if (!_enabled) return;
|
||||
|
||||
J9StackTraceNotification notif;
|
||||
StackContext java_ctx;
|
||||
notif.num_frames = _cstack == CSTACK_NO ? 0 : _cstack == CSTACK_DWARF
|
||||
? StackWalker::walkDwarf(ucontext, notif.addr, MAX_J9_NATIVE_FRAMES, &java_ctx)
|
||||
: StackWalker::walkFP(ucontext, notif.addr, MAX_J9_NATIVE_FRAMES, &java_ctx);
|
||||
? StackWalker::walkDwarf(ucontext, notif.addr, MAX_J9_NATIVE_FRAMES)
|
||||
: StackWalker::walkFP(ucontext, notif.addr, MAX_J9_NATIVE_FRAMES);
|
||||
J9StackTraces::checkpoint(_interval, ¬if);
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class PerfEvents : public CpuEngine {
|
||||
const char* title();
|
||||
const char* units();
|
||||
|
||||
static int walk(int tid, void* ucontext, const void** callchain, int max_depth, StackContext* java_ctx);
|
||||
static int walk(int tid, void* ucontext, const void** callchain, int max_depth, u64* cpu);
|
||||
static void resetBuffer(int tid);
|
||||
|
||||
static bool supported();
|
||||
@@ -62,7 +62,7 @@ class PerfEvents : public CpuEngine {
|
||||
return Error("PerfEvents are not supported on this platform");
|
||||
}
|
||||
|
||||
static int walk(int tid, void* ucontext, const void** callchain, int max_depth, StackContext* java_ctx) {
|
||||
static int walk(int tid, void* ucontext, const void** callchain, int max_depth, u64* cpu) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -784,8 +784,8 @@ void PerfEvents::signalHandlerJ9(int signo, siginfo_t* siginfo, void* ucontext)
|
||||
if (_enabled) {
|
||||
u64 counter = readCounter(siginfo, ucontext);
|
||||
J9StackTraceNotification notif;
|
||||
StackContext java_ctx;
|
||||
notif.num_frames = _cstack == CSTACK_NO ? 0 : walk(OS::threadId(), ucontext, notif.addr, MAX_J9_NATIVE_FRAMES, &java_ctx);
|
||||
u64 cpu = 0;
|
||||
notif.num_frames = _cstack == CSTACK_NO ? 0 : walk(OS::threadId(), ucontext, notif.addr, MAX_J9_NATIVE_FRAMES, &cpu);
|
||||
J9StackTraces::checkpoint(counter, ¬if);
|
||||
} else {
|
||||
resetBuffer(OS::threadId());
|
||||
@@ -896,7 +896,7 @@ void PerfEvents::stop() {
|
||||
J9StackTraces::stop();
|
||||
}
|
||||
|
||||
int PerfEvents::walk(int tid, void* ucontext, const void** callchain, int max_depth, StackContext* java_ctx) {
|
||||
int PerfEvents::walk(int tid, void* ucontext, const void** callchain, int max_depth, u64* cpu) {
|
||||
PerfEvent* event = &_events[tid];
|
||||
if (!event->tryLock()) {
|
||||
return 0; // the event is being destroyed
|
||||
@@ -917,7 +917,7 @@ int PerfEvents::walk(int tid, void* ucontext, const void** callchain, int max_de
|
||||
|
||||
if (hdr->type == PERF_RECORD_SAMPLE) {
|
||||
if (_record_cpu) {
|
||||
java_ctx->cpu = ring.next();
|
||||
*cpu = ring.next();
|
||||
}
|
||||
|
||||
u64 nr = ring.next();
|
||||
@@ -927,7 +927,6 @@ int PerfEvents::walk(int tid, void* ucontext, const void** callchain, int max_de
|
||||
const void* iptr = (const void*)ip;
|
||||
if (CodeHeap::contains(iptr) || depth >= max_depth) {
|
||||
// Stop at the first Java frame
|
||||
java_ctx->pc = iptr;
|
||||
goto stack_complete;
|
||||
}
|
||||
callchain[depth++] = iptr;
|
||||
@@ -946,9 +945,9 @@ stack_complete:
|
||||
event->unlock();
|
||||
|
||||
if (_cstack == CSTACK_FP) {
|
||||
depth += StackWalker::walkFP(ucontext, callchain + depth, max_depth - depth, java_ctx);
|
||||
depth += StackWalker::walkFP(ucontext, callchain + depth, max_depth - depth);
|
||||
} else if (_cstack == CSTACK_DWARF) {
|
||||
depth += StackWalker::walkDwarf(ucontext, callchain + depth, max_depth - depth, java_ctx);
|
||||
depth += StackWalker::walkDwarf(ucontext, callchain + depth, max_depth - depth);
|
||||
}
|
||||
|
||||
return depth;
|
||||
|
||||
@@ -284,19 +284,19 @@ CodeBlob* Profiler::findRuntimeStub(const void* address) {
|
||||
return _runtime_stubs.findBlobByAddress(address);
|
||||
}
|
||||
|
||||
int Profiler::getNativeTrace(void* ucontext, ASGCT_CallFrame* frames, EventType event_type, int tid, StackContext* java_ctx) {
|
||||
int Profiler::getNativeTrace(void* ucontext, ASGCT_CallFrame* frames, EventType event_type, int tid, u64* cpu) {
|
||||
const void* callchain[MAX_NATIVE_FRAMES];
|
||||
int native_frames;
|
||||
|
||||
// Use PerfEvents stack walker for execution samples, or basic stack walker for other events
|
||||
if (event_type == PERF_SAMPLE) {
|
||||
native_frames = PerfEvents::walk(tid, ucontext, callchain, MAX_NATIVE_FRAMES, java_ctx);
|
||||
native_frames = PerfEvents::walk(tid, ucontext, callchain, MAX_NATIVE_FRAMES, cpu);
|
||||
} else if (_cstack == CSTACK_VM) {
|
||||
return 0;
|
||||
} else if (_cstack == CSTACK_DWARF) {
|
||||
native_frames = StackWalker::walkDwarf(ucontext, callchain, MAX_NATIVE_FRAMES, java_ctx);
|
||||
native_frames = StackWalker::walkDwarf(ucontext, callchain, MAX_NATIVE_FRAMES);
|
||||
} else {
|
||||
native_frames = StackWalker::walkFP(ucontext, callchain, MAX_NATIVE_FRAMES, java_ctx);
|
||||
native_frames = StackWalker::walkFP(ucontext, callchain, MAX_NATIVE_FRAMES);
|
||||
}
|
||||
|
||||
return convertNativeTrace(native_frames, callchain, frames, event_type);
|
||||
@@ -331,7 +331,7 @@ int Profiler::convertNativeTrace(int native_frames, const void** callchain, ASGC
|
||||
return depth;
|
||||
}
|
||||
|
||||
int Profiler::getJavaTraceAsync(void* ucontext, ASGCT_CallFrame* frames, int max_depth, StackContext* java_ctx) {
|
||||
int Profiler::getJavaTraceAsync(void* ucontext, ASGCT_CallFrame* frames, int max_depth) {
|
||||
// Workaround for JDK-8132510: it's not safe to call GetEnv() inside a signal handler
|
||||
// since JDK 9, so we do it only for threads already registered in ThreadLocalStorage
|
||||
VMThread* vm_thread = VMThread::current();
|
||||
@@ -417,13 +417,13 @@ u64 Profiler::recordSample(void* ucontext, u64 counter, EventType event_type, Ev
|
||||
}
|
||||
}
|
||||
|
||||
StackContext java_ctx = {0};
|
||||
u64 cpu = 0;
|
||||
if (hasNativeStack(event_type)) {
|
||||
if (_features.pc_addr && event_type <= WALL_CLOCK_SAMPLE) {
|
||||
num_frames += makeFrame(frames + num_frames, BCI_ADDRESS, StackFrame(ucontext).pc());
|
||||
}
|
||||
if (_cstack != CSTACK_NO) {
|
||||
num_frames += getNativeTrace(ucontext, frames + num_frames, event_type, tid, &java_ctx);
|
||||
num_frames += getNativeTrace(ucontext, frames + num_frames, event_type, tid, &cpu);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -433,14 +433,14 @@ u64 Profiler::recordSample(void* ucontext, u64 counter, EventType event_type, Ev
|
||||
if (_cstack == CSTACK_VM) {
|
||||
num_frames += StackWalker::walkVM(ucontext, frames + num_frames, _max_stack_depth, lock_index, _features, event_type);
|
||||
} else {
|
||||
num_frames += getJavaTraceAsync(ucontext, frames + num_frames, _max_stack_depth, &java_ctx);
|
||||
num_frames += getJavaTraceAsync(ucontext, frames + num_frames, _max_stack_depth);
|
||||
}
|
||||
} else if (event_type >= ALLOC_SAMPLE && event_type <= ALLOC_OUTSIDE_TLAB && _alloc_engine == &alloc_tracer) {
|
||||
if (VMStructs::hasStackStructs()) {
|
||||
StackWalkFeatures no_features{};
|
||||
num_frames += StackWalker::walkVM(ucontext, frames + num_frames, _max_stack_depth, lock_index, no_features, event_type);
|
||||
} else {
|
||||
num_frames += getJavaTraceAsync(ucontext, frames + num_frames, _max_stack_depth, &java_ctx);
|
||||
num_frames += getJavaTraceAsync(ucontext, frames + num_frames, _max_stack_depth);
|
||||
}
|
||||
} else {
|
||||
// Lock events and instrumentation events can safely call synchronous JVM TI stack walker.
|
||||
@@ -460,7 +460,7 @@ u64 Profiler::recordSample(void* ucontext, u64 counter, EventType event_type, Ev
|
||||
num_frames += makeFrame(frames + num_frames, BCI_ERROR, OS::schedPolicy(0));
|
||||
}
|
||||
if (_add_cpu_frame && event_type == PERF_SAMPLE) {
|
||||
num_frames += makeFrame(frames + num_frames, BCI_CPU, java_ctx.cpu | 0x8000);
|
||||
num_frames += makeFrame(frames + num_frames, BCI_CPU, cpu | 0x8000);
|
||||
}
|
||||
|
||||
if (stack_walk_begin != 0) {
|
||||
|
||||
@@ -110,8 +110,8 @@ class Profiler {
|
||||
|
||||
const char* asgctError(int code);
|
||||
u32 getLockIndex(int tid);
|
||||
int getNativeTrace(void* ucontext, ASGCT_CallFrame* frames, EventType event_type, int tid, StackContext* java_ctx);
|
||||
int getJavaTraceAsync(void* ucontext, ASGCT_CallFrame* frames, int max_depth, StackContext* java_ctx);
|
||||
int getNativeTrace(void* ucontext, ASGCT_CallFrame* frames, EventType event_type, int tid, u64* cpu);
|
||||
int getJavaTraceAsync(void* ucontext, ASGCT_CallFrame* frames, int max_depth);
|
||||
int getJavaTraceJvmti(jvmtiFrameInfo* jvmti_frames, ASGCT_CallFrame* frames, int start_depth, int max_depth);
|
||||
void setThreadInfo(int tid, const char* name, jlong java_thread_id);
|
||||
void updateThreadName(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread);
|
||||
|
||||
@@ -62,7 +62,7 @@ static jmethodID getMethodId(VMMethod* method) {
|
||||
}
|
||||
|
||||
|
||||
int StackWalker::walkFP(void* ucontext, const void** callchain, int max_depth, StackContext* java_ctx) {
|
||||
int StackWalker::walkFP(void* ucontext, const void** callchain, int max_depth) {
|
||||
const void* pc;
|
||||
uintptr_t fp;
|
||||
uintptr_t sp;
|
||||
@@ -84,7 +84,6 @@ 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) && !(depth == 0 && frame.unwindAtomicStub(pc))) {
|
||||
java_ctx->set(pc, sp, fp);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -112,7 +111,7 @@ int StackWalker::walkFP(void* ucontext, const void** callchain, int max_depth, S
|
||||
return depth;
|
||||
}
|
||||
|
||||
int StackWalker::walkDwarf(void* ucontext, const void** callchain, int max_depth, StackContext* java_ctx) {
|
||||
int StackWalker::walkDwarf(void* ucontext, const void** callchain, int max_depth) {
|
||||
const void* pc;
|
||||
uintptr_t fp;
|
||||
uintptr_t sp;
|
||||
@@ -135,9 +134,6 @@ 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) && !(depth == 0 && frame.unwindAtomicStub(pc))) {
|
||||
// Don't dereference pc as it may point to unreadable memory
|
||||
// frame.adjustSP(page_start, pc, sp);
|
||||
java_ctx->set(pc, sp, fp);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,23 +14,10 @@
|
||||
|
||||
class JavaFrameAnchor;
|
||||
|
||||
struct StackContext {
|
||||
const void* pc;
|
||||
uintptr_t sp;
|
||||
uintptr_t fp;
|
||||
u64 cpu;
|
||||
|
||||
void set(const void* pc, uintptr_t sp, uintptr_t fp) {
|
||||
this->pc = pc;
|
||||
this->sp = sp;
|
||||
this->fp = fp;
|
||||
}
|
||||
};
|
||||
|
||||
class StackWalker {
|
||||
public:
|
||||
static int walkFP(void* ucontext, const void** callchain, int max_depth, StackContext* java_ctx);
|
||||
static int walkDwarf(void* ucontext, const void** callchain, int max_depth, StackContext* java_ctx);
|
||||
static int walkFP(void* ucontext, const void** callchain, int max_depth);
|
||||
static int walkDwarf(void* ucontext, const void** callchain, int max_depth);
|
||||
static int walkVM(void* ucontext, ASGCT_CallFrame* frames, int max_depth, int lock_index,
|
||||
StackWalkFeatures features, EventType event_type);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user