Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw002/clrfldw002.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;
37
static jvmtiEventCallbacks callbacks;
38
static jvmtiCapabilities caps;
39
static jint result = PASSED;
40
41
void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env,
42
jthread thd, jmethodID mid, jlocation loc,
43
jclass field_klass, jobject obj, jfieldID field) {
44
}
45
46
#ifdef STATIC_BUILD
47
JNIEXPORT jint JNICALL Agent_OnLoad_clrfldw002(JavaVM *jvm, char *options, void *reserved) {
48
return Agent_Initialize(jvm, options, reserved);
49
}
50
JNIEXPORT jint JNICALL Agent_OnAttach_clrfldw002(JavaVM *jvm, char *options, void *reserved) {
51
return Agent_Initialize(jvm, options, reserved);
52
}
53
JNIEXPORT jint JNI_OnLoad_clrfldw002(JavaVM *jvm, char *options, void *reserved) {
54
return JNI_VERSION_1_8;
55
}
56
#endif
57
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
58
jint res;
59
jvmtiError err;
60
61
res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);
62
if (res != JNI_OK || jvmti == NULL) {
63
printf("Wrong result of a valid call to GetEnv !\n");
64
return JNI_ERR;
65
}
66
67
68
err = jvmti->GetPotentialCapabilities(&caps);
69
if (err != JVMTI_ERROR_NONE) {
70
printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n",
71
TranslateError(err), err);
72
return JNI_ERR;
73
}
74
75
err = jvmti->AddCapabilities(&caps);
76
if (err != JVMTI_ERROR_NONE) {
77
printf("(AddCapabilities) unexpected error: %s (%d)\n",
78
TranslateError(err), err);
79
return JNI_ERR;
80
}
81
82
err = jvmti->GetCapabilities(&caps);
83
if (err != JVMTI_ERROR_NONE) {
84
printf("(GetCapabilities) unexpected error: %s (%d)\n",
85
TranslateError(err), err);
86
return JNI_ERR;
87
}
88
89
if (caps.can_generate_field_access_events) {
90
callbacks.FieldAccess = &FieldAccess;
91
err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks));
92
if (err != JVMTI_ERROR_NONE) {
93
printf("(SetEventCallbacks) unexpected error: %s (%d)\n",
94
TranslateError(err), err);
95
return JNI_ERR;
96
}
97
98
err = jvmti->SetEventNotificationMode(JVMTI_ENABLE,
99
JVMTI_EVENT_FIELD_ACCESS, NULL);
100
if (err != JVMTI_ERROR_NONE) {
101
printf("Failed to enable JVMTI_EVENT_FIELD_ACCESS: %s (%d)\n",
102
TranslateError(err), err);
103
return JNI_ERR;
104
}
105
} else {
106
printf("Warning: FieldAccess watch is not implemented\n");
107
}
108
109
return JNI_OK;
110
}
111
112
JNIEXPORT void JNICALL
113
Java_nsk_jvmti_ClearFieldAccessWatch_clrfldw002_check(JNIEnv *env, jclass cls) {
114
jvmtiError err;
115
jfieldID fid1, fid2;
116
117
fid1 = env->GetStaticFieldID(cls, "fld1", "I");
118
fid2 = env->GetStaticFieldID(cls, "fld2", "I");
119
120
if (!caps.can_generate_field_access_events) {
121
err = jvmti->ClearFieldAccessWatch(cls, fid1);
122
if (err != JVMTI_ERROR_MUST_POSSESS_CAPABILITY) {
123
result = STATUS_FAILED;
124
printf("Failed to return MUST_POSSESS_CAPABILITY: %s (%d)\n",
125
TranslateError(err), err);
126
}
127
} else {
128
err = jvmti->ClearFieldAccessWatch(NULL, fid2);
129
if (err != JVMTI_ERROR_INVALID_CLASS) {
130
result = STATUS_FAILED;
131
printf("Failed to return JVMTI_ERROR_INVALID_CLASS: %s (%d)\n",
132
TranslateError(err), err);
133
}
134
135
err = jvmti->ClearFieldAccessWatch(cls, NULL);
136
if (err != JVMTI_ERROR_INVALID_FIELDID) {
137
result = STATUS_FAILED;
138
printf("Failed to return INVALID_FIELDID: %s (%d)\n",
139
TranslateError(err), err);
140
}
141
142
err = jvmti->ClearFieldAccessWatch(cls, fid2);
143
if (err != JVMTI_ERROR_NOT_FOUND) {
144
result = STATUS_FAILED;
145
printf("Failed to return NOT_FOUND: %s (%d)\n",
146
TranslateError(err), err);
147
}
148
}
149
}
150
151
JNIEXPORT jint JNICALL
152
Java_nsk_jvmti_ClearFieldAccessWatch_clrfldw002_getRes(JNIEnv *env, jclass cls) {
153
return result;
154
}
155
156
}
157
158