Skip to content

Commit 4ba59ba

Browse files
committed
CRIU DeadlockTest adds thread synchronization to keep the lock
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]>
1 parent 0ab22ee commit 4ba59ba

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

test/functional/cmdLineTests/criu/criu_nonPortable.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@
273273
</test>
274274

275275
<test id="Create and Restore Criu Checkpoint Image once - CheckpointDeadlock">
276-
<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>
276+
<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>
277277
<output type="success" caseSensitive="yes" regex="no">User requested Java dump using</output>
278278
<output type="failure" caseSensitive="yes" regex="no">AOT load and compilation disabled post restore</output>
279279
<output type="success" caseSensitive="yes" regex="no">TEST PASSED</output>

test/functional/cmdLineTests/criu/src/org/openj9/criu/DeadlockTest.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,29 @@ public static void checkpointDeadlock() {
7575
final TestResult testResult = new TestResult(true, 0);
7676

7777
Thread t1 = new Thread(() -> {
78+
CRIUTestUtils.showThreadCurrentTime("checkpointDeadlock.t1 started with testResult.lockStatus = "
79+
+ testResult.lockStatus.get());
7880
synchronized (lock) {
7981
testResult.lockStatus.set(1);
80-
try {
81-
Thread.sleep(20000);
82-
} catch (InterruptedException e) {
83-
e.printStackTrace();
82+
CRIUTestUtils.showThreadCurrentTime("checkpointDeadlock.t1 locked with testResult.lockStatus = "
83+
+ testResult.lockStatus.get());
84+
// Hold the lock until the lockStatus value is changed.
85+
while (testResult.lockStatus.get() == 1) {
86+
Thread.yield();
8487
}
8588
}
89+
CRIUTestUtils.showThreadCurrentTime("checkpointDeadlock.t1 finished with testResult.lockStatus = "
90+
+ testResult.lockStatus.get());
8691
});
8792

8893
t1.start();
8994

9095
CRIUSupport criuSupport = new CRIUSupport(path);
9196
criuSupport.registerPreCheckpointHook(() -> {
9297
synchronized (lock) {
93-
System.out.println("Precheckpoint hook inside monitor");
98+
CRIUTestUtils.showThreadCurrentTime("Precheckpoint hook inside monitor with testResult.lockStatus = "
99+
+ testResult.lockStatus.get());
100+
testResult.lockStatus.set(2);
94101
testResult.testPassed = false;
95102
}
96103
});
@@ -101,7 +108,11 @@ public static void checkpointDeadlock() {
101108

102109
try {
103110
System.out.println("Pre-checkpoint");
111+
CRIUTestUtils.showThreadCurrentTime("Pre-checkpoint with testResult.lockStatus = "
112+
+ testResult.lockStatus.get());
104113
CRIUTestUtils.checkPointJVM(criuSupport, path, true);
114+
CRIUTestUtils.showThreadCurrentTime("Post-restore with testResult.lockStatus = "
115+
+ testResult.lockStatus.get());
105116
testResult.testPassed = false;
106117
} catch (JVMCheckpointException e) {
107118
/*
@@ -122,10 +133,18 @@ public static void checkpointDeadlock() {
122133
at java.base/openj9.internal.criu.InternalCRIUSupport.lambda$registerCheckpointHookHelper$2(InternalCRIUSupport.java:697)
123134
*/
124135
if (!e.getCause().getCause().getMessage().contains("Blocking operation is not allowed in CRIU single thread mode")) {
136+
CRIUTestUtils.showThreadCurrentTime("checkpointDeadlock test failed with testResult.lockStatus = "
137+
+ testResult.lockStatus.get());
125138
testResult.testPassed = false;
126139
e.printStackTrace();
127140
}
128141
}
142+
testResult.lockStatus.set(3);
143+
try {
144+
t1.join();
145+
} catch (InterruptedException e) {
146+
e.printStackTrace();
147+
}
129148

130149
if (testResult.testPassed) {
131150
System.out.println("TEST PASSED");

0 commit comments

Comments
 (0)