-
Notifications
You must be signed in to change notification settings - Fork 0
/
jvmtiHelper.cpp
57 lines (44 loc) · 1.14 KB
/
jvmtiHelper.cpp
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
#include "stdafx.h"
#include <stdlib.h>
#include "jvmtiHelper.h"
void fatal_error(const char * format, ...) {
va_list ap;
va_start(ap, format);
(void) vfprintf(stderr, format, ap);
(void) fflush(stderr);
va_end(ap);
exit(3);
}
void check_jvmti_error(jvmtiEnv *jvmti, jvmtiError errnum,
const char *str) {
if (errnum != JVMTI_ERROR_NONE) {
char *errnum_str;
errnum_str = NULL;
jvmti->GetErrorName(errnum, &errnum_str);
fatal_error("ERROR: JVMTI: %d(%s): %s\n", errnum,
(errnum_str == NULL ? "Unknown" : errnum_str),
(str == NULL ? "" : str));
}
}
void describe(jvmtiEnv *jvmti, jvmtiError err) {
jvmtiError err0;
char *descr;
err0 = jvmti->GetErrorName(err, &descr);
if (err0 == JVMTI_ERROR_NONE) {
printf(descr);
} else {
printf("error [%d]", err);
}
}
/* Enter raw monitor */
void menter(jvmtiEnv *jvmti, jrawMonitorID rmon) {
jvmtiError err;
err = jvmti->RawMonitorEnter(rmon);
check_jvmti_error(jvmti, err, "raw monitor enter");
}
/* Exit raw monitor */
void mexit(jvmtiEnv *jvmti, jrawMonitorID rmon) {
jvmtiError err;
err = jvmti->RawMonitorExit(rmon);
check_jvmti_error(jvmti, err, "raw monitor exit");
}