Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/jvmti/CanGenerateAllClassHook/libCanGenerateAllClassHook.c
41155 views
1
/*
2
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
#include <stdio.h>
25
#include <string.h>
26
#include "jvmti.h"
27
#include "jni.h"
28
29
#ifdef __cplusplus
30
extern "C" {
31
#endif
32
33
#ifndef JNI_ENV_ARG
34
35
#ifdef __cplusplus
36
#define JNI_ENV_ARG(x, y) y
37
#define JNI_ENV_PTR(x) x
38
#else
39
#define JNI_ENV_ARG(x,y) x, y
40
#define JNI_ENV_PTR(x) (*x)
41
#endif
42
43
#endif
44
45
46
static jvmtiEnv *jvmti = NULL;
47
48
typedef enum {
49
Yes = 1,
50
No = 0,
51
Error = -1
52
} IsAvail;
53
54
static IsAvail onLoadIsAvail = Error;
55
56
void reportError(const char *msg, int err) {
57
printf("%s, error: %d\n", msg, err);
58
}
59
60
static IsAvail isClassHookAvail() {
61
IsAvail result = Error;
62
do {
63
jvmtiCapabilities caps;
64
jvmtiPhase phase;
65
jvmtiError err;
66
67
if (jvmti == NULL) {
68
reportError("jvmti is NULL", -1);
69
break;
70
}
71
72
err = (*jvmti)->GetPhase(jvmti, &phase);
73
if (err != JVMTI_ERROR_NONE) {
74
reportError("GetPhase failed", err);
75
break;
76
}
77
78
err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps);
79
if (err != JVMTI_ERROR_NONE) {
80
reportError("GetPotentialCapabilities failed", err);
81
break;
82
}
83
84
result = caps.can_generate_all_class_hook_events ? Yes : No;
85
86
printf("isClassHookAvail: phase=%d, value=%d\n", phase, result);
87
} while (0);
88
return result;
89
}
90
91
92
JNIEXPORT jint JNICALL
93
Agent_OnLoad(JavaVM *jvm, char *options, void *reserved)
94
{
95
jint res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_9);
96
if (res != JNI_OK || jvmti == NULL) {
97
reportError("GetEnv failed", res);
98
return JNI_ERR;
99
}
100
101
// check and save can_generate_all_class_hook_events for ONLOAD phase
102
onLoadIsAvail = isClassHookAvail();
103
104
return JNI_OK;
105
}
106
107
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) {
108
return JNI_VERSION_9;
109
}
110
111
112
JNIEXPORT jint JNICALL
113
Java_CanGenerateAllClassHook_getClassHookAvail(JNIEnv *env, jclass cls) {
114
return isClassHookAvail();
115
}
116
117
JNIEXPORT jint JNICALL
118
Java_CanGenerateAllClassHook_getOnLoadClassHookAvail(JNIEnv *env, jclass cls) {
119
return onLoadIsAvail;
120
}
121
122
123
#ifdef __cplusplus
124
}
125
#endif
126
127
128