Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetBytecodes/bytecodes002/bytecodes002.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 jint result = PASSED;
39
static jboolean printdump = JNI_FALSE;
40
41
#ifdef STATIC_BUILD
42
JNIEXPORT jint JNICALL Agent_OnLoad_bytecodes002(JavaVM *jvm, char *options, void *reserved) {
43
return Agent_Initialize(jvm, options, reserved);
44
}
45
JNIEXPORT jint JNICALL Agent_OnAttach_bytecodes002(JavaVM *jvm, char *options, void *reserved) {
46
return Agent_Initialize(jvm, options, reserved);
47
}
48
JNIEXPORT jint JNI_OnLoad_bytecodes002(JavaVM *jvm, char *options, void *reserved) {
49
return JNI_VERSION_1_8;
50
}
51
#endif
52
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
53
jint res;
54
jvmtiError err;
55
56
if (options != NULL && strcmp(options, "printdump") == 0) {
57
printdump = JNI_TRUE;
58
}
59
60
res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);
61
if (res != JNI_OK || jvmti == NULL) {
62
printf("Wrong result of a valid call to GetEnv!\n");
63
return JNI_ERR;
64
}
65
66
err = jvmti->GetCapabilities(&caps);
67
if (err != JVMTI_ERROR_NONE) {
68
printf("(GetCapabilities) unexpected error: %s (%d)\n",
69
TranslateError(err), err);
70
return JNI_ERR;
71
}
72
73
err = jvmti->GetPotentialCapabilities(&caps);
74
if (err != JVMTI_ERROR_NONE) {
75
printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n",
76
TranslateError(err), err);
77
return JNI_ERR;
78
}
79
80
err = jvmti->AddCapabilities(&caps);
81
if (err != JVMTI_ERROR_NONE) {
82
printf("(AddCapabilities) unexpected error: %s (%d)\n",
83
TranslateError(err), err);
84
return JNI_ERR;
85
}
86
87
err = jvmti->GetCapabilities(&caps);
88
if (err != JVMTI_ERROR_NONE) {
89
printf("(GetCapabilities) unexpected error: %s (%d)\n",
90
TranslateError(err), err);
91
return JNI_ERR;
92
}
93
94
if (!caps.can_get_bytecodes) {
95
printf("Warning: GetBytecodes is not implemented\n");
96
}
97
98
return JNI_OK;
99
}
100
101
JNIEXPORT jint JNICALL
102
Java_nsk_jvmti_GetBytecodes_bytecodes002_check(JNIEnv *env, jclass cls) {
103
jvmtiError err;
104
jmethodID mid;
105
jint bytecodeCount;
106
unsigned char *bytecodes;
107
108
if (jvmti == NULL) {
109
printf("JVMTI client was not properly loaded!\n");
110
return STATUS_FAILED;
111
}
112
113
mid = env->GetMethodID(cls, "<init>", "()V");
114
if (mid == NULL) {
115
printf("Cannot get method ID for \"<init>\"!\n");
116
return STATUS_FAILED;
117
}
118
119
if (printdump == JNI_TRUE) {
120
printf(">>> invalid method check ...\n");
121
}
122
err = jvmti->GetBytecodes(NULL, &bytecodeCount, &bytecodes);
123
if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && !caps.can_get_bytecodes) {
124
/* It is OK */
125
} else if (err != JVMTI_ERROR_INVALID_METHODID) {
126
printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n");
127
printf("\tactual: %s (%d)\n", TranslateError(err), err);
128
result = STATUS_FAILED;
129
}
130
131
if (printdump == JNI_TRUE) {
132
printf(">>> (bytecodeCountPtr) null pointer check ...\n");
133
}
134
err = jvmti->GetBytecodes(mid, NULL, &bytecodes);
135
if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && !caps.can_get_bytecodes) {
136
/* It is OK */
137
} else if (err != JVMTI_ERROR_NULL_POINTER) {
138
printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n");
139
printf("\tactual: %s (%d)\n", TranslateError(err), err);
140
result = STATUS_FAILED;
141
}
142
143
if (printdump == JNI_TRUE) {
144
printf(">>> (bytecodesPtr) null pointer check ...\n");
145
}
146
err = jvmti->GetBytecodes(mid, &bytecodeCount, NULL);
147
if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && !caps.can_get_bytecodes) {
148
/* It is OK */
149
} else if (err != JVMTI_ERROR_NULL_POINTER) {
150
printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n");
151
printf("\tactual: %s (%d)\n", TranslateError(err), err);
152
result = STATUS_FAILED;
153
}
154
155
mid = env->GetStaticMethodID(cls, "check", "()I");
156
if (mid == NULL) {
157
printf("Cannot get method ID for \"check\"!\n");
158
return STATUS_FAILED;
159
}
160
161
if (printdump == JNI_TRUE) {
162
printf(">>> native method check ...\n");
163
}
164
err = jvmti->GetBytecodes(mid, &bytecodeCount, &bytecodes);
165
if (err != JVMTI_ERROR_NATIVE_METHOD) {
166
printf("Error expected: JVMTI_ERROR_NATIVE_METHOD,\n");
167
printf("\tactual: %s (%d)\n", TranslateError(err), err);
168
result = STATUS_FAILED;
169
}
170
171
if (printdump == JNI_TRUE) {
172
printf(">>> ... done\n");
173
}
174
175
return result;
176
}
177
178
}
179
180