From 5b5d14ede69bad467102fb7b08a69f58895e4430 Mon Sep 17 00:00:00 2001 From: Jason Feng Date: Mon, 10 Feb 2025 11:25:51 -0500 Subject: [PATCH] CRIU DeadlockTest adds thread synchronization to prevent premature exit Ensure a test thread with @NotCheckpointSafe running while another thread attempts to checkpoint in the single thread mode; Also add a few log messages and trace points. Signed-off-by: Jason Feng --- .../cmdLineTests/criu/criu_nonPortable.xml | 2 +- .../src/org/openj9/criu/DeadlockTest.java | 26 ++++++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/test/functional/cmdLineTests/criu/criu_nonPortable.xml b/test/functional/cmdLineTests/criu/criu_nonPortable.xml index d6abeac0917..c10edd67936 100644 --- a/test/functional/cmdLineTests/criu/criu_nonPortable.xml +++ b/test/functional/cmdLineTests/criu/criu_nonPortable.xml @@ -291,7 +291,7 @@ - bash $SCRIPPATH$ $TEST_RESROOT$ $JAVA_COMMAND$ "$JVM_OPTIONS$ -XX:+ThrowOnDelayedCheckpointOperation -Xtrace:print=j9vm.731 --add-opens java.base/jdk.internal.misc=ALL-UNNAMED $STD_CMD_OPTS$" $MAINCLASS_DEADLOCK_TEST$ NotCheckpointSafeDeadlock 1 false false + bash $SCRIPPATH$ $TEST_RESROOT$ $JAVA_COMMAND$ "$JVM_OPTIONS$ -XX:+ThrowOnDelayedCheckpointOperation -Xtrace:print={j9jcl.533,j9vm.684-696,j9vm.699,j9vm.717-743} --add-opens java.base/jdk.internal.misc=ALL-UNNAMED $STD_CMD_OPTS$" $MAINCLASS_DEADLOCK_TEST$ NotCheckpointSafeDeadlock 1 false false User requested Java dump using AOT load and compilation disabled post restore TEST PASSED diff --git a/test/functional/cmdLineTests/criu/src/org/openj9/criu/DeadlockTest.java b/test/functional/cmdLineTests/criu/src/org/openj9/criu/DeadlockTest.java index da70721d58d..08f4078cd8a 100644 --- a/test/functional/cmdLineTests/criu/src/org/openj9/criu/DeadlockTest.java +++ b/test/functional/cmdLineTests/criu/src/org/openj9/criu/DeadlockTest.java @@ -107,7 +107,6 @@ public static void checkpointDeadlock() { } try { - System.out.println("Pre-checkpoint"); CRIUTestUtils.showThreadCurrentTime("Pre-checkpoint with testResult.lockStatus = " + testResult.lockStatus.get()); CRIUTestUtils.checkPointJVM(criuSupport, path, true); @@ -161,14 +160,16 @@ public static void notCheckpointSafeDeadlock() { Thread t1 = new Thread(() -> { Runnable run = () -> { + CRIUTestUtils.showThreadCurrentTime("notCheckpointSafeDeadlock.t1 started with testResult.lockStatus = " + + testResult.lockStatus.get()); synchronized (lock) { testResult.lockStatus.set(1); - try { - Thread.sleep(20000); - } catch (InterruptedException e) { - e.printStackTrace(); + CRIUTestUtils.showThreadCurrentTime("notCheckpointSafeDeadlock.t1 locked with testResult.lockStatus = " + + testResult.lockStatus.get()); + // Wait until the lockStatus value is changed. + while (testResult.lockStatus.get() == 1) { + Thread.yield(); } - } }; @@ -184,15 +185,26 @@ public static void notCheckpointSafeDeadlock() { } try { - System.out.println("Pre-checkpoint"); + CRIUTestUtils.showThreadCurrentTime("Pre-checkpoint with testResult.lockStatus = " + + testResult.lockStatus.get()); CRIUTestUtils.checkPointJVM(criuSupport, path, true); + CRIUTestUtils.showThreadCurrentTime("Post-restore with testResult.lockStatus = " + + testResult.lockStatus.get()); testResult.testPassed = false; } catch (JVMCheckpointException e) { if (!e.getMessage().contains("The JVM attempted to checkpoint but was unable to due to code being executed")) { + CRIUTestUtils.showThreadCurrentTime("notCheckpointSafeDeadlock test failed with testResult.lockStatus = " + + testResult.lockStatus.get()); testResult.testPassed = false; e.printStackTrace(); } } + testResult.lockStatus.set(3); + try { + t1.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } if (testResult.testPassed) { System.out.println("TEST PASSED");