Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss002/clsldrclss002.cpp
40955 views
1
/*
2
* Copyright (c) 2004, 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 <stdlib.h>
25
#include <string.h>
26
#include "jni_tools.h"
27
#include "agent_common.h"
28
#include "jvmti_tools.h"
29
30
extern "C" {
31
32
/* ========================================================================== */
33
34
/* scaffold objects */
35
static jlong timeout = 0;
36
37
/* test objects */
38
static jobject testedClassLoader = NULL;
39
static jclass testedClass = NULL;
40
static jfieldID testedFieldID = NULL;
41
42
static const char* CLASS_SIG =
43
"Lnsk/jvmti/GetClassLoaderClasses/clsldrclss002;";
44
static const char* CLASS_SIG_A =
45
"Lnsk/jvmti/GetClassLoaderClasses/clsldrclss002a;";
46
static const char* CLASS_SIG_E =
47
"Lnsk/jvmti/GetClassLoaderClasses/clsldrclss002e;";
48
static const char* CLASS_SIG_I =
49
"Lnsk/jvmti/GetClassLoaderClasses/clsldrclss002i;";
50
51
/* ========================================================================== */
52
53
static int prepare(JNIEnv* jni) {
54
const char* CLASS_NAME = "nsk/jvmti/GetClassLoaderClasses/clsldrclss002";
55
const char* FIELD_NAME = "testedClassLoader";
56
const char* FIELD_SIGNATURE = "Ljava/lang/ClassLoader;";
57
58
NSK_DISPLAY0("Obtain tested object from a static field of debugee class\n");
59
60
NSK_DISPLAY1("Find class: %s\n", CLASS_NAME);
61
if (!NSK_JNI_VERIFY(jni, (testedClass = jni->FindClass(CLASS_NAME)) != NULL))
62
return NSK_FALSE;
63
64
if (!NSK_JNI_VERIFY(jni, (testedClass = (jclass) jni->NewGlobalRef(testedClass)) != NULL))
65
return NSK_FALSE;
66
67
NSK_DISPLAY2("Find field: %s:%s\n", FIELD_NAME, FIELD_SIGNATURE);
68
if (!NSK_JNI_VERIFY(jni, (testedFieldID =
69
jni->GetStaticFieldID(testedClass, FIELD_NAME, FIELD_SIGNATURE)) != NULL))
70
return NSK_FALSE;
71
72
return NSK_TRUE;
73
}
74
75
static int lookup(jvmtiEnv* jvmti,
76
jint classCount, jclass *classes, const char *exp_sig) {
77
char *signature, *generic;
78
int found = NSK_FALSE;
79
jint i;
80
81
for (i = 0; i < classCount && !found; i++) {
82
if (!NSK_JVMTI_VERIFY(jvmti->GetClassSignature(classes[i], &signature, &generic)))
83
break;
84
85
if (signature != NULL && strcmp(signature, exp_sig) == 0) {
86
NSK_DISPLAY1("Expected class found: %s\n", exp_sig);
87
found = NSK_TRUE;
88
}
89
90
if (signature != NULL)
91
jvmti->Deallocate((unsigned char*)signature);
92
93
if (generic != NULL)
94
jvmti->Deallocate((unsigned char*)generic);
95
}
96
97
return found;
98
}
99
100
/* ========================================================================== */
101
102
/** Agent algorithm. */
103
static void JNICALL
104
agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
105
jclass *classes;
106
jint classCount;
107
108
if (!nsk_jvmti_waitForSync(timeout))
109
return;
110
111
if (!prepare(jni)) {
112
nsk_jvmti_setFailStatus();
113
return;
114
}
115
116
NSK_DISPLAY0("Testcase #1: check on default classloader\n");
117
if (!NSK_JNI_VERIFY(jni, (testedClassLoader =
118
jni->GetStaticObjectField(testedClass, testedFieldID)) != NULL)) {
119
nsk_jvmti_setFailStatus();
120
return;
121
}
122
if (!NSK_JVMTI_VERIFY(jvmti->GetClassLoaderClasses(testedClassLoader, &classCount, &classes))) {
123
nsk_jvmti_setFailStatus();
124
return;
125
}
126
if (!NSK_VERIFY(classCount != 0)) {
127
nsk_jvmti_setFailStatus();
128
return;
129
}
130
if (!NSK_VERIFY(classes != NULL)) {
131
nsk_jvmti_setFailStatus();
132
return;
133
}
134
if (!lookup(jvmti, classCount, classes, CLASS_SIG)) {
135
NSK_COMPLAIN1("Cannot find class in the list: %s\n", CLASS_SIG);
136
nsk_jvmti_setFailStatus();
137
return;
138
}
139
if (classes != NULL)
140
jvmti->Deallocate((unsigned char*)classes);
141
142
if (!nsk_jvmti_resumeSync())
143
return;
144
if (!nsk_jvmti_waitForSync(timeout))
145
return;
146
147
NSK_DISPLAY0("Testcase #2: check on custom classloader\n");
148
if (!NSK_JNI_VERIFY(jni, (testedClassLoader =
149
jni->GetStaticObjectField(testedClass, testedFieldID)) != NULL)) {
150
nsk_jvmti_setFailStatus();
151
return;
152
}
153
if (!NSK_JVMTI_VERIFY(jvmti->GetClassLoaderClasses(testedClassLoader, &classCount, &classes))) {
154
nsk_jvmti_setFailStatus();
155
return;
156
}
157
if (!NSK_VERIFY(classCount != 0)) {
158
nsk_jvmti_setFailStatus();
159
return;
160
}
161
if (!NSK_VERIFY(classes != NULL)) {
162
nsk_jvmti_setFailStatus();
163
return;
164
}
165
if (!lookup(jvmti, classCount, classes, CLASS_SIG_A)) {
166
NSK_COMPLAIN1("Cannot find class in the list: %s\n", CLASS_SIG_A);
167
nsk_jvmti_setFailStatus();
168
}
169
if (!lookup(jvmti, classCount, classes, CLASS_SIG_I)) {
170
NSK_COMPLAIN1("Cannot find class in the list: %s\n", CLASS_SIG_I);
171
nsk_jvmti_setFailStatus();
172
}
173
if (!lookup(jvmti, classCount, classes, CLASS_SIG_E)) {
174
NSK_COMPLAIN1("Cannot find class in the list: %s\n", CLASS_SIG_E);
175
nsk_jvmti_setFailStatus();
176
}
177
if (classes != NULL)
178
jvmti->Deallocate((unsigned char*)classes);
179
180
NSK_TRACE(jni->DeleteGlobalRef(testedClass));
181
182
if (!nsk_jvmti_resumeSync())
183
return;
184
}
185
186
/* ========================================================================== */
187
188
/** Agent library initialization. */
189
#ifdef STATIC_BUILD
190
JNIEXPORT jint JNICALL Agent_OnLoad_clsldrclss002(JavaVM *jvm, char *options, void *reserved) {
191
return Agent_Initialize(jvm, options, reserved);
192
}
193
JNIEXPORT jint JNICALL Agent_OnAttach_clsldrclss002(JavaVM *jvm, char *options, void *reserved) {
194
return Agent_Initialize(jvm, options, reserved);
195
}
196
JNIEXPORT jint JNI_OnLoad_clsldrclss002(JavaVM *jvm, char *options, void *reserved) {
197
return JNI_VERSION_1_8;
198
}
199
#endif
200
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
201
jvmtiEnv* jvmti = NULL;
202
203
NSK_DISPLAY0("Agent_OnLoad\n");
204
205
if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
206
return JNI_ERR;
207
208
timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
209
210
if (!NSK_VERIFY((jvmti =
211
nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
212
return JNI_ERR;
213
214
if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
215
return JNI_ERR;
216
217
return JNI_OK;
218
}
219
220
/* ========================================================================== */
221
222
}
223
224