Skip to content

Commit 71ad47a

Browse files
More AGCT cleanup after removal of recovery tricks (async-profiler#1683)
1 parent 0023021 commit 71ad47a

File tree

7 files changed

+26
-45
lines changed

7 files changed

+26
-45
lines changed

src/cpuEngine.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,8 @@ void CpuEngine::signalHandlerJ9(int signo, siginfo_t* siginfo, void* ucontext) {
124124
if (!_enabled) return;
125125

126126
J9StackTraceNotification notif;
127-
StackContext java_ctx;
128127
notif.num_frames = _cstack == CSTACK_NO ? 0 : _cstack == CSTACK_DWARF
129-
? StackWalker::walkDwarf(ucontext, notif.addr, MAX_J9_NATIVE_FRAMES, &java_ctx)
130-
: StackWalker::walkFP(ucontext, notif.addr, MAX_J9_NATIVE_FRAMES, &java_ctx);
128+
? StackWalker::walkDwarf(ucontext, notif.addr, MAX_J9_NATIVE_FRAMES)
129+
: StackWalker::walkFP(ucontext, notif.addr, MAX_J9_NATIVE_FRAMES);
131130
J9StackTraces::checkpoint(_interval, &notif);
132131
}

src/perfEvents.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class PerfEvents : public CpuEngine {
4545
const char* title();
4646
const char* units();
4747

48-
static int walk(int tid, void* ucontext, const void** callchain, int max_depth, StackContext* java_ctx);
48+
static int walk(int tid, void* ucontext, const void** callchain, int max_depth, u64* cpu);
4949
static void resetBuffer(int tid);
5050

5151
static bool supported();
@@ -62,7 +62,7 @@ class PerfEvents : public CpuEngine {
6262
return Error("PerfEvents are not supported on this platform");
6363
}
6464

65-
static int walk(int tid, void* ucontext, const void** callchain, int max_depth, StackContext* java_ctx) {
65+
static int walk(int tid, void* ucontext, const void** callchain, int max_depth, u64* cpu) {
6666
return 0;
6767
}
6868

src/perfEvents_linux.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,8 @@ void PerfEvents::signalHandlerJ9(int signo, siginfo_t* siginfo, void* ucontext)
784784
if (_enabled) {
785785
u64 counter = readCounter(siginfo, ucontext);
786786
J9StackTraceNotification notif;
787-
StackContext java_ctx;
788-
notif.num_frames = _cstack == CSTACK_NO ? 0 : walk(OS::threadId(), ucontext, notif.addr, MAX_J9_NATIVE_FRAMES, &java_ctx);
787+
u64 cpu = 0;
788+
notif.num_frames = _cstack == CSTACK_NO ? 0 : walk(OS::threadId(), ucontext, notif.addr, MAX_J9_NATIVE_FRAMES, &cpu);
789789
J9StackTraces::checkpoint(counter, &notif);
790790
} else {
791791
resetBuffer(OS::threadId());
@@ -896,7 +896,7 @@ void PerfEvents::stop() {
896896
J9StackTraces::stop();
897897
}
898898

899-
int PerfEvents::walk(int tid, void* ucontext, const void** callchain, int max_depth, StackContext* java_ctx) {
899+
int PerfEvents::walk(int tid, void* ucontext, const void** callchain, int max_depth, u64* cpu) {
900900
PerfEvent* event = &_events[tid];
901901
if (!event->tryLock()) {
902902
return 0; // the event is being destroyed
@@ -917,7 +917,7 @@ int PerfEvents::walk(int tid, void* ucontext, const void** callchain, int max_de
917917

918918
if (hdr->type == PERF_RECORD_SAMPLE) {
919919
if (_record_cpu) {
920-
java_ctx->cpu = ring.next();
920+
*cpu = ring.next();
921921
}
922922

923923
u64 nr = ring.next();
@@ -927,7 +927,6 @@ int PerfEvents::walk(int tid, void* ucontext, const void** callchain, int max_de
927927
const void* iptr = (const void*)ip;
928928
if (CodeHeap::contains(iptr) || depth >= max_depth) {
929929
// Stop at the first Java frame
930-
java_ctx->pc = iptr;
931930
goto stack_complete;
932931
}
933932
callchain[depth++] = iptr;
@@ -946,9 +945,9 @@ int PerfEvents::walk(int tid, void* ucontext, const void** callchain, int max_de
946945
event->unlock();
947946

948947
if (_cstack == CSTACK_FP) {
949-
depth += StackWalker::walkFP(ucontext, callchain + depth, max_depth - depth, java_ctx);
948+
depth += StackWalker::walkFP(ucontext, callchain + depth, max_depth - depth);
950949
} else if (_cstack == CSTACK_DWARF) {
951-
depth += StackWalker::walkDwarf(ucontext, callchain + depth, max_depth - depth, java_ctx);
950+
depth += StackWalker::walkDwarf(ucontext, callchain + depth, max_depth - depth);
952951
}
953952

954953
return depth;

src/profiler.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -284,19 +284,19 @@ CodeBlob* Profiler::findRuntimeStub(const void* address) {
284284
return _runtime_stubs.findBlobByAddress(address);
285285
}
286286

287-
int Profiler::getNativeTrace(void* ucontext, ASGCT_CallFrame* frames, EventType event_type, int tid, StackContext* java_ctx) {
287+
int Profiler::getNativeTrace(void* ucontext, ASGCT_CallFrame* frames, EventType event_type, int tid, u64* cpu) {
288288
const void* callchain[MAX_NATIVE_FRAMES];
289289
int native_frames;
290290

291291
// Use PerfEvents stack walker for execution samples, or basic stack walker for other events
292292
if (event_type == PERF_SAMPLE) {
293-
native_frames = PerfEvents::walk(tid, ucontext, callchain, MAX_NATIVE_FRAMES, java_ctx);
293+
native_frames = PerfEvents::walk(tid, ucontext, callchain, MAX_NATIVE_FRAMES, cpu);
294294
} else if (_cstack == CSTACK_VM) {
295295
return 0;
296296
} else if (_cstack == CSTACK_DWARF) {
297-
native_frames = StackWalker::walkDwarf(ucontext, callchain, MAX_NATIVE_FRAMES, java_ctx);
297+
native_frames = StackWalker::walkDwarf(ucontext, callchain, MAX_NATIVE_FRAMES);
298298
} else {
299-
native_frames = StackWalker::walkFP(ucontext, callchain, MAX_NATIVE_FRAMES, java_ctx);
299+
native_frames = StackWalker::walkFP(ucontext, callchain, MAX_NATIVE_FRAMES);
300300
}
301301

302302
return convertNativeTrace(native_frames, callchain, frames, event_type);
@@ -331,7 +331,7 @@ int Profiler::convertNativeTrace(int native_frames, const void** callchain, ASGC
331331
return depth;
332332
}
333333

334-
int Profiler::getJavaTraceAsync(void* ucontext, ASGCT_CallFrame* frames, int max_depth, StackContext* java_ctx) {
334+
int Profiler::getJavaTraceAsync(void* ucontext, ASGCT_CallFrame* frames, int max_depth) {
335335
// Workaround for JDK-8132510: it's not safe to call GetEnv() inside a signal handler
336336
// since JDK 9, so we do it only for threads already registered in ThreadLocalStorage
337337
VMThread* vm_thread = VMThread::current();
@@ -417,13 +417,13 @@ u64 Profiler::recordSample(void* ucontext, u64 counter, EventType event_type, Ev
417417
}
418418
}
419419

420-
StackContext java_ctx = {0};
420+
u64 cpu = 0;
421421
if (hasNativeStack(event_type)) {
422422
if (_features.pc_addr && event_type <= WALL_CLOCK_SAMPLE) {
423423
num_frames += makeFrame(frames + num_frames, BCI_ADDRESS, StackFrame(ucontext).pc());
424424
}
425425
if (_cstack != CSTACK_NO) {
426-
num_frames += getNativeTrace(ucontext, frames + num_frames, event_type, tid, &java_ctx);
426+
num_frames += getNativeTrace(ucontext, frames + num_frames, event_type, tid, &cpu);
427427
}
428428
}
429429

@@ -433,14 +433,14 @@ u64 Profiler::recordSample(void* ucontext, u64 counter, EventType event_type, Ev
433433
if (_cstack == CSTACK_VM) {
434434
num_frames += StackWalker::walkVM(ucontext, frames + num_frames, _max_stack_depth, lock_index, _features, event_type);
435435
} else {
436-
num_frames += getJavaTraceAsync(ucontext, frames + num_frames, _max_stack_depth, &java_ctx);
436+
num_frames += getJavaTraceAsync(ucontext, frames + num_frames, _max_stack_depth);
437437
}
438438
} else if (event_type >= ALLOC_SAMPLE && event_type <= ALLOC_OUTSIDE_TLAB && _alloc_engine == &alloc_tracer) {
439439
if (VMStructs::hasStackStructs()) {
440440
StackWalkFeatures no_features{};
441441
num_frames += StackWalker::walkVM(ucontext, frames + num_frames, _max_stack_depth, lock_index, no_features, event_type);
442442
} else {
443-
num_frames += getJavaTraceAsync(ucontext, frames + num_frames, _max_stack_depth, &java_ctx);
443+
num_frames += getJavaTraceAsync(ucontext, frames + num_frames, _max_stack_depth);
444444
}
445445
} else {
446446
// 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
460460
num_frames += makeFrame(frames + num_frames, BCI_ERROR, OS::schedPolicy(0));
461461
}
462462
if (_add_cpu_frame && event_type == PERF_SAMPLE) {
463-
num_frames += makeFrame(frames + num_frames, BCI_CPU, java_ctx.cpu | 0x8000);
463+
num_frames += makeFrame(frames + num_frames, BCI_CPU, cpu | 0x8000);
464464
}
465465

466466
if (stack_walk_begin != 0) {

src/profiler.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ class Profiler {
110110

111111
const char* asgctError(int code);
112112
u32 getLockIndex(int tid);
113-
int getNativeTrace(void* ucontext, ASGCT_CallFrame* frames, EventType event_type, int tid, StackContext* java_ctx);
114-
int getJavaTraceAsync(void* ucontext, ASGCT_CallFrame* frames, int max_depth, StackContext* java_ctx);
113+
int getNativeTrace(void* ucontext, ASGCT_CallFrame* frames, EventType event_type, int tid, u64* cpu);
114+
int getJavaTraceAsync(void* ucontext, ASGCT_CallFrame* frames, int max_depth);
115115
int getJavaTraceJvmti(jvmtiFrameInfo* jvmti_frames, ASGCT_CallFrame* frames, int start_depth, int max_depth);
116116
void setThreadInfo(int tid, const char* name, jlong java_thread_id);
117117
void updateThreadName(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread);

src/stackWalker.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static jmethodID getMethodId(VMMethod* method) {
6262
}
6363

6464

65-
int StackWalker::walkFP(void* ucontext, const void** callchain, int max_depth, StackContext* java_ctx) {
65+
int StackWalker::walkFP(void* ucontext, const void** callchain, int max_depth) {
6666
const void* pc;
6767
uintptr_t fp;
6868
uintptr_t sp;
@@ -84,7 +84,6 @@ int StackWalker::walkFP(void* ucontext, const void** callchain, int max_depth, S
8484
// Walk until the bottom of the stack or until the first Java frame
8585
while (depth < max_depth) {
8686
if (CodeHeap::contains(pc) && !(depth == 0 && frame.unwindAtomicStub(pc))) {
87-
java_ctx->set(pc, sp, fp);
8887
break;
8988
}
9089

@@ -112,7 +111,7 @@ int StackWalker::walkFP(void* ucontext, const void** callchain, int max_depth, S
112111
return depth;
113112
}
114113

115-
int StackWalker::walkDwarf(void* ucontext, const void** callchain, int max_depth, StackContext* java_ctx) {
114+
int StackWalker::walkDwarf(void* ucontext, const void** callchain, int max_depth) {
116115
const void* pc;
117116
uintptr_t fp;
118117
uintptr_t sp;
@@ -135,9 +134,6 @@ int StackWalker::walkDwarf(void* ucontext, const void** callchain, int max_depth
135134
// Walk until the bottom of the stack or until the first Java frame
136135
while (depth < max_depth) {
137136
if (CodeHeap::contains(pc) && !(depth == 0 && frame.unwindAtomicStub(pc))) {
138-
// Don't dereference pc as it may point to unreadable memory
139-
// frame.adjustSP(page_start, pc, sp);
140-
java_ctx->set(pc, sp, fp);
141137
break;
142138
}
143139

src/stackWalker.h

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,10 @@
1414

1515
class JavaFrameAnchor;
1616

17-
struct StackContext {
18-
const void* pc;
19-
uintptr_t sp;
20-
uintptr_t fp;
21-
u64 cpu;
22-
23-
void set(const void* pc, uintptr_t sp, uintptr_t fp) {
24-
this->pc = pc;
25-
this->sp = sp;
26-
this->fp = fp;
27-
}
28-
};
29-
3017
class StackWalker {
3118
public:
32-
static int walkFP(void* ucontext, const void** callchain, int max_depth, StackContext* java_ctx);
33-
static int walkDwarf(void* ucontext, const void** callchain, int max_depth, StackContext* java_ctx);
19+
static int walkFP(void* ucontext, const void** callchain, int max_depth);
20+
static int walkDwarf(void* ucontext, const void** callchain, int max_depth);
3421
static int walkVM(void* ucontext, ASGCT_CallFrame* frames, int max_depth, int lock_index,
3522
StackWalkFeatures features, EventType event_type);
3623

0 commit comments

Comments
 (0)