|
23 | 23 | * questions. |
24 | 24 | */ |
25 | 25 |
|
| 26 | +/* |
| 27 | + * =========================================================================== |
| 28 | + * (c) Copyright IBM Corp. 2022, 2022 All Rights Reserved |
| 29 | + * =========================================================================== |
| 30 | + */ |
| 31 | + |
26 | 32 | package java.util; |
27 | 33 | import java.util.Date; |
28 | 34 | import java.util.concurrent.atomic.AtomicInteger; |
29 | 35 | import java.lang.ref.Cleaner.Cleanable; |
30 | 36 | import jdk.internal.ref.CleanerFactory; |
31 | 37 |
|
| 38 | +/*[IF CRIU_SUPPORT]*/ |
| 39 | +import openj9.internal.criu.InternalCRIUSupport; |
| 40 | +/*[ENDIF] CRIU_SUPPORT*/ |
| 41 | + |
32 | 42 | /** |
33 | 43 | * A facility for threads to schedule tasks for future execution in a |
34 | 44 | * background thread. Tasks may be scheduled for one-time execution, or for |
@@ -202,6 +212,12 @@ public Timer(String name, boolean isDaemon) { |
202 | 212 | public void schedule(TimerTask task, long delay) { |
203 | 213 | if (delay < 0) |
204 | 214 | 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*/ |
205 | 221 | sched(task, System.currentTimeMillis()+delay, 0); |
206 | 222 | } |
207 | 223 |
|
@@ -257,6 +273,12 @@ public void schedule(TimerTask task, long delay, long period) { |
257 | 273 | throw new IllegalArgumentException("Negative delay."); |
258 | 274 | if (period <= 0) |
259 | 275 | 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*/ |
260 | 282 | sched(task, System.currentTimeMillis()+delay, -period); |
261 | 283 | } |
262 | 284 |
|
@@ -337,6 +359,12 @@ public void scheduleAtFixedRate(TimerTask task, long delay, long period) { |
337 | 359 | throw new IllegalArgumentException("Negative delay."); |
338 | 360 | if (period <= 0) |
339 | 361 | 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*/ |
340 | 368 | sched(task, System.currentTimeMillis()+delay, period); |
341 | 369 | } |
342 | 370 |
|
@@ -547,6 +575,18 @@ private void mainLoop() { |
547 | 575 | continue; // No action required, poll queue again |
548 | 576 | } |
549 | 577 | 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*/ |
550 | 590 | executionTime = task.nextExecutionTime; |
551 | 591 | if (taskFired = (executionTime<=currentTime)) { |
552 | 592 | if (task.period == 0) { // Non-repeating, remove |
|
0 commit comments