Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes001/bytecodes001.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
typedef struct {
37
const char *name;
38
const char *sig;
39
jboolean stat;
40
jint count;
41
unsigned char *codes;
42
} info;
43
44
static jvmtiEnv *jvmti = NULL;
45
static jvmtiCapabilities caps;
46
static jint result = PASSED;
47
static jboolean printdump = JNI_FALSE;
48
49
static unsigned char m0[] = { 0x2A, 0xB7, 0x00, 0x01, 0xB1 };
50
static unsigned char m1[] = { 0xB1 };
51
static unsigned char m2[] = { 0x1A, 0xBC, 0x06, 0x4C, 0x2B, 0xB0 };
52
static info meth_tab[3] = {
53
{ "<init>", "()V", JNI_FALSE, 5, m0 },
54
{ "meth1", "()V", JNI_FALSE, 1, m1 },
55
{ "meth2", "(I)[F", JNI_TRUE, 6, m2 }
56
};
57
58
#ifdef STATIC_BUILD
59
JNIEXPORT jint JNICALL Agent_OnLoad_bytecodes001(JavaVM *jvm, char *options, void *reserved) {
60
return Agent_Initialize(jvm, options, reserved);
61
}
62
JNIEXPORT jint JNICALL Agent_OnAttach_bytecodes001(JavaVM *jvm, char *options, void *reserved) {
63
return Agent_Initialize(jvm, options, reserved);
64
}
65
JNIEXPORT jint JNI_OnLoad_bytecodes001(JavaVM *jvm, char *options, void *reserved) {
66
return JNI_VERSION_1_8;
67
}
68
#endif
69
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
70
jint res;
71
jvmtiError err;
72
73
if (options != NULL && strcmp(options, "printdump") == 0) {
74
printdump = JNI_TRUE;
75
}
76
77
res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);
78
if (res != JNI_OK || jvmti == NULL) {
79
printf("Wrong result of a valid call to GetEnv!\n");
80
return JNI_ERR;
81
}
82
83
err = jvmti->GetCapabilities(&caps);
84
if (err != JVMTI_ERROR_NONE) {
85
printf("(GetCapabilities) unexpected error: %s (%d)\n",
86
TranslateError(err), err);
87
return JNI_ERR;
88
}
89
90
err = jvmti->GetPotentialCapabilities(&caps);
91
if (err != JVMTI_ERROR_NONE) {
92
printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n",
93
TranslateError(err), err);
94
return JNI_ERR;
95
}
96
97
err = jvmti->AddCapabilities(&caps);
98
if (err != JVMTI_ERROR_NONE) {
99
printf("(AddCapabilities) unexpected error: %s (%d)\n",
100
TranslateError(err), err);
101
return JNI_ERR;
102
}
103
104
err = jvmti->GetCapabilities(&caps);
105
if (err != JVMTI_ERROR_NONE) {
106
printf("(GetCapabilities) unexpected error: %s (%d)\n",
107
TranslateError(err), err);
108
return JNI_ERR;
109
}
110
111
if (!caps.can_get_bytecodes) {
112
printf("Warning: GetBytecodes is not implemented\n");
113
}
114
115
return JNI_OK;
116
}
117
118
void checkMeth(JNIEnv *env, jclass cl, int meth_ind) {
119
jvmtiError err;
120
jmethodID mid = NULL;
121
jint count = -1;
122
unsigned char *codes = NULL;
123
int i;
124
125
if (jvmti == NULL) {
126
printf("JVMTI client was not properly loaded!\n");
127
result = STATUS_FAILED;
128
return;
129
}
130
131
if (meth_tab[meth_ind].stat == JNI_TRUE) {
132
mid = env->GetStaticMethodID(cl,
133
meth_tab[meth_ind].name, meth_tab[meth_ind].sig);
134
} else {
135
mid = env->GetMethodID(cl,
136
meth_tab[meth_ind].name, meth_tab[meth_ind].sig);
137
}
138
if (mid == NULL) {
139
printf("\"%s%s\": cannot get method ID!\n",
140
meth_tab[meth_ind].name, meth_tab[meth_ind].sig);
141
result = STATUS_FAILED;
142
return;
143
}
144
145
if (printdump == JNI_TRUE) {
146
printf(">>> \"%s%s\" check ...\n",
147
meth_tab[meth_ind].name, meth_tab[meth_ind].sig);
148
}
149
150
err = jvmti->GetBytecodes(mid, &count, &codes);
151
if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && !caps.can_get_bytecodes) {
152
/* It is OK */
153
return;
154
} else if (err != JVMTI_ERROR_NONE) {
155
printf("(GetBytecodes#%s) unexpected error: %s (%d)\n",
156
meth_tab[meth_ind].name, TranslateError(err), err);
157
result = STATUS_FAILED;
158
}
159
160
if (count != meth_tab[meth_ind].count) {
161
printf("\"%s%s\": byte codes count expected: %d, actual: %d\n",
162
meth_tab[meth_ind].name, meth_tab[meth_ind].sig,
163
meth_tab[meth_ind].count, count);
164
result = STATUS_FAILED;
165
return;
166
}
167
for (i = 0; i < count; i++) {
168
if (codes[i] != meth_tab[meth_ind].codes[i]) {
169
printf("\"%s%s\": [%d] byte expected: 0x%x, actual: 0x%x\n",
170
meth_tab[meth_ind].name, meth_tab[meth_ind].sig, i,
171
meth_tab[meth_ind].codes[i], codes[i]);
172
result = STATUS_FAILED;
173
}
174
}
175
}
176
177
JNIEXPORT jint JNICALL Java_nsk_jvmti_GetBytecodes_bytecodes001_check(JNIEnv *env, jclass cls) {
178
checkMeth(env, cls, 0);
179
checkMeth(env, cls, 1);
180
checkMeth(env, cls, 2);
181
return result;
182
}
183
184
}
185
186