-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathjvmSupport.cpp
More file actions
56 lines (46 loc) · 1.51 KB
/
jvmSupport.cpp
File metadata and controls
56 lines (46 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Copyright 2026, Datadog, Inc.
* SPDX-License-Identifier: Apache-2.0
*/
#include "jvmSupport.h"
#include "asyncSampleMutex.h"
#include "frames.h"
#include "os.h"
#include "profiler.h"
#include "thread.h"
#include "hotspot/hotspotSupport.h"
#include <jni.h>
int JVMSupport::walkJavaStack(StackWalkRequest& request) {
if (VM::isHotspot()) {
return HotspotSupport::walkJavaStack(request);
} else if (VM::isOpenJ9() || VM::isZing()) {
assert(request.event_type == BCI_CPU || request.event_type == BCI_WALL);
return asyncGetCallTrace(request.frames, request.max_depth, request.ucontext);
}
assert(false && "Unsupported JVM");
return 0;
}
int JVMSupport::asyncGetCallTrace(ASGCT_CallFrame *frames, int max_depth, void* ucontext) {
JNIEnv *jni = VM::jni();
if (jni == nullptr) {
return 0;
}
AsyncSampleMutex mutex(ProfiledThread::currentSignalSafe());
if (!mutex.acquired()) {
return 0;
}
JitWriteProtection jit(false);
// AsyncGetCallTrace writes to ASGCT_CallFrame array
ASGCT_CallTrace trace = {jni, 0, frames};
VM::_asyncGetCallTrace(&trace, max_depth, ucontext);
if (trace.num_frames > 0) {
return trace.num_frames;
}
const char* err_string = Profiler::asgctError(trace.num_frames);
if (err_string == NULL) {
// No Java stack, because thread is not in Java context
return 0;
}
Profiler::instance()->incFailure(-trace.num_frames);
return makeFrame(frames, BCI_ERROR, err_string);
}