Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/FramePop/framepop001/framepop001.cpp
40955 views
1
/*
2
* Copyright (c) 2003, 2020, 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 <inttypes.h>
27
#include "jvmti.h"
28
#include "agent_common.h"
29
#include "JVMTITools.h"
30
31
extern "C" {
32
33
34
#define PASSED 0
35
#define STATUS_FAILED 2
36
37
typedef struct {
38
const char *cls_sig;
39
const char *name;
40
const char *sig;
41
jlocation loc;
42
} pop_info;
43
44
static jvmtiEnv *jvmti = NULL;
45
static jvmtiCapabilities caps;
46
static jvmtiEventCallbacks callbacks;
47
static jint result = PASSED;
48
static jboolean printdump = JNI_FALSE;
49
static size_t eventsExpected = 0;
50
static size_t eventsCount = 0;
51
static pop_info pops[] = {
52
{ "Lnsk/jvmti/FramePop/framepop001;", "chain", "()V", 0 },
53
{ "Lnsk/jvmti/FramePop/framepop001a;", "dummy", "()V", 3 },
54
};
55
56
void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env,
57
jthread thr, jmethodID method, jlocation location) {
58
jvmtiError err;
59
60
err = jvmti_env->NotifyFramePop(thr, 0);
61
if (err == JVMTI_ERROR_NONE) {
62
eventsExpected++;
63
} else {
64
printf("(NotifyFramePop#0) unexpected error: %s (%d)\n",
65
TranslateError(err), err);
66
result = STATUS_FAILED;
67
}
68
69
err = jvmti_env->NotifyFramePop(thr, 1);
70
if (err == JVMTI_ERROR_NONE) {
71
eventsExpected++;
72
} else {
73
printf("(NotifyFramePop#1) unexpected error: %s (%d)\n",
74
TranslateError(err), err);
75
result = STATUS_FAILED;
76
}
77
}
78
79
void JNICALL FramePop(jvmtiEnv *jvmti_env, JNIEnv *env,
80
jthread thr, jmethodID method, jboolean wasPopedByException) {
81
jvmtiError err;
82
char *cls_sig, *name, *sig, *generic;
83
jclass cls;
84
jmethodID mid;
85
jlocation loc;
86
87
if (printdump == JNI_TRUE) {
88
printf(">>> retrieving frame pop info ...\n");
89
}
90
err = jvmti_env->GetMethodDeclaringClass(method, &cls);
91
if (err != JVMTI_ERROR_NONE) {
92
printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n",
93
TranslateError(err), err);
94
result = STATUS_FAILED;
95
return;
96
}
97
err = jvmti_env->GetClassSignature(cls, &cls_sig, &generic);
98
if (err != JVMTI_ERROR_NONE) {
99
printf("(GetClassSignature) unexpected error: %s (%d)\n",
100
TranslateError(err), err);
101
result = STATUS_FAILED;
102
return;
103
}
104
err = jvmti_env->GetMethodName(method, &name, &sig, &generic);
105
if (err != JVMTI_ERROR_NONE) {
106
printf("(GetMethodName) unexpected error: %s (%d)\n",
107
TranslateError(err), err);
108
result = STATUS_FAILED;
109
return;
110
}
111
err = jvmti_env->GetFrameLocation(thr, 0, &mid, &loc);
112
if (err != JVMTI_ERROR_NONE) {
113
printf("(GetFrameLocation) unexpected error: %s (%d)\n",
114
TranslateError(err), err);
115
result = STATUS_FAILED;
116
}
117
if (printdump == JNI_TRUE) {
118
printf(">>> class: \"%s\"\n", cls_sig);
119
printf(">>> method: \"%s%s\"\n", name, sig);
120
printf(">>> location: 0x%x%08x\n",
121
(jint)(loc >> 32), (jint)loc);
122
printf(">>> ... done\n");
123
}
124
if (eventsCount < sizeof(pops)/sizeof(pop_info)) {
125
if (cls_sig == NULL ||
126
strcmp(cls_sig, pops[eventsCount].cls_sig) != 0) {
127
printf("(pop#%" PRIuPTR ") wrong class: \"%s\"",
128
eventsCount, cls_sig);
129
printf(", expected: \"%s\"\n", pops[eventsCount].cls_sig);
130
result = STATUS_FAILED;
131
}
132
if (name == NULL ||
133
strcmp(name, pops[eventsCount].name) != 0) {
134
printf("(pop#%" PRIuPTR ") wrong method name: \"%s\"",
135
eventsCount, name);
136
printf(", expected: \"%s\"\n", pops[eventsCount].name);
137
result = STATUS_FAILED;
138
}
139
if (sig == NULL ||
140
strcmp(sig, pops[eventsCount].sig) != 0) {
141
printf("(pop#%" PRIuPTR ") wrong method sig: \"%s\"",
142
eventsCount, sig);
143
printf(", expected: \"%s\"\n", pops[eventsCount].sig);
144
result = STATUS_FAILED;
145
}
146
if (loc != pops[eventsCount].loc) {
147
printf("(pop#%" PRIuPTR ") wrong location: 0x%x%08x",
148
eventsCount, (jint)(loc >> 32), (jint)loc);
149
printf(", expected: 0x%x\n", (jint)pops[eventsCount].loc);
150
result = STATUS_FAILED;
151
}
152
} else {
153
printf("Unexpected frame pop catched:");
154
printf(" class: \"%s\"\n", cls_sig);
155
printf(" method: \"%s%s\"\n", name, sig);
156
printf(" location: 0x%x%08x\n", (jint)(loc >> 32), (jint)loc);
157
result = STATUS_FAILED;
158
}
159
eventsCount++;
160
}
161
162
#ifdef STATIC_BUILD
163
JNIEXPORT jint JNICALL Agent_OnLoad_framepop001(JavaVM *jvm, char *options, void *reserved) {
164
return Agent_Initialize(jvm, options, reserved);
165
}
166
JNIEXPORT jint JNICALL Agent_OnAttach_framepop001(JavaVM *jvm, char *options, void *reserved) {
167
return Agent_Initialize(jvm, options, reserved);
168
}
169
JNIEXPORT jint JNI_OnLoad_framepop001(JavaVM *jvm, char *options, void *reserved) {
170
return JNI_VERSION_1_8;
171
}
172
#endif
173
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
174
jvmtiError err;
175
jint res;
176
177
if (options != NULL && strcmp(options, "printdump") == 0) {
178
printdump = JNI_TRUE;
179
}
180
181
res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);
182
if (res != JNI_OK || jvmti == NULL) {
183
printf("Wrong result of a valid call to GetEnv!\n");
184
return JNI_ERR;
185
}
186
187
err = jvmti->GetPotentialCapabilities(&caps);
188
if (err != JVMTI_ERROR_NONE) {
189
printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n",
190
TranslateError(err), err);
191
return JNI_ERR;
192
}
193
194
err = jvmti->AddCapabilities(&caps);
195
if (err != JVMTI_ERROR_NONE) {
196
printf("(AddCapabilities) unexpected error: %s (%d)\n",
197
TranslateError(err), err);
198
return JNI_ERR;
199
}
200
201
err = jvmti->GetCapabilities(&caps);
202
if (err != JVMTI_ERROR_NONE) {
203
printf("(GetCapabilities) unexpected error: %s (%d)\n",
204
TranslateError(err), err);
205
return JNI_ERR;
206
}
207
208
if (caps.can_generate_frame_pop_events &&
209
caps.can_generate_breakpoint_events) {
210
callbacks.Breakpoint = &Breakpoint;
211
callbacks.FramePop = &FramePop;
212
err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks));
213
if (err != JVMTI_ERROR_NONE) {
214
printf("(SetEventCallbacks) unexpected error: %s (%d)\n",
215
TranslateError(err), err);
216
return JNI_ERR;
217
}
218
} else {
219
printf("Warning: FramePop or Breakpoint event is not implemented\n");
220
}
221
222
return JNI_OK;
223
}
224
225
JNIEXPORT jint JNICALL
226
Java_nsk_jvmti_FramePop_framepop001_check(JNIEnv *env, jclass cls) {
227
jvmtiError err;
228
jclass clz;
229
jmethodID mid;
230
231
if (jvmti == NULL) {
232
printf("JVMTI client was not properly loaded!\n");
233
return STATUS_FAILED;
234
}
235
236
if (!caps.can_generate_frame_pop_events ||
237
!caps.can_generate_breakpoint_events) {
238
return result;
239
}
240
241
mid = env->GetStaticMethodID(cls, "chain", "()V");
242
if (mid == 0) {
243
printf("Cannot find Method ID for method chain\n");
244
return STATUS_FAILED;
245
}
246
err = jvmti->SetBreakpoint(mid, 0);
247
if (err != JVMTI_ERROR_NONE) {
248
printf("Failed to SetBreakpoint: %s (%d)\n",
249
TranslateError(err), err);
250
return STATUS_FAILED;
251
}
252
err = jvmti->SetEventNotificationMode(JVMTI_ENABLE,
253
JVMTI_EVENT_FRAME_POP, NULL);
254
if (err != JVMTI_ERROR_NONE) {
255
printf("Failed to enable JVMTI_EVENT_FRAME_POP event: %s (%d)\n",
256
TranslateError(err), err);
257
result = STATUS_FAILED;
258
}
259
err = jvmti->SetEventNotificationMode(JVMTI_ENABLE,
260
JVMTI_EVENT_BREAKPOINT, NULL);
261
if (err != JVMTI_ERROR_NONE) {
262
printf("Failed to enable BREAKPOINT event: %s (%d)\n",
263
TranslateError(err), err);
264
result = STATUS_FAILED;
265
}
266
267
clz = env->FindClass("nsk/jvmti/FramePop/framepop001a");
268
if (clz == NULL) {
269
printf("Cannot find framepop001a class!\n");
270
result = STATUS_FAILED;
271
return STATUS_FAILED;
272
}
273
mid = env->GetStaticMethodID(clz, "dummy", "()V");
274
if (mid == 0) {
275
printf("Cannot find Method ID for method dummy\n");
276
return STATUS_FAILED;
277
}
278
env->CallStaticVoidMethod(clz, mid);
279
280
if (eventsCount != eventsExpected) {
281
printf("Wrong number of frame pop events: %" PRIuPTR ", expected: %" PRIuPTR "\n",
282
eventsCount, eventsExpected);
283
result = STATUS_FAILED;
284
}
285
286
return result;
287
}
288
289
}
290
291