Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk001/clrbrk001.cpp
40951 views
1
/*
2
* Copyright (c) 2003, 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 "agent_common.h"
28
#include "JVMTITools.h"
29
30
extern "C" {
31
32
33
#define PASSED 0
34
#define STATUS_FAILED 2
35
36
static jvmtiEnv *jvmti = NULL;
37
static jvmtiCapabilities caps;
38
static jvmtiEventCallbacks callbacks;
39
static jint result = PASSED;
40
static jboolean printdump = JNI_FALSE;
41
static jmethodID mid;
42
static int breakpointsExpected = 0;
43
static int breakpointsCount = 0;
44
45
void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env,
46
jthread thr, jmethodID method, jlocation location) {
47
breakpointsCount++;
48
}
49
50
#ifdef STATIC_BUILD
51
JNIEXPORT jint JNICALL Agent_OnLoad_clrbrk001(JavaVM *jvm, char *options, void *reserved) {
52
return Agent_Initialize(jvm, options, reserved);
53
}
54
JNIEXPORT jint JNICALL Agent_OnAttach_clrbrk001(JavaVM *jvm, char *options, void *reserved) {
55
return Agent_Initialize(jvm, options, reserved);
56
}
57
JNIEXPORT jint JNI_OnLoad_clrbrk001(JavaVM *jvm, char *options, void *reserved) {
58
return JNI_VERSION_1_8;
59
}
60
#endif
61
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
62
jvmtiError err;
63
jint res;
64
65
if (options != NULL && strcmp(options, "printdump") == 0) {
66
printdump = JNI_TRUE;
67
}
68
69
res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);
70
if (res != JNI_OK || jvmti == NULL) {
71
printf("Wrong result of a valid call to GetEnv!\n");
72
return JNI_ERR;
73
}
74
75
err = jvmti->GetPotentialCapabilities(&caps);
76
if (err != JVMTI_ERROR_NONE) {
77
printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n",
78
TranslateError(err), err);
79
return JNI_ERR;
80
}
81
82
err = jvmti->AddCapabilities(&caps);
83
if (err != JVMTI_ERROR_NONE) {
84
printf("(AddCapabilities) unexpected error: %s (%d)\n",
85
TranslateError(err), err);
86
return JNI_ERR;
87
}
88
89
err = jvmti->GetCapabilities(&caps);
90
if (err != JVMTI_ERROR_NONE) {
91
printf("(GetCapabilities) unexpected error: %s (%d)\n",
92
TranslateError(err), err);
93
return JNI_ERR;
94
}
95
96
if (caps.can_generate_breakpoint_events) {
97
callbacks.Breakpoint = &Breakpoint;
98
err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks));
99
if (err != JVMTI_ERROR_NONE) {
100
printf("(SetEventCallbacks) unexpected error: %s (%d)\n",
101
TranslateError(err), err);
102
return JNI_ERR;
103
}
104
err = jvmti->SetEventNotificationMode(JVMTI_ENABLE,
105
JVMTI_EVENT_BREAKPOINT, NULL);
106
if (err != JVMTI_ERROR_NONE) {
107
printf("Failed to enable BREAKPOINT event: %s (%d)\n",
108
TranslateError(err), err);
109
return JNI_ERR;
110
}
111
} else {
112
printf("Warning: Breakpoint is not implemented\n");
113
}
114
115
return JNI_OK;
116
}
117
118
JNIEXPORT void JNICALL
119
Java_nsk_jvmti_ClearBreakpoint_clrbrk001_getReady(JNIEnv *env, jclass cls, jint i) {
120
mid = env->GetStaticMethodID(cls, "trial", "(I)I");
121
if (mid == NULL) {
122
printf("Cannot find method \"trial(I)I\"\n");
123
result = STATUS_FAILED;
124
} else {
125
breakpointsExpected = i;
126
}
127
}
128
129
JNIEXPORT void JNICALL Java_nsk_jvmti_ClearBreakpoint_clrbrk001_setBP(JNIEnv *env, jclass cls) {
130
jvmtiError err;
131
132
if (jvmti == NULL) {
133
printf("JVMTI client was not properly loaded!\n");
134
return;
135
}
136
137
if (!caps.can_generate_breakpoint_events) {
138
return;
139
}
140
141
if (mid == NULL) {
142
return;
143
}
144
145
err = jvmti->SetBreakpoint(mid, 0);
146
if (err != JVMTI_ERROR_NONE) {
147
printf("Failed to SetBreakpoint: %s (%d)\n",
148
TranslateError(err), err);
149
result = STATUS_FAILED;
150
}
151
}
152
153
JNIEXPORT void JNICALL Java_nsk_jvmti_ClearBreakpoint_clrbrk001_clearBP(JNIEnv *env, jclass cls) {
154
jvmtiError err;
155
156
if (jvmti == NULL) {
157
printf("JVMTI client was not properly loaded!\n");
158
return;
159
}
160
161
if (!caps.can_generate_breakpoint_events) {
162
return;
163
}
164
165
if (mid == NULL) {
166
return;
167
}
168
169
err = jvmti->ClearBreakpoint(mid, 0);
170
if (err != JVMTI_ERROR_NONE) {
171
printf("Failed to ClearBreakpoint: %s (%d)\n",
172
TranslateError(err), err);
173
result = STATUS_FAILED;
174
}
175
}
176
177
JNIEXPORT jint JNICALL
178
Java_nsk_jvmti_ClearBreakpoint_clrbrk001_check(JNIEnv *env, jclass cls) {
179
if (jvmti == NULL) {
180
printf("JVMTI client was not properly loaded!\n");
181
return STATUS_FAILED;
182
}
183
184
if (!caps.can_generate_breakpoint_events) {
185
return result;
186
}
187
188
if (printdump == JNI_TRUE) {
189
printf("Total number of Breakpoint events: %d\n", breakpointsCount);
190
}
191
192
if (breakpointsCount != breakpointsExpected) {
193
printf("Wrong number of Breakpoint events: %d, expected: %d\n",
194
breakpointsCount, breakpointsExpected);
195
result = STATUS_FAILED;
196
}
197
198
return result;
199
}
200
201
}
202
203