Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldModificationWatch/clrfmodw002/clrfmodw002.cpp
40955 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 FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env,
42
jthread thd, jmethodID mid, jlocation loc,
43
jclass field_klass, jobject obj, jfieldID field,
44
char sig, jvalue new_value) {
45
}
46
47
#ifdef STATIC_BUILD
48
JNIEXPORT jint JNICALL Agent_OnLoad_clrfmodw002(JavaVM *jvm, char *options, void *reserved) {
49
return Agent_Initialize(jvm, options, reserved);
50
}
51
JNIEXPORT jint JNICALL Agent_OnAttach_clrfmodw002(JavaVM *jvm, char *options, void *reserved) {
52
return Agent_Initialize(jvm, options, reserved);
53
}
54
JNIEXPORT jint JNI_OnLoad_clrfmodw002(JavaVM *jvm, char *options, void *reserved) {
55
return JNI_VERSION_1_8;
56
}
57
#endif
58
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
59
jint res;
60
jvmtiError err;
61
62
res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);
63
if (res != JNI_OK || jvmti == NULL) {
64
printf("Wrong result of a valid call to GetEnv !\n");
65
return JNI_ERR;
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_modification_events) {
90
callbacks.FieldModification = &FieldModification;
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_MODIFICATION, NULL);
100
if (err != JVMTI_ERROR_NONE) {
101
printf("Failed to enable JVMTI_EVENT_FIELD_MODIFICATION: %s (%d)\n",
102
TranslateError(err), err);
103
return JNI_ERR;
104
}
105
} else {
106
printf("Warning: FieldModification watch is not implemented\n");
107
}
108
109
return JNI_OK;
110
}
111
112
JNIEXPORT void JNICALL
113
Java_nsk_jvmti_ClearFieldModificationWatch_clrfmodw002_check(JNIEnv *env,
114
jclass cls) {
115
jvmtiError err;
116
jfieldID fid1, fid2;
117
118
fid1 = env->GetStaticFieldID(cls, "fld1", "I");
119
fid2 = env->GetStaticFieldID(cls, "fld2", "I");
120
121
if (!caps.can_generate_field_modification_events) {
122
printf("Warning: ClearFieldModificationWatch is not implemented\n");
123
err = jvmti->ClearFieldModificationWatch(cls, fid1);
124
if (err != JVMTI_ERROR_MUST_POSSESS_CAPABILITY) {
125
result = STATUS_FAILED;
126
printf("Failed to return MUST_POSSESS_CAPABILITY: %s (%d)\n",
127
TranslateError(err), err);
128
}
129
} else {
130
err = jvmti->ClearFieldModificationWatch(NULL, fid2);
131
if (err != JVMTI_ERROR_INVALID_CLASS) {
132
result = STATUS_FAILED;
133
printf("Failed to return JVMTI_ERROR_INVALID_CLASS: %s (%d)\n",
134
TranslateError(err), err);
135
}
136
137
err = jvmti->ClearFieldModificationWatch(cls, NULL);
138
if (err != JVMTI_ERROR_INVALID_FIELDID) {
139
result = STATUS_FAILED;
140
printf("Failed to return INVALID_FIELDID: %s (%d)\n",
141
TranslateError(err), err);
142
}
143
144
err = jvmti->ClearFieldModificationWatch(cls, fid2);
145
if (err != JVMTI_ERROR_NOT_FOUND) {
146
result = STATUS_FAILED;
147
printf("Failed to return NOT_FOUND: %s (%d)\n",
148
TranslateError(err), err);
149
}
150
}
151
}
152
153
JNIEXPORT jint JNICALL
154
Java_nsk_jvmti_ClearFieldModificationWatch_clrfmodw002_getRes(JNIEnv *env,
155
jclass cls) {
156
return result;
157
}
158
159
}
160
161