Skip to content

Commit f937c26

Browse files
authored
Merge pull request #110 from JasonFengJ9/portjdk11pr53
CRIU update TimerTask.nextExecutionTime with checkpointRestoreTimeDelta
2 parents e9f9e07 + 5cfaf66 commit f937c26

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

closed/GensrcJ9JCL.gmk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ $(eval $(call SetupCopyFiles,COPY_OVERLAY_FILES, \
5252
DEST := $(SUPPORT_OUTPUTDIR)/overlay, \
5353
FILES := \
5454
src/java.base/share/classes/java/security/Security.java \
55+
src/java.base/share/classes/java/util/Timer.java \
56+
src/java.base/share/classes/java/util/TimerTask.java \
5557
src/java.base/unix/classes/java/lang/ProcessEnvironment.java \
5658
))
5759

src/java.base/share/classes/java/util/Timer.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,22 @@
2323
* questions.
2424
*/
2525

26+
/*
27+
* ===========================================================================
28+
* (c) Copyright IBM Corp. 2022, 2022 All Rights Reserved
29+
* ===========================================================================
30+
*/
31+
2632
package java.util;
2733
import java.util.Date;
2834
import java.util.concurrent.atomic.AtomicInteger;
2935
import java.lang.ref.Cleaner.Cleanable;
3036
import jdk.internal.ref.CleanerFactory;
3137

38+
/*[IF CRIU_SUPPORT]*/
39+
import openj9.internal.criu.InternalCRIUSupport;
40+
/*[ENDIF] CRIU_SUPPORT*/
41+
3242
/**
3343
* A facility for threads to schedule tasks for future execution in a
3444
* background thread. Tasks may be scheduled for one-time execution, or for
@@ -202,6 +212,12 @@ public Timer(String name, boolean isDaemon) {
202212
public void schedule(TimerTask task, long delay) {
203213
if (delay < 0)
204214
throw new IllegalArgumentException("Negative delay.");
215+
/*[IF CRIU_SUPPORT]*/
216+
// only tasks scheduled before Checkpoint to be adjusted
217+
if (InternalCRIUSupport.getCheckpointRestoreNanoTimeDelta() == 0) {
218+
task.criuAdjustRequired = true;
219+
}
220+
/*[ENDIF] CRIU_SUPPORT*/
205221
sched(task, System.currentTimeMillis()+delay, 0);
206222
}
207223

@@ -257,6 +273,12 @@ public void schedule(TimerTask task, long delay, long period) {
257273
throw new IllegalArgumentException("Negative delay.");
258274
if (period <= 0)
259275
throw new IllegalArgumentException("Non-positive period.");
276+
/*[IF CRIU_SUPPORT]*/
277+
// only tasks scheduled before Checkpoint to be adjusted
278+
if (InternalCRIUSupport.getCheckpointRestoreNanoTimeDelta() == 0) {
279+
task.criuAdjustRequired = true;
280+
}
281+
/*[ENDIF] CRIU_SUPPORT*/
260282
sched(task, System.currentTimeMillis()+delay, -period);
261283
}
262284

@@ -337,6 +359,12 @@ public void scheduleAtFixedRate(TimerTask task, long delay, long period) {
337359
throw new IllegalArgumentException("Negative delay.");
338360
if (period <= 0)
339361
throw new IllegalArgumentException("Non-positive period.");
362+
/*[IF CRIU_SUPPORT]*/
363+
// only tasks scheduled before Checkpoint to be adjusted
364+
if (InternalCRIUSupport.getCheckpointRestoreNanoTimeDelta() == 0) {
365+
task.criuAdjustRequired = true;
366+
}
367+
/*[ENDIF] CRIU_SUPPORT*/
340368
sched(task, System.currentTimeMillis()+delay, period);
341369
}
342370

@@ -547,6 +575,18 @@ private void mainLoop() {
547575
continue; // No action required, poll queue again
548576
}
549577
currentTime = System.currentTimeMillis();
578+
/*[IF CRIU_SUPPORT]*/
579+
if (task.criuAdjustRequired) {
580+
long checkpointRestoreTimeDelta = InternalCRIUSupport.getCheckpointRestoreNanoTimeDelta();
581+
// A zero checkpointRestoreTimeDelta value indicates no Checkpoint performed yet,
582+
// it can't be negative, otherwise a RestoreException already was thrown.
583+
if (checkpointRestoreTimeDelta > 0) {
584+
task.nextExecutionTime += (checkpointRestoreTimeDelta / 1000000);
585+
// clear the flag - only one time adjustment required
586+
task.criuAdjustRequired = false;
587+
}
588+
}
589+
/*[ENDIF] CRIU_SUPPORT*/
550590
executionTime = task.nextExecutionTime;
551591
if (taskFired = (executionTime<=currentTime)) {
552592
if (task.period == 0) { // Non-repeating, remove

src/java.base/share/classes/java/util/TimerTask.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
* questions.
2424
*/
2525

26+
/*
27+
* ===========================================================================
28+
* (c) Copyright IBM Corp. 2022, 2022 All Rights Reserved
29+
* ===========================================================================
30+
*/
31+
2632
package java.util;
2733

2834
/**
@@ -84,6 +90,13 @@ public abstract class TimerTask implements Runnable {
8490
*/
8591
long period = 0;
8692

93+
/*[IF CRIU_SUPPORT]*/
94+
/**
95+
* Determine if the nextExecutionTime is to be adjusted.
96+
*/
97+
boolean criuAdjustRequired;
98+
/*[ENDIF] CRIU_SUPPORT*/
99+
87100
/**
88101
* Creates a new timer task.
89102
*/

0 commit comments

Comments
 (0)