-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathvmEntry.h
More file actions
194 lines (153 loc) · 5.73 KB
/
vmEntry.h
File metadata and controls
194 lines (153 loc) · 5.73 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
* Copyright The async-profiler authors
* Copyright 2021, 2025 Datadog, Inc
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _VMENTRY_H
#define _VMENTRY_H
#include <jvmti.h>
#include "arch_dd.h"
#include "arch_dd.h"
#include "codeCache.h"
#include "frame.h"
#ifdef __clang__
#define DLLEXPORT __attribute__((visibility("default")))
#else
#define DLLEXPORT __attribute__((visibility("default"), externally_visible))
#endif
// Denotes ASGCT_CallFrame where method_id has special meaning (not jmethodID)
enum ASGCT_CallFrameType {
BCI_CPU = 0, // cpu time
BCI_WALL = -10, // wall time
BCI_NATIVE_FRAME = -11, // native function name (char*)
BCI_ALLOC = -12, // name of the allocated class
BCI_ALLOC_OUTSIDE_TLAB = -13, // name of the class allocated outside TLAB
BCI_LIVENESS = -14, // name of the allocated class
BCI_LOCK = -15, // class name of the locked object
BCI_PARK = -16, // class name of the park() blocker
BCI_THREAD_ID = -17, // method_id designates a thread
BCI_ERROR = -18, // method_id is an error string
};
// See hotspot/src/share/vm/prims/forte.cpp
enum ASGCT_Failure {
ticks_no_Java_frame = 0,
ticks_no_class_load = -1,
ticks_GC_active = -2,
ticks_unknown_not_Java = -3,
ticks_not_walkable_not_Java = -4,
ticks_unknown_Java = -5,
ticks_not_walkable_Java = -6,
ticks_unknown_state = -7,
ticks_thread_exit = -8,
ticks_deopt = -9,
ticks_safepoint = -10,
ticks_skipped = -11,
ASGCT_FAILURE_TYPES = 12
};
typedef struct {
jint bci;
LP64_ONLY(jint padding;)
jmethodID method_id;
} ASGCT_CallFrame;
typedef struct {
JNIEnv *env;
jint num_frames;
ASGCT_CallFrame *frames;
} ASGCT_CallTrace;
typedef void (*AsyncGetCallTrace)(ASGCT_CallTrace *, jint, void *);
typedef struct {
void *unused[38];
jstring(JNICALL *ExecuteDiagnosticCommand)(JNIEnv *, jstring);
} VMManagement;
typedef VMManagement *(*JVM_GetManagement)(jint);
typedef struct {
void *unused1[86];
jvmtiError(JNICALL *RedefineClasses)(jvmtiEnv *, jint,
const jvmtiClassDefinition *);
void *unused2[64];
jvmtiError(JNICALL *RetransformClasses)(jvmtiEnv *, jint, const jclass *);
} JVMTIFunctions;
typedef struct {
int major;
int update;
} JavaFullVersion;
class JavaVersionAccess {
public:
static JavaFullVersion get_java_version(char* prop_value);
static int get_hotspot_version(char* prop_value);
};
class VM {
private:
static JavaVM *_vm;
static jvmtiEnv *_jvmti;
static int _java_version;
static int _java_update_version;
static int _hotspot_version;
static bool _openj9;
static bool _hotspot;
static bool _zing;
static bool _can_sample_objects;
static bool _can_intercept_binding;
static bool _is_adaptive_gc_boundary_flag_set;
static jvmtiError(JNICALL *_orig_RedefineClasses)(
jvmtiEnv *, jint, const jvmtiClassDefinition *);
static jvmtiError(JNICALL *_orig_RetransformClasses)(jvmtiEnv *, jint,
const jclass *classes);
static void ready(jvmtiEnv *jvmti, JNIEnv *jni);
static void applyPatch(char *func, const char *patch, const char *end_patch);
static void *getLibraryHandle(const char *name);
static void loadMethodIDs(jvmtiEnv *jvmti, JNIEnv *jni, jclass klass);
static void loadAllMethodIDs(jvmtiEnv *jvmti, JNIEnv *jni);
static bool initShared(JavaVM *vm);
static CodeCache* openJvmLibrary();
public:
static void *_libjvm;
static void *_libjava;
static AsyncGetCallTrace _asyncGetCallTrace;
static JVM_GetManagement _getManagement;
static bool initLibrary(JavaVM *vm);
static bool initProfilerBridge(JavaVM *vm, bool attach);
static jvmtiEnv *jvmti() { return _jvmti; }
static bool loaded() { return _jvmti != nullptr; }
static JNIEnv *jni() {
JNIEnv *jni;
return _vm->GetEnv((void **)&jni, JNI_VERSION_1_6) == 0 ? jni : NULL;
}
static JNIEnv *attachThread(const char *name) {
JNIEnv *jni;
JavaVMAttachArgs args = {JNI_VERSION_1_6, (char *)name, NULL};
return _vm->AttachCurrentThreadAsDaemon((void **)&jni, &args) == 0 ? jni
: NULL;
}
static void detachThread() { _vm->DetachCurrentThread(); }
static VMManagement *management() {
return _getManagement != NULL ? _getManagement(0x20030000) : NULL;
}
static int java_version() { return _java_version; }
static int hotspot_version() { return isHotspot() ? _hotspot_version : -1; }
static int java_update_version() { return _java_update_version; }
static bool isOpenJ9() { return _openj9; }
static bool isHotspot() { return _hotspot; }
static bool canSampleObjects() { return _can_sample_objects; }
static bool isZing() { return _zing; }
static bool isUseAdaptiveGCBoundarySet() {
return _is_adaptive_gc_boundary_flag_set;
}
static void JNICALL VMInit(jvmtiEnv *jvmti, JNIEnv *jni, jthread thread);
static void JNICALL VMDeath(jvmtiEnv *jvmti, JNIEnv *jni);
static void JNICALL ClassLoad(jvmtiEnv *jvmti, JNIEnv *jni, jthread thread,
jclass klass) {
// Needed only for AsyncGetCallTrace support
}
static void JNICALL ClassPrepare(jvmtiEnv *jvmti, JNIEnv *jni, jthread thread,
jclass klass) {
loadMethodIDs(jvmti, jni, klass);
}
static jvmtiError JNICALL
RedefineClassesHook(jvmtiEnv *jvmti, jint class_count,
const jvmtiClassDefinition *class_definitions);
static jvmtiError JNICALL RetransformClassesHook(jvmtiEnv *jvmti,
jint class_count,
const jclass *classes);
};
#endif // _VMENTRY_H