26 #include "jni_tools.h"
27 #include "agent_common.h"
28 #include "jvmti_tools.h"
29
30 extern "C" {
31
32 /* ========================================================================== */
33
34 /* scaffold objects */
35 static jlong timeout = 0;
36
37 /* test objects */
38 static jrawMonitorID access_lock;
39 static jvmtiPhase phase;
40
41 /* ========================================================================== */
42
43 /* Check SetVerboseFlag function
44 */
45 static int checkSetVerboseFlag(jvmtiEnv *jvmti) {
46 if (!NSK_JVMTI_VERIFY(
47 NSK_CPP_STUB3(SetVerboseFlag, jvmti, JVMTI_VERBOSE_OTHER, JNI_TRUE)))
48 return NSK_FALSE;
49
50 if (!NSK_JVMTI_VERIFY(
51 NSK_CPP_STUB3(SetVerboseFlag, jvmti, JVMTI_VERBOSE_OTHER, JNI_FALSE)))
52 return NSK_FALSE;
53
54 if (!NSK_JVMTI_VERIFY(
55 NSK_CPP_STUB3(SetVerboseFlag, jvmti, JVMTI_VERBOSE_GC, JNI_TRUE)))
56 return NSK_FALSE;
57
58 if (!NSK_JVMTI_VERIFY(
59 NSK_CPP_STUB3(SetVerboseFlag, jvmti, JVMTI_VERBOSE_GC, JNI_FALSE)))
60 return NSK_FALSE;
61
62 if (!NSK_JVMTI_VERIFY(
63 NSK_CPP_STUB3(SetVerboseFlag, jvmti, JVMTI_VERBOSE_CLASS, JNI_TRUE)))
64 return NSK_FALSE;
65
66 if (!NSK_JVMTI_VERIFY(
67 NSK_CPP_STUB3(SetVerboseFlag, jvmti, JVMTI_VERBOSE_CLASS, JNI_FALSE)))
68 return NSK_FALSE;
69
70 if (!NSK_JVMTI_VERIFY(
71 NSK_CPP_STUB3(SetVerboseFlag, jvmti, JVMTI_VERBOSE_JNI, JNI_TRUE)))
72 return NSK_FALSE;
73
74 if (!NSK_JVMTI_VERIFY(
75 NSK_CPP_STUB3(SetVerboseFlag, jvmti, JVMTI_VERBOSE_JNI, JNI_FALSE)))
76 return NSK_FALSE;
77
78 return NSK_TRUE;
79 }
80
81 /* ========================================================================== */
82
83 void JNICALL
84 VMInit(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread) {
85
86 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti, &phase)))
87 nsk_jvmti_setFailStatus();
88
89 NSK_DISPLAY1("Phase: %s\n", TranslatePhase(phase));
90
91 /* testcase #3: check SetVerboseFlag in VMInit */
92 NSK_DISPLAY0("Testcase #3: check SetVerboseFlag in VMInit\n");
93 if (!checkSetVerboseFlag(jvmti))
94 nsk_jvmti_setFailStatus();
95 }
96
97 void JNICALL
98 ClassFileLoadHook(jvmtiEnv *jvmti, JNIEnv *jni,
99 jclass class_being_redefined,
100 jobject loader, const char* name,
101 jobject protection_domain,
102 jint class_data_len,
103 const unsigned char* class_data,
104 jint* new_class_data_len,
105 unsigned char** new_class_data) {
106 jvmtiPhase curr_phase;
107
108 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, access_lock)))
109 nsk_jvmti_setFailStatus();
110
111 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti, &curr_phase)))
112 nsk_jvmti_setFailStatus();
113
114 if (phase != curr_phase) {
115 phase = curr_phase;
116 NSK_DISPLAY1("Phase: %s\n", TranslatePhase(phase));
117
118 /* testcase #2: check SetVerboseFlag in ClassFileLoadHook */
119 NSK_DISPLAY0("Testcase #2: check SetVerboseFlag in ClassFileLoadHook\n");
120 if (!checkSetVerboseFlag(jvmti))
121 nsk_jvmti_setFailStatus();
122 }
123
124 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, access_lock)))
125 nsk_jvmti_setFailStatus();
126 }
127
128 /* ========================================================================== */
129
130 /* agent algorithm */
131 static void JNICALL
132 agentProc(jvmtiEnv *jvmti, JNIEnv* jni, void* arg) {
133
134 /* wait for debuggee start */
135 if (!nsk_jvmti_waitForSync(timeout))
136 return;
137
138 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti, &phase)))
139 nsk_jvmti_setFailStatus();
140
141 NSK_DISPLAY1("Phase: %s\n", TranslatePhase(phase));
142
143 /* testcase #4: check SetVerboseFlag in agentProc */
144 NSK_DISPLAY0("Testcase #4: check SetVerboseFlag in agentProc\n");
145 if (!checkSetVerboseFlag(jvmti))
146 nsk_jvmti_setFailStatus();
147
148 /* resume debugee after last sync */
149 if (!nsk_jvmti_resumeSync())
150 return;
151 }
152
153 /* ========================================================================== */
154
155 /* agent library initialization */
156 #ifdef STATIC_BUILD
157 JNIEXPORT jint JNICALL Agent_OnLoad_setvrbflag001(JavaVM *jvm, char *options, void *reserved) {
158 return Agent_Initialize(jvm, options, reserved);
164 return JNI_VERSION_1_8;
165 }
166 #endif
167 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
168 jvmtiEnv *jvmti = NULL;
169 jvmtiEventCallbacks callbacks;
170
171 /* init framework and parse options */
172 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
173 return JNI_ERR;
174
175 timeout = nsk_jvmti_getWaitTime() * 60000;
176 NSK_DISPLAY1("Timeout: %d msc\n", (int)timeout);
177
178 /* create JVMTI environment */
179 if (!NSK_VERIFY((jvmti =
180 nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
181 return JNI_ERR;
182
183 /* Create data access lock */
184 if (!NSK_JVMTI_VERIFY(
185 NSK_CPP_STUB3(CreateRawMonitor, jvmti,
186 "_access_lock", &access_lock)))
187 return JNI_ERR;
188
189 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti, &phase)))
190 return JNI_ERR;
191
192 NSK_DISPLAY1("Phase: %s\n", TranslatePhase(phase));
193
194 /* testcase #1: check SetVerboseFlag in Agent_OnLoad */
195 NSK_DISPLAY0("Testcase #1: check SetVerboseFlag in Agent_OnLoad\n");
196 if (!checkSetVerboseFlag(jvmti))
197 nsk_jvmti_setFailStatus();
198
199 memset(&callbacks, 0, sizeof(callbacks));
200 callbacks.VMInit = &VMInit;
201 callbacks.ClassFileLoadHook = &ClassFileLoadHook;
202 if (!NSK_JVMTI_VERIFY(
203 NSK_CPP_STUB3(SetEventCallbacks, jvmti,
204 &callbacks, sizeof(callbacks))))
205 return JNI_ERR;
206
207 /* enable VMInit event */
208 if (!NSK_JVMTI_VERIFY(
209 NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE,
210 JVMTI_EVENT_VM_INIT, NULL)))
211 return JNI_ERR;
212
213 /* enable ClassFileLoadHook event */
214 if (!NSK_JVMTI_VERIFY(
215 NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE,
216 JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL)))
217 return JNI_ERR;
218
219 /* register agent proc and arg */
220 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
221 return JNI_ERR;
222
223 return JNI_OK;
224 }
225
226 /* ========================================================================== */
227
228 }
|
26 #include "jni_tools.h"
27 #include "agent_common.h"
28 #include "jvmti_tools.h"
29
30 extern "C" {
31
32 /* ========================================================================== */
33
34 /* scaffold objects */
35 static jlong timeout = 0;
36
37 /* test objects */
38 static jrawMonitorID access_lock;
39 static jvmtiPhase phase;
40
41 /* ========================================================================== */
42
43 /* Check SetVerboseFlag function
44 */
45 static int checkSetVerboseFlag(jvmtiEnv *jvmti) {
46 if (!NSK_JVMTI_VERIFY(jvmti->SetVerboseFlag(JVMTI_VERBOSE_OTHER, JNI_TRUE)))
47 return NSK_FALSE;
48
49 if (!NSK_JVMTI_VERIFY(jvmti->SetVerboseFlag(JVMTI_VERBOSE_OTHER, JNI_FALSE)))
50 return NSK_FALSE;
51
52 if (!NSK_JVMTI_VERIFY(jvmti->SetVerboseFlag(JVMTI_VERBOSE_GC, JNI_TRUE)))
53 return NSK_FALSE;
54
55 if (!NSK_JVMTI_VERIFY(jvmti->SetVerboseFlag(JVMTI_VERBOSE_GC, JNI_FALSE)))
56 return NSK_FALSE;
57
58 if (!NSK_JVMTI_VERIFY(jvmti->SetVerboseFlag(JVMTI_VERBOSE_CLASS, JNI_TRUE)))
59 return NSK_FALSE;
60
61 if (!NSK_JVMTI_VERIFY(jvmti->SetVerboseFlag(JVMTI_VERBOSE_CLASS, JNI_FALSE)))
62 return NSK_FALSE;
63
64 if (!NSK_JVMTI_VERIFY(jvmti->SetVerboseFlag(JVMTI_VERBOSE_JNI, JNI_TRUE)))
65 return NSK_FALSE;
66
67 if (!NSK_JVMTI_VERIFY(jvmti->SetVerboseFlag(JVMTI_VERBOSE_JNI, JNI_FALSE)))
68 return NSK_FALSE;
69
70 return NSK_TRUE;
71 }
72
73 /* ========================================================================== */
74
75 void JNICALL
76 VMInit(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread) {
77
78 if (!NSK_JVMTI_VERIFY(jvmti->GetPhase(&phase)))
79 nsk_jvmti_setFailStatus();
80
81 NSK_DISPLAY1("Phase: %s\n", TranslatePhase(phase));
82
83 /* testcase #3: check SetVerboseFlag in VMInit */
84 NSK_DISPLAY0("Testcase #3: check SetVerboseFlag in VMInit\n");
85 if (!checkSetVerboseFlag(jvmti))
86 nsk_jvmti_setFailStatus();
87 }
88
89 void JNICALL
90 ClassFileLoadHook(jvmtiEnv *jvmti, JNIEnv *jni,
91 jclass class_being_redefined,
92 jobject loader, const char* name,
93 jobject protection_domain,
94 jint class_data_len,
95 const unsigned char* class_data,
96 jint* new_class_data_len,
97 unsigned char** new_class_data) {
98 jvmtiPhase curr_phase;
99
100 if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(access_lock)))
101 nsk_jvmti_setFailStatus();
102
103 if (!NSK_JVMTI_VERIFY(jvmti->GetPhase(&curr_phase)))
104 nsk_jvmti_setFailStatus();
105
106 if (phase != curr_phase) {
107 phase = curr_phase;
108 NSK_DISPLAY1("Phase: %s\n", TranslatePhase(phase));
109
110 /* testcase #2: check SetVerboseFlag in ClassFileLoadHook */
111 NSK_DISPLAY0("Testcase #2: check SetVerboseFlag in ClassFileLoadHook\n");
112 if (!checkSetVerboseFlag(jvmti))
113 nsk_jvmti_setFailStatus();
114 }
115
116 if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(access_lock)))
117 nsk_jvmti_setFailStatus();
118 }
119
120 /* ========================================================================== */
121
122 /* agent algorithm */
123 static void JNICALL
124 agentProc(jvmtiEnv *jvmti, JNIEnv* jni, void* arg) {
125
126 /* wait for debuggee start */
127 if (!nsk_jvmti_waitForSync(timeout))
128 return;
129
130 if (!NSK_JVMTI_VERIFY(jvmti->GetPhase(&phase)))
131 nsk_jvmti_setFailStatus();
132
133 NSK_DISPLAY1("Phase: %s\n", TranslatePhase(phase));
134
135 /* testcase #4: check SetVerboseFlag in agentProc */
136 NSK_DISPLAY0("Testcase #4: check SetVerboseFlag in agentProc\n");
137 if (!checkSetVerboseFlag(jvmti))
138 nsk_jvmti_setFailStatus();
139
140 /* resume debugee after last sync */
141 if (!nsk_jvmti_resumeSync())
142 return;
143 }
144
145 /* ========================================================================== */
146
147 /* agent library initialization */
148 #ifdef STATIC_BUILD
149 JNIEXPORT jint JNICALL Agent_OnLoad_setvrbflag001(JavaVM *jvm, char *options, void *reserved) {
150 return Agent_Initialize(jvm, options, reserved);
156 return JNI_VERSION_1_8;
157 }
158 #endif
159 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
160 jvmtiEnv *jvmti = NULL;
161 jvmtiEventCallbacks callbacks;
162
163 /* init framework and parse options */
164 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
165 return JNI_ERR;
166
167 timeout = nsk_jvmti_getWaitTime() * 60000;
168 NSK_DISPLAY1("Timeout: %d msc\n", (int)timeout);
169
170 /* create JVMTI environment */
171 if (!NSK_VERIFY((jvmti =
172 nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
173 return JNI_ERR;
174
175 /* Create data access lock */
176 if (!NSK_JVMTI_VERIFY(jvmti->CreateRawMonitor("_access_lock", &access_lock)))
177 return JNI_ERR;
178
179 if (!NSK_JVMTI_VERIFY(jvmti->GetPhase(&phase)))
180 return JNI_ERR;
181
182 NSK_DISPLAY1("Phase: %s\n", TranslatePhase(phase));
183
184 /* testcase #1: check SetVerboseFlag in Agent_OnLoad */
185 NSK_DISPLAY0("Testcase #1: check SetVerboseFlag in Agent_OnLoad\n");
186 if (!checkSetVerboseFlag(jvmti))
187 nsk_jvmti_setFailStatus();
188
189 memset(&callbacks, 0, sizeof(callbacks));
190 callbacks.VMInit = &VMInit;
191 callbacks.ClassFileLoadHook = &ClassFileLoadHook;
192 if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks))))
193 return JNI_ERR;
194
195 /* enable VMInit event */
196 if (!NSK_JVMTI_VERIFY(
197 jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_VM_INIT, NULL)))
198 return JNI_ERR;
199
200 /* enable ClassFileLoadHook event */
201 if (!NSK_JVMTI_VERIFY(
202 jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL)))
203 return JNI_ERR;
204
205 /* register agent proc and arg */
206 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
207 return JNI_ERR;
208
209 return JNI_OK;
210 }
211
212 /* ========================================================================== */
213
214 }
|