eclipse-openj9 / openj9

Eclipse OpenJ9: A Java Virtual Machine for OpenJDK that's optimized for small footprint, fast start-up, and high throughput. Builds on Eclipse OMR (https://github.com/eclipse/omr) and combines with the Extensions for OpenJDK for OpenJ9 repo.
Other
3.28k stars 721 forks source link

Add testing for VM marking exit started too early #10326

Open DanHeidinga opened 4 years ago

DanHeidinga commented 4 years ago

I have no idea how to add tests that aren't in the JVMTI framework (which isn't appropriate here), so I suggest merging this and opening a new issue to get the test added.

For the record, I modified the test to use wait/notify rather than the latch (which doesn't exist in java 8). This isn't realiable enough to put into an automated test, so perhaps the original test should be added for JDK11+.

Originally posted by @gacholio in https://github.com/eclipse/openj9/pull/10273#issuecomment-665722821

gacholio commented 4 years ago

If it's important to add to Java 8, a properly crafted wait/notify solution could be produced. The issue with just using wait/notify without protecting a state variable is that the notify could be lost (if the main thread notifies before the daemon gets into wait, the daemon would not exit).

The test should not depend on the exit code, as the main thread may well win the race to shut the VM down, depending on thread scheduling.

gacholio commented 4 years ago

Original test code:

public class Launchee {
    public static void main(String[] args) throws Exception {
        final CountDownLatch latch = new CountDownLatch(1);
        Thread t = new Thread() {
            @Override
            public void run() {
                latch.countDown();
                System.exit(1);
            }
        };
        t.setDaemon(true);
        t.start();
        latch.await();
    }
}