Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig005/getclsig005.cpp
40952 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
#define CLASS_SIGNATURE "Lnsk/jvmti/GetClassSignature/getclsig005;"
36
37
static jvmtiEnv *jvmti = NULL;
38
static jint result = PASSED;
39
static jboolean printdump = JNI_FALSE;
40
41
#ifdef STATIC_BUILD
42
JNIEXPORT jint JNICALL Agent_OnLoad_getclsig005(JavaVM *jvm, char *options, void *reserved) {
43
return Agent_Initialize(jvm, options, reserved);
44
}
45
JNIEXPORT jint JNICALL Agent_OnAttach_getclsig005(JavaVM *jvm, char *options, void *reserved) {
46
return Agent_Initialize(jvm, options, reserved);
47
}
48
JNIEXPORT jint JNI_OnLoad_getclsig005(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
55
if (options != NULL && strcmp(options, "printdump") == 0) {
56
printdump = JNI_TRUE;
57
}
58
59
res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);
60
if (res != JNI_OK || jvmti == NULL) {
61
printf("Wrong result of a valid call to GetEnv!\n");
62
return JNI_ERR;
63
}
64
65
return JNI_OK;
66
}
67
68
JNIEXPORT jint JNICALL
69
Java_nsk_jvmti_GetClassSignature_getclsig005_check(JNIEnv *env, jclass cls) {
70
jvmtiError err;
71
char *sig, *generic;
72
73
if (jvmti == NULL) {
74
printf("JVMTI client was not properly loaded!\n");
75
return STATUS_FAILED;
76
}
77
78
if (printdump == JNI_TRUE) {
79
printf(">>> invalid class check ...\n");
80
}
81
err = jvmti->GetClassSignature(NULL, &sig, &generic);
82
if (err != JVMTI_ERROR_INVALID_CLASS) {
83
printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n");
84
printf("\tactual: %s (%d)\n", TranslateError(err), err);
85
result = STATUS_FAILED;
86
}
87
88
if (printdump == JNI_TRUE) {
89
printf(">>> (signature_ptr) null pointer check ...\n");
90
}
91
err = jvmti->GetClassSignature(cls, NULL, &generic);
92
if (err != JVMTI_ERROR_NONE) {
93
printf("(signature_ptr) unexpected error: %s (%d)\n",
94
TranslateError(err), err);
95
result = STATUS_FAILED;
96
} else {
97
if (printdump == JNI_TRUE) {
98
printf(">>> generic = \"%s\"\n", generic);
99
}
100
}
101
102
if (printdump == JNI_TRUE) {
103
printf(">>> (generic_ptr) null pointer check ...\n");
104
}
105
err = jvmti->GetClassSignature(cls, &sig, NULL);
106
if (err != JVMTI_ERROR_NONE) {
107
printf("(generic_ptr) unexpected error: %s (%d)\n",
108
TranslateError(err), err);
109
result = STATUS_FAILED;
110
} else {
111
if (printdump == JNI_TRUE) {
112
printf(">>> sig = \"%s\"\n", sig);
113
}
114
if (sig == NULL || strcmp(sig, CLASS_SIGNATURE) != 0) {
115
printf("Wrong class sig: \"%s\", expected: \"%s\"\n",
116
CLASS_SIGNATURE, sig);
117
result = STATUS_FAILED;
118
}
119
}
120
121
if (printdump == JNI_TRUE) {
122
printf(">>> ... done\n");
123
}
124
125
return result;
126
}
127
128
}
129
130