Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf007/getclmdf007.cpp
40955 views
1
/*
2
* Copyright (c) 2003, 2021, 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
#define ACC_PUBLIC 0x0001
37
#define ACC_PRIVATE 0x0002
38
#define ACC_PROTECTED 0x0004
39
#define ACC_STATIC 0x0008
40
#define ACC_FINAL 0x0010
41
#define ACC_SUPER 0x0020
42
#define ACC_INTERFACE 0x0200
43
#define ACC_ABSTRACT 0x0400
44
45
static jvmtiEnv *jvmti = NULL;
46
static jint result = PASSED;
47
static jboolean printdump = JNI_FALSE;
48
49
#ifdef STATIC_BUILD
50
JNIEXPORT jint JNICALL Agent_OnLoad_getclmdf007(JavaVM *jvm, char *options, void *reserved) {
51
return Agent_Initialize(jvm, options, reserved);
52
}
53
JNIEXPORT jint JNICALL Agent_OnAttach_getclmdf007(JavaVM *jvm, char *options, void *reserved) {
54
return Agent_Initialize(jvm, options, reserved);
55
}
56
JNIEXPORT jint JNI_OnLoad_getclmdf007(JavaVM *jvm, char *options, void *reserved) {
57
return JNI_VERSION_1_8;
58
}
59
#endif
60
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
61
jint res;
62
63
if (options != NULL && strcmp(options, "printdump") == 0) {
64
printdump = JNI_TRUE;
65
}
66
67
res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);
68
if (res != JNI_OK || jvmti == NULL) {
69
printf("Wrong result of a valid call to GetEnv!\n");
70
return JNI_ERR;
71
}
72
73
return JNI_OK;
74
}
75
76
void printModifiers(jint mod) {
77
if (mod & ACC_PUBLIC) printf(" PUBLIC");
78
if (mod & ACC_PRIVATE) printf(" PRIVATE");
79
if (mod & ACC_PROTECTED) printf(" PROTECTED");
80
if (mod & ACC_STATIC) printf(" STATIC");
81
if (mod & ACC_FINAL) printf(" FINAL");
82
if (mod & ACC_SUPER) printf(" SUPER");
83
if (mod & ACC_INTERFACE) printf(" INTERFACE");
84
if (mod & ACC_ABSTRACT) printf(" ABSTRACT");
85
printf(" (0x%0x)\n", mod);
86
}
87
88
JNIEXPORT void JNICALL
89
Java_nsk_jvmti_GetClassModifiers_getclmdf007_check(JNIEnv *env, jclass cls, jint i, jclass arr, jclass comp) {
90
jvmtiError err;
91
jint ArrayModifiers;
92
jint ComponentModifiers;
93
94
if (jvmti == NULL) {
95
printf("JVMTI client was not properly loaded!\n");
96
result = STATUS_FAILED;
97
return;
98
}
99
100
err = jvmti->GetClassModifiers(arr, &ArrayModifiers);
101
if (err != JVMTI_ERROR_NONE) {
102
printf("(GetClassModifiers#%d, arr) unexpected error: %s (%d)\n",
103
i, TranslateError(err), err);
104
result = STATUS_FAILED;
105
return;
106
}
107
108
if (printdump == JNI_TRUE) {
109
printf(">>> %d:", i);
110
printModifiers(ArrayModifiers);
111
}
112
113
if ((ArrayModifiers & ACC_FINAL) == 0) {
114
printf("(%d) ACC_FINAL bit should be set\n", i);
115
result = STATUS_FAILED;
116
}
117
118
if ((ArrayModifiers & ACC_INTERFACE) != 0) {
119
printf("(%d) ACC_INTERFACE bit should be clear\n", i);
120
result = STATUS_FAILED;
121
}
122
123
err = jvmti->GetClassModifiers(comp, &ComponentModifiers);
124
if (err != JVMTI_ERROR_NONE) {
125
printf("(GetClassModifiers#%d, comp) unexpected error: %s (%d)\n",
126
i, TranslateError(err), err);
127
result = STATUS_FAILED;
128
return;
129
}
130
131
ArrayModifiers &= (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED);
132
ComponentModifiers &= (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED);
133
if (ArrayModifiers != ComponentModifiers) {
134
printf("(%d) access bits of array do not match component ones\n", i);
135
printf(" array:");
136
printModifiers(ArrayModifiers);
137
printf(" component:");
138
printModifiers(ComponentModifiers);
139
result = STATUS_FAILED;
140
}
141
}
142
143
JNIEXPORT int JNICALL Java_nsk_jvmti_GetClassModifiers_getclmdf007_getRes(JNIEnv *env, jclass cls) {
144
return result;
145
}
146
147
}
148
149