01-02-2011, 07:23 AM
Orphis is right, it should be declared volatile. The problem is actually due to optimizations done by the JIT Server Compiler such as variable caching which causes the infinite while loop, so it's not a bug but inappropriate optimization done by the JIT Server Compiler. This kind of optimization is not done in the JIT Client Compiler so that's why it works in the 32-bit Client JVM without being declared volatile.
So, the proper fix should be to change the declaration of saveListSelected on line 329 to:
protected volatile boolean saveListSelected;
and maybe clean up the while loop on line 788 as follows:
// Wait for user selection.
while (!saveListSelected && mainDisplay.isVisible()) {
// Do nothing.
}
However, it seems that there's no need to check the state of saveListSelected at all in the while loop. We need to leave the loop regardless of the state of saveListSelected since the user can just close the dialog or click the Cancel button. We only need to check whether mainDisplay is visible and exit the loop when it's no longer visible. So, the proper loop should be:
// Wait for user selection.
while (mainDisplay.isVisible()) {
// Do nothing.
}
The above works in the 32-bit Client JVM, but hangs with the JIT Server Compiler due to inappropriate optimization. Adding a sleep delay inside the while loop is still a valid workaround here, and also saves the CPU from doing unnecessary constant polling.
So, I propose the following while loop:
// Wait for user selection.
while (mainDisplay.isVisible()) {
try {
Thread.sleep(250);
} catch (InterruptedException ex) {}
}
Comments and corrections are very welcome. I learn something new everyday by playing with Jpcsp.
So, the proper fix should be to change the declaration of saveListSelected on line 329 to:
protected volatile boolean saveListSelected;
and maybe clean up the while loop on line 788 as follows:
// Wait for user selection.
while (!saveListSelected && mainDisplay.isVisible()) {
// Do nothing.
}
However, it seems that there's no need to check the state of saveListSelected at all in the while loop. We need to leave the loop regardless of the state of saveListSelected since the user can just close the dialog or click the Cancel button. We only need to check whether mainDisplay is visible and exit the loop when it's no longer visible. So, the proper loop should be:
// Wait for user selection.
while (mainDisplay.isVisible()) {
// Do nothing.
}
The above works in the 32-bit Client JVM, but hangs with the JIT Server Compiler due to inappropriate optimization. Adding a sleep delay inside the while loop is still a valid workaround here, and also saves the CPU from doing unnecessary constant polling.
So, I propose the following while loop:
// Wait for user selection.
while (mainDisplay.isVisible()) {
try {
Thread.sleep(250);
} catch (InterruptedException ex) {}
}
Comments and corrections are very welcome. I learn something new everyday by playing with Jpcsp.