Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassMethods/getclmthd007/getclmthd007.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 "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
typedef struct {
37
const char *name;
38
const char *sig;
39
} meth_info;
40
41
typedef struct {
42
const char *name;
43
jint mcount;
44
meth_info *meths;
45
} class_info;
46
47
static jvmtiEnv *jvmti = NULL;
48
static jint result = PASSED;
49
static jboolean printdump = JNI_FALSE;
50
51
static meth_info m0[] = {
52
{ "<init>", "(Lnsk/jvmti/GetClassMethods/getclmthd007;)V" },
53
{ "meth_1", "(Ljava/lang/String;)V" }
54
};
55
56
static meth_info m1[] = {
57
{ "meth_n1", "()V" },
58
{ "meth_def1", "()V" }
59
};
60
61
static meth_info m2[] = {
62
{ "<init>", "()V" },
63
{ "meth_n1", "()V" },
64
{ "meth_n2", "()I" },
65
{ "<clinit>", "()V" }
66
};
67
68
static meth_info m3[] = {
69
{ "<init>", "()V" }
70
};
71
72
static meth_info m4[] = {
73
{ "<init>", "()V" },
74
{ "meth_o2", "()V" }
75
};
76
77
static meth_info m5[] = {
78
{ "<init>", "()V" },
79
{ "meth_o3", "()I" }
80
};
81
82
static meth_info m6[] = {
83
{ "meth_i1", "()I" }
84
};
85
86
static meth_info m7[] = {
87
{ "meth_i2", "()I" }
88
};
89
90
static meth_info m8[] = {
91
{ "<init>", "()V" },
92
{ "meth_i2", "()I" }
93
};
94
95
static meth_info m9[] = {
96
{ "<init>", "()V" },
97
{ "meth_i1", "()I" }
98
};
99
100
static class_info classes[] = {
101
{ "InnerClass1", 2, m0 },
102
{ "InnerInterface", 2, m1 },
103
{ "InnerClass2", 4, m2 },
104
{ "OuterClass1", 1, m3 },
105
{ "OuterClass2", 2, m4 },
106
{ "OuterClass3", 2, m5 },
107
{ "OuterInterface1", 1, m6 },
108
{ "OuterInterface2", 1, m7 },
109
{ "OuterClass4", 2, m8 },
110
{ "OuterClass5", 2, m9 }
111
};
112
113
#ifdef STATIC_BUILD
114
JNIEXPORT jint JNICALL Agent_OnLoad_getclmthd007(JavaVM *jvm, char *options, void *reserved) {
115
return Agent_Initialize(jvm, options, reserved);
116
}
117
JNIEXPORT jint JNICALL Agent_OnAttach_getclmthd007(JavaVM *jvm, char *options, void *reserved) {
118
return Agent_Initialize(jvm, options, reserved);
119
}
120
JNIEXPORT jint JNI_OnLoad_getclmthd007(JavaVM *jvm, char *options, void *reserved) {
121
return JNI_VERSION_1_8;
122
}
123
#endif
124
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
125
jint res;
126
127
if (options != NULL && strcmp(options, "printdump") == 0) {
128
printdump = JNI_TRUE;
129
}
130
131
res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);
132
if (res != JNI_OK || jvmti == NULL) {
133
printf("Wrong result of a valid call to GetEnv!\n");
134
return JNI_ERR;
135
}
136
137
return JNI_OK;
138
}
139
140
JNIEXPORT void JNICALL
141
Java_nsk_jvmti_GetClassMethods_getclmthd007_check(JNIEnv *env,
142
jclass cls, jint i, jclass clazz) {
143
jvmtiError err;
144
jint mcount;
145
jmethodID *methods;
146
char *name, *sig, *generic;
147
int j, k;
148
149
int failed = JNI_FALSE; // enable debugging on failure
150
if (jvmti == NULL) {
151
printf("JVMTI client was not properly loaded!\n");
152
result = STATUS_FAILED;
153
return;
154
}
155
156
if (printdump == JNI_TRUE) {
157
printf(">>> %s:\n", classes[i].name);
158
}
159
160
err = jvmti->GetClassMethods(clazz, &mcount, &methods);
161
if (err != JVMTI_ERROR_NONE) {
162
printf("(GetClassMethods#%d) unexpected error: %s (%d)\n",
163
i, TranslateError(err), err);
164
result = STATUS_FAILED;
165
return;
166
}
167
168
if (mcount != classes[i].mcount) {
169
printf("(%d) wrong number of methods: %d, expected: %d\n",
170
i, mcount, classes[i].mcount);
171
result = STATUS_FAILED;
172
failed = JNI_TRUE; // show the methods found
173
printf(">>> %s:\n", classes[i].name);
174
}
175
for (k = 0; k < mcount; k++) {
176
if (methods[k] == NULL) {
177
printf("(%d:%d) methodID = null\n", i, k);
178
result = STATUS_FAILED;
179
} else if (printdump == JNI_TRUE || failed == JNI_TRUE) {
180
err = jvmti->GetMethodName(methods[k],
181
&name, &sig, &generic);
182
if (err == JVMTI_ERROR_NONE) {
183
printf(">>> [%d]: %s%s\n", k, name, sig);
184
}
185
}
186
}
187
for (j = 0; j < classes[i].mcount; j++) {
188
/* search the returned table for each expected entry */
189
for (k = 0; k < mcount; k++) {
190
if (methods[k] != NULL) {
191
err = jvmti->GetMethodName(methods[k],
192
&name, &sig, &generic);
193
if (err != JVMTI_ERROR_NONE) {
194
printf("(GetMethodName#%d:%d) unexpected error: %s (%d)\n",
195
i, k, TranslateError(err), err);
196
result = STATUS_FAILED;
197
} else {
198
if (name != NULL && sig != NULL &&
199
strcmp(name, classes[i].meths[j].name) == 0 &&
200
strcmp(sig, classes[i].meths[j].sig) == 0) break;
201
}
202
}
203
}
204
if (k == mcount) {
205
printf("(%d:%d) method not found: \"%s%s\"", i, j,
206
classes[i].meths[j].name, classes[i].meths[j].sig);
207
result = STATUS_FAILED;
208
}
209
}
210
}
211
212
JNIEXPORT int JNICALL
213
Java_nsk_jvmti_GetClassMethods_getclmthd007_getRes(JNIEnv *env, jclass cls) {
214
return result;
215
}
216
217
}
218
219