Skip to content

Commit

Permalink
CRIU DeadlockTest adds thread synchronization to keep the lock
Browse files Browse the repository at this point in the history
Ensure the test thread hold the lock while a checkpoint thread attempts
to acquire this lock in the single thread mode;
Also add a few log messages and trace points.

Signed-off-by: Jason Feng <[email protected]>
  • Loading branch information
JasonFengJ9 committed Feb 3, 2025
1 parent 0ab22ee commit 4ba59ba
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion test/functional/cmdLineTests/criu/criu_nonPortable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
</test>

<test id="Create and Restore Criu Checkpoint Image once - CheckpointDeadlock">
<command>bash $SCRIPPATH$ $TEST_RESROOT$ $JAVA_COMMAND$ "$JVM_OPTIONS$ --add-opens java.base/jdk.internal.misc=ALL-UNNAMED $STD_CMD_OPTS$" $MAINCLASS_DEADLOCK_TEST$ CheckpointDeadlock 1 false false</command>
<command>bash $SCRIPPATH$ $TEST_RESROOT$ $JAVA_COMMAND$ "$JVM_OPTIONS$ -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$ CheckpointDeadlock 1 false false</command>
<output type="success" caseSensitive="yes" regex="no">User requested Java dump using</output>
<output type="failure" caseSensitive="yes" regex="no">AOT load and compilation disabled post restore</output>
<output type="success" caseSensitive="yes" regex="no">TEST PASSED</output>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,29 @@ public static void checkpointDeadlock() {
final TestResult testResult = new TestResult(true, 0);

Thread t1 = new Thread(() -> {
CRIUTestUtils.showThreadCurrentTime("checkpointDeadlock.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("checkpointDeadlock.t1 locked with testResult.lockStatus = "
+ testResult.lockStatus.get());
// Hold the lock until the lockStatus value is changed.
while (testResult.lockStatus.get() == 1) {
Thread.yield();
}
}
CRIUTestUtils.showThreadCurrentTime("checkpointDeadlock.t1 finished with testResult.lockStatus = "
+ testResult.lockStatus.get());
});

t1.start();

CRIUSupport criuSupport = new CRIUSupport(path);
criuSupport.registerPreCheckpointHook(() -> {
synchronized (lock) {
System.out.println("Precheckpoint hook inside monitor");
CRIUTestUtils.showThreadCurrentTime("Precheckpoint hook inside monitor with testResult.lockStatus = "
+ testResult.lockStatus.get());
testResult.lockStatus.set(2);
testResult.testPassed = false;
}
});
Expand All @@ -101,7 +108,11 @@ 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);
CRIUTestUtils.showThreadCurrentTime("Post-restore with testResult.lockStatus = "
+ testResult.lockStatus.get());
testResult.testPassed = false;
} catch (JVMCheckpointException e) {
/*
Expand All @@ -122,10 +133,18 @@ public static void checkpointDeadlock() {
at java.base/openj9.internal.criu.InternalCRIUSupport.lambda$registerCheckpointHookHelper$2(InternalCRIUSupport.java:697)
*/
if (!e.getCause().getCause().getMessage().contains("Blocking operation is not allowed in CRIU single thread mode")) {
CRIUTestUtils.showThreadCurrentTime("checkpointDeadlock 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");
Expand Down

0 comments on commit 4ba59ba

Please sign in to comment.