-
Bug
-
Resolution: Fixed
-
P3
-
21
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8309839 | 22 | Martin Doerr | P3 | Resolved | Fixed | b02 |
JDK-8323753 | 17.0.11 | Sergey Bylokhov | P3 | Resolved | Fixed | b01 |
JDK-8323758 | 11.0.23 | Sergey Bylokhov | P3 | Resolved | Fixed | b01 |
The xlc17 compiler is doing so, and IBM claims that they are following the standard and will not fix this on compiler side.
So we have (at least) 3 ways to circumvent this behavior.
1. We can introduce the call of a nop library function, which will hinder the optimizer to throw away the loop (This is our proposed solution, but instead of a heavy looping thread, the result is a more or less idle thread):
#include <unistd.h>
static void
sys_thread_3(jvmtiEnv* jvmti, JNIEnv* jni, void *p)
{
while (1) {
sleep(1);
}
}
2. We can make use of a volatile variable in the loop body which also hinders the optimizer to throw away the loop:
static void
sys_thread_3(jvmtiEnv* jvmti, JNIEnv* jni, void *p)
{
volatile int i = 1;
while (i) {
i += 2;
}
}
3. We can use the __attribute__ ((optnone)) modifier in the function declaration to suppress the optimization at all:
static void
sys_thread_3(jvmtiEnv* jvmti, JNIEnv* jni, void *p) __attribute__ ((optnone))
{
while (1) {
}
}
To make the third approach platform independent, we can implement it in the following way:
In globalDefinitions.hpp
#ifndef OPTNONE
#define OPTNONE
#endif
In globalDefinitions_xlc.hpp
// optnone support
//
// To use if a function should not be optimized
// Usage:
// void* func(size_t size) OPTNONE {...}
#define OPTNONE __attribute__(( optnone))
With this we can change libagentthr001.cpp in a platform independent way to
static void
sys_thread_3(jvmtiEnv* jvmti, JNIEnv* jni, void *p) OPTNONE
{
while (1) {
}
}
- backported by
-
JDK-8309839 [AIX] vmTestbase/nsk/jvmti/RunAgentThread/agentthr001/TestDescription.java crashing due to empty while loop
-
- Resolved
-
-
JDK-8323753 [AIX] vmTestbase/nsk/jvmti/RunAgentThread/agentthr001/TestDescription.java crashing due to empty while loop
-
- Resolved
-
-
JDK-8323758 [AIX] vmTestbase/nsk/jvmti/RunAgentThread/agentthr001/TestDescription.java crashing due to empty while loop
-
- Resolved
-
- links to
-
Commit openjdk/jdk11u-dev/1f3c7d58
-
Commit openjdk/jdk17u-dev/2ca591e1
-
Commit openjdk/jdk21/08eff92b
-
Commit openjdk/jdk/cf9e6353
-
Review openjdk/jdk11u-dev/2457
-
Review openjdk/jdk17u-dev/2125
-
Review openjdk/jdk21/9
-
Review openjdk/jdk/14330