Skip to content

Commit 334a1ee

Browse files
committed
8351375: nsk/jvmti/ tests should fail when nsk_jvmti_setFailStatus() is called
Reviewed-by: sspitsyn, cjplummer
1 parent 7442039 commit 334a1ee

File tree

5 files changed

+51
-24
lines changed

5 files changed

+51
-24
lines changed

test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass029/redefclass029.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 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
@@ -97,6 +97,16 @@ CompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size,
9797
const void* compile_info) {
9898
char *name;
9999
char *sig;
100+
jvmtiPhase phase;
101+
102+
if (!NSK_JVMTI_VERIFY(jvmti_env->GetPhase(&phase))) {
103+
nsk_jvmti_setFailStatus();
104+
return;
105+
}
106+
if (phase == JVMTI_PHASE_DEAD) {
107+
NSK_DISPLAY0("CompiledMethodLoad event recieved in dead phase");
108+
return;
109+
}
100110

101111
NSK_DISPLAY0("CompiledMethodLoad event received for:\n");
102112
if (!NSK_JVMTI_VERIFY(jvmti_env->GetMethodName(method, &name, &sig, nullptr))) {

test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM04/em04t001/em04t001.cpp

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 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
@@ -116,6 +116,18 @@ cbDynamicCodeGenerated2(jvmtiEnv *jvmti_env, const char *name,
116116
NSK_DISPLAY3("NOT FOUND: 0x%p %7d %s\n", address, length, name);
117117
jvmti->RawMonitorExit(syncLock);
118118

119+
}
120+
121+
void JNICALL
122+
cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) {
123+
if (!NSK_VERIFY(nsk_list_destroy(plist))) {
124+
nsk_jvmti_setFailStatus();
125+
}
126+
127+
if (!NSK_JVMTI_VERIFY(jvmti->DestroyRawMonitor(syncLock))) {
128+
nsk_jvmti_setFailStatus();
129+
}
130+
119131
}
120132

121133
/* ============================================================================= */
@@ -135,6 +147,7 @@ int setCallBacks(int stage) {
135147
jvmtiEventCallbacks eventCallbacks;
136148
memset(&eventCallbacks, 0, sizeof(eventCallbacks));
137149

150+
eventCallbacks.VMDeath = cbVMDeath;
138151
eventCallbacks.DynamicCodeGenerated = (stage == 1) ?
139152
cbDynamicCodeGenerated1 : cbDynamicCodeGenerated2;
140153

@@ -242,23 +255,4 @@ jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
242255
return JNI_OK;
243256
}
244257

245-
/* ============================================================================= */
246-
247-
JNIEXPORT void JNICALL
248-
#ifdef STATIC_BUILD
249-
Agent_OnUnload_em04t001(JavaVM *jvm)
250-
#else
251-
Agent_OnUnload(JavaVM *jvm)
252-
#endif
253-
{
254-
255-
if (!NSK_VERIFY(nsk_list_destroy(plist))) {
256-
nsk_jvmti_setFailStatus();
257-
}
258-
259-
if (!NSK_JVMTI_VERIFY(jvmti->DestroyRawMonitor(syncLock))) {
260-
nsk_jvmti_setFailStatus();
261-
}
262-
}
263-
264258
}

test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t006/ma10t006.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 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
@@ -51,9 +51,18 @@ CompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method,
5151
const jvmtiAddrLocationMap* map, const void* compile_info) {
5252
char *name = nullptr;
5353
char *signature = nullptr;
54+
jvmtiPhase phase;
5455

5556
CompiledMethodLoadEventsCount++;
5657

58+
if (!NSK_JVMTI_VERIFY(jvmti_env->GetPhase(&phase))) {
59+
nsk_jvmti_setFailStatus();
60+
return;
61+
}
62+
if (phase == JVMTI_PHASE_DEAD) {
63+
NSK_DISPLAY0("CompiledMethodLoad event recieved in dead phase");
64+
return;
65+
}
5766
if (!NSK_JVMTI_VERIFY(jvmti_env->GetMethodName(method, &name, &signature, nullptr))) {
5867
nsk_jvmti_setFailStatus();
5968
return;

test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/agent_tools.cpp

Lines changed: 5 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
@@ -21,6 +21,7 @@
2121
* questions.
2222
*/
2323

24+
#include <stdio.h>
2425
#include <stdlib.h>
2526
#include <string.h>
2627

@@ -62,6 +63,9 @@ static volatile int currentAgentStatus = NSK_STATUS_PASSED;
6263

6364
void nsk_jvmti_setFailStatus() {
6465
currentAgentStatus = NSK_STATUS_FAILED;
66+
printf("Test failed by setFailStatus(). See log.");
67+
fflush(stdout);
68+
exit(97);
6569
}
6670

6771
int nsk_jvmti_isFailStatus() {

test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/hotswap/HotSwap.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 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
@@ -141,9 +141,19 @@ CompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method,
141141
const jvmtiAddrLocationMap* map, const void* compile_info) {
142142
char *name = nullptr;
143143
char *signature = nullptr;
144+
jvmtiPhase phase;
144145

145146
CompiledMethodLoadEventsCount++;
146147

148+
// GetMethodName works in live phase only so just exit if the event is generated too late
149+
if (!NSK_JVMTI_VERIFY(jvmti_env->GetPhase(&phase))) {
150+
nsk_jvmti_setFailStatus();
151+
return;
152+
}
153+
if (phase == JVMTI_PHASE_DEAD) {
154+
NSK_DISPLAY0("CompiledMethodLoad event recieved in dead phase");
155+
return;
156+
}
147157
if (!NSK_JVMTI_VERIFY(jvmti_env->GetMethodName(method, &name, &signature, nullptr))) {
148158
nsk_jvmti_setFailStatus();
149159
return;

0 commit comments

Comments
 (0)