1
1
/*
2
- * Copyright (c) 2003, 2024 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2003, 2025 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -33,6 +33,7 @@ extern "C" {
33
33
/* ============================================================================= */
34
34
35
35
static jlong timeout = 0 ;
36
+ static jrawMonitorID monitor; // a monitor to serialize event callbacks and checkCpuTime calls
36
37
37
38
#define TESTED_THREAD_NAME " thrcputime002Thread"
38
39
@@ -150,6 +151,7 @@ agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
150
151
151
152
NSK_DISPLAY0 (" >>> Testcase #2: Check initial cpu time in agent thread\n " );
152
153
{
154
+ RawMonitorLocker rml (jvmti, jni, monitor);
153
155
if (!checkCpuTime (jvmti, testAgentThread, &prevAgentThreadTime, nullptr , " agent thread" )) {
154
156
nsk_jvmti_setFailStatus ();
155
157
}
@@ -173,6 +175,7 @@ agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
173
175
174
176
NSK_DISPLAY0 (" >>> Testcase #5: Check middle cpu time from agent thread\n " );
175
177
{
178
+ RawMonitorLocker rml (jvmti, jni, monitor);
176
179
julong time = 0 ;
177
180
runIterations (iterations);
178
181
if (!checkCpuTime (jvmti, testAgentThread, &time, &prevAgentThreadTime, " agent thread" )) {
@@ -183,6 +186,7 @@ agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
183
186
if (testedThread != nullptr ) {
184
187
NSK_DISPLAY0 (" >>> Testcase #6: Check tested thread cpu time from agent thread\n " );
185
188
{
189
+ RawMonitorLocker rml (jvmti, jni, monitor);
186
190
julong time = 0 ;
187
191
runIterations (iterations);
188
192
if (!checkCpuTime (jvmti, testedThread, &time, &prevTestedThreadTime, " agent thread" )) {
@@ -224,6 +228,7 @@ agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
224
228
*/
225
229
JNIEXPORT void JNICALL
226
230
callbackVMInit (jvmtiEnv* jvmti, JNIEnv* jni, jthread thread) {
231
+ RawMonitorLocker rml (jvmti, jni, monitor);
227
232
228
233
NSK_DISPLAY0 (" >>> Testcase #1: Check initial cpu time in VM_INIT callback\n " );
229
234
{
@@ -239,6 +244,8 @@ callbackVMInit(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread) {
239
244
*/
240
245
JNIEXPORT void JNICALL
241
246
callbackVMDeath (jvmtiEnv* jvmti, JNIEnv* jni) {
247
+ RawMonitorLocker rml (jvmti, jni, monitor);
248
+
242
249
int success = NSK_TRUE;
243
250
244
251
NSK_DISPLAY1 (" Disable events: %d events\n " , EVENTS_COUNT);
@@ -261,6 +268,7 @@ callbackVMDeath(jvmtiEnv* jvmti, JNIEnv* jni) {
261
268
*/
262
269
JNIEXPORT void JNICALL
263
270
callbackThreadStart (jvmtiEnv* jvmti, JNIEnv* jni, jthread thread) {
271
+ RawMonitorLocker rml (jvmti, jni, monitor);
264
272
265
273
jvmtiThreadInfo threadInfo;
266
274
{
@@ -296,6 +304,7 @@ callbackThreadStart(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread) {
296
304
*/
297
305
JNIEXPORT void JNICALL
298
306
callbackThreadEnd (jvmtiEnv* jvmti, JNIEnv* jni, jthread thread) {
307
+ RawMonitorLocker rml (jvmti, jni, monitor);
299
308
300
309
jvmtiThreadInfo threadInfo;
301
310
{
@@ -389,6 +398,7 @@ jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
389
398
if (nsk_jvmti_enableEvents (JVMTI_ENABLE, EVENTS_COUNT, events, nullptr )) {
390
399
NSK_DISPLAY0 (" ... enabled\n " );
391
400
}
401
+ monitor = create_raw_monitor (jvmti, " Raw monitor for synchronization" );
392
402
393
403
return JNI_OK;
394
404
}
0 commit comments