Skip to content

Commit b783173

Browse files
author
Satyen Subramaniam
committed
8332857: Test vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime002/TestDescription.java failed
Backport-of: 6ef860c728d3f2f29fe8f7318c0f56032e0679be
1 parent da71a5c commit b783173

File tree

1 file changed

+11
-1
lines changed
  • test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime002

1 file changed

+11
-1
lines changed

test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime002/thrcputime002.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -33,6 +33,7 @@ extern "C" {
3333
/* ============================================================================= */
3434

3535
static jlong timeout = 0;
36+
static jrawMonitorID monitor; // a monitor to serialize event callbacks and checkCpuTime calls
3637

3738
#define TESTED_THREAD_NAME "thrcputime002Thread"
3839

@@ -150,6 +151,7 @@ agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
150151

151152
NSK_DISPLAY0(">>> Testcase #2: Check initial cpu time in agent thread\n");
152153
{
154+
RawMonitorLocker rml(jvmti, jni, monitor);
153155
if (!checkCpuTime(jvmti, testAgentThread, &prevAgentThreadTime, nullptr, "agent thread")) {
154156
nsk_jvmti_setFailStatus();
155157
}
@@ -173,6 +175,7 @@ agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
173175

174176
NSK_DISPLAY0(">>> Testcase #5: Check middle cpu time from agent thread\n");
175177
{
178+
RawMonitorLocker rml(jvmti, jni, monitor);
176179
julong time = 0;
177180
runIterations(iterations);
178181
if (!checkCpuTime(jvmti, testAgentThread, &time, &prevAgentThreadTime, "agent thread")) {
@@ -183,6 +186,7 @@ agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
183186
if (testedThread != nullptr) {
184187
NSK_DISPLAY0(">>> Testcase #6: Check tested thread cpu time from agent thread\n");
185188
{
189+
RawMonitorLocker rml(jvmti, jni, monitor);
186190
julong time = 0;
187191
runIterations(iterations);
188192
if (!checkCpuTime(jvmti, testedThread, &time, &prevTestedThreadTime, "agent thread")) {
@@ -224,6 +228,7 @@ agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
224228
*/
225229
JNIEXPORT void JNICALL
226230
callbackVMInit(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread) {
231+
RawMonitorLocker rml(jvmti, jni, monitor);
227232

228233
NSK_DISPLAY0(">>> Testcase #1: Check initial cpu time in VM_INIT callback\n");
229234
{
@@ -239,6 +244,8 @@ callbackVMInit(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread) {
239244
*/
240245
JNIEXPORT void JNICALL
241246
callbackVMDeath(jvmtiEnv* jvmti, JNIEnv* jni) {
247+
RawMonitorLocker rml(jvmti, jni, monitor);
248+
242249
int success = NSK_TRUE;
243250

244251
NSK_DISPLAY1("Disable events: %d events\n", EVENTS_COUNT);
@@ -261,6 +268,7 @@ callbackVMDeath(jvmtiEnv* jvmti, JNIEnv* jni) {
261268
*/
262269
JNIEXPORT void JNICALL
263270
callbackThreadStart(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread) {
271+
RawMonitorLocker rml(jvmti, jni, monitor);
264272

265273
jvmtiThreadInfo threadInfo;
266274
{
@@ -296,6 +304,7 @@ callbackThreadStart(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread) {
296304
*/
297305
JNIEXPORT void JNICALL
298306
callbackThreadEnd(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread) {
307+
RawMonitorLocker rml(jvmti, jni, monitor);
299308

300309
jvmtiThreadInfo threadInfo;
301310
{
@@ -389,6 +398,7 @@ jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
389398
if (nsk_jvmti_enableEvents(JVMTI_ENABLE, EVENTS_COUNT, events, nullptr)) {
390399
NSK_DISPLAY0(" ... enabled\n");
391400
}
401+
monitor = create_raw_monitor(jvmti, "Raw monitor for synchronization");
392402

393403
return JNI_OK;
394404
}

0 commit comments

Comments
 (0)