Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassFields/getclfld007/getclfld007.cpp
40955 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
typedef struct {
37
const char *name;
38
const char *sig;
39
} fld_info;
40
41
typedef struct {
42
const char *name;
43
jint fcount;
44
fld_info *flds;
45
} class_info;
46
47
static jvmtiEnv *jvmti = NULL;
48
static jint result = PASSED;
49
static jboolean printdump = JNI_FALSE;
50
51
static fld_info f0[] = {
52
{ "fld_1", "Ljava/lang/String;" }
53
};
54
55
static fld_info f1[] = {
56
{ "fld_n1", "I" }
57
};
58
59
static fld_info f2[] = {
60
{ "fld_n2", "I" }
61
};
62
63
static fld_info f4[] = {
64
{ "fld_o2", "I" }
65
};
66
67
static fld_info f5[] = {
68
{ "fld_o3", "I" }
69
};
70
71
static fld_info f6[] = {
72
{ "fld_i1", "I" }
73
};
74
75
static fld_info f7[] = {
76
{ "fld_i2", "I" }
77
};
78
79
static fld_info f8[] = {
80
{ "fld_i2", "I" }
81
};
82
83
static fld_info f9[] = {
84
{ "fld_i1", "I" }
85
};
86
87
static class_info classes[] = {
88
{ "InnerClass1", 1, f0 },
89
{ "InnerInterface", 1, f1 },
90
{ "InnerClass2", 1, f2 },
91
{ "OuterClass1", 0, NULL },
92
{ "OuterClass2", 1, f4 },
93
{ "OuterClass3", 1, f5 },
94
{ "OuterInterface1", 1, f6 },
95
{ "OuterInterface2", 1, f7 },
96
{ "OuterClass4", 1, f8 },
97
{ "OuterClass5", 1, f9 }
98
};
99
100
#ifdef STATIC_BUILD
101
JNIEXPORT jint JNICALL Agent_OnLoad_getclfld007(JavaVM *jvm, char *options, void *reserved) {
102
return Agent_Initialize(jvm, options, reserved);
103
}
104
JNIEXPORT jint JNICALL Agent_OnAttach_getclfld007(JavaVM *jvm, char *options, void *reserved) {
105
return Agent_Initialize(jvm, options, reserved);
106
}
107
JNIEXPORT jint JNI_OnLoad_getclfld007(JavaVM *jvm, char *options, void *reserved) {
108
return JNI_VERSION_1_8;
109
}
110
#endif
111
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
112
jint res;
113
114
if (options != NULL && strcmp(options, "printdump") == 0) {
115
printdump = JNI_TRUE;
116
}
117
118
res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);
119
if (res != JNI_OK || jvmti == NULL) {
120
printf("Wrong result of a valid call to GetEnv!\n");
121
return JNI_ERR;
122
}
123
124
return JNI_OK;
125
}
126
127
JNIEXPORT void JNICALL
128
Java_nsk_jvmti_GetClassFields_getclfld007_check(JNIEnv *env, jclass cls, jint i, jclass clazz) {
129
jvmtiError err;
130
jint fcount;
131
jfieldID *fields;
132
char *name, *sig, *generic;
133
int j;
134
135
if (jvmti == NULL) {
136
printf("JVMTI client was not properly loaded!\n");
137
result = STATUS_FAILED;
138
return;
139
}
140
141
if (printdump == JNI_TRUE) {
142
printf(">>> %s:\n", classes[i].name);
143
}
144
145
err = jvmti->GetClassFields(clazz, &fcount, &fields);
146
if (err != JVMTI_ERROR_NONE) {
147
printf("(GetClassFields#%d) unexpected error: %s (%d)\n",
148
i, TranslateError(err), err);
149
result = STATUS_FAILED;
150
return;
151
}
152
153
if (fcount != classes[i].fcount) {
154
printf("(%d) wrong number of fields: %d, expected: %d\n",
155
i, fcount, classes[i].fcount);
156
result = STATUS_FAILED;
157
}
158
for (j = 0; j < fcount; j++) {
159
if (fields[j] == NULL) {
160
printf("(%d:%d) fieldID = null\n", i, j);
161
} else {
162
err = jvmti->GetFieldName(clazz, fields[j],
163
&name, &sig, &generic);
164
if (err != JVMTI_ERROR_NONE) {
165
printf("(GetFieldName#%d:%d) unexpected error: %s (%d)\n",
166
i, j, TranslateError(err), err);
167
} else {
168
if (printdump == JNI_TRUE) {
169
printf(">>> [%d]: %s, sig = \"%s\"\n", j, name, sig);
170
}
171
if ((j < classes[i].fcount) &&
172
(name == NULL || sig == NULL ||
173
strcmp(name, classes[i].flds[j].name) != 0 ||
174
strcmp(sig, classes[i].flds[j].sig) != 0)) {
175
printf("(%d:%d) wrong field: \"%s%s\"", i, j, name, sig);
176
printf(", expected: \"%s%s\"\n",
177
classes[i].flds[j].name, classes[i].flds[j].sig);
178
result = STATUS_FAILED;
179
}
180
}
181
}
182
}
183
}
184
185
JNIEXPORT int JNICALL
186
Java_nsk_jvmti_GetClassFields_getclfld007_getRes(JNIEnv *env, jclass cls) {
187
return result;
188
}
189
190
}
191
192