Skip to content

Commit 654ad1c

Browse files
committed
8266949: Check possibility to disable OperationTimedOut on Unix
Backport-of: e6705c0
1 parent d896cda commit 654ad1c

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

src/java.desktop/share/classes/sun/awt/SunToolkit.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1407,15 +1407,6 @@ public static boolean isLightweightOrUnknown(Component comp) {
14071407
|| comp instanceof Window);
14081408
}
14091409

1410-
@SuppressWarnings("serial")
1411-
public static class OperationTimedOut extends RuntimeException {
1412-
public OperationTimedOut(String msg) {
1413-
super(msg);
1414-
}
1415-
public OperationTimedOut() {
1416-
}
1417-
}
1418-
14191410
@SuppressWarnings("serial")
14201411
public static class IllegalThreadException extends RuntimeException {
14211412
public IllegalThreadException(String msg) {
@@ -1433,7 +1424,7 @@ public IllegalThreadException() {
14331424
/**
14341425
* Parameterless version of realsync which uses default timout (see DEFAUL_WAIT_TIME).
14351426
*/
1436-
public void realSync() throws OperationTimedOut {
1427+
public void realSync() {
14371428
realSync(DEFAULT_WAIT_TIME);
14381429
}
14391430

@@ -1482,7 +1473,7 @@ public void realSync() throws OperationTimedOut {
14821473
*
14831474
* @param timeout the maximum time to wait in milliseconds, negative means "forever".
14841475
*/
1485-
public void realSync(final long timeout) throws OperationTimedOut {
1476+
public void realSync(final long timeout) {
14861477
if (EventQueue.isDispatchThread()) {
14871478
throw new IllegalThreadException("The SunToolkit.realSync() method cannot be used on the event dispatch thread (EDT).");
14881479
}
@@ -1538,7 +1529,7 @@ public void realSync(final long timeout) throws OperationTimedOut {
15381529
&& bigLoop < MAX_ITERS);
15391530
}
15401531

1541-
private long timeout(long end){
1532+
protected long timeout(long end){
15421533
return end - TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
15431534
}
15441535

@@ -1568,6 +1559,9 @@ private boolean isEQEmpty() {
15681559
*/
15691560
@SuppressWarnings("serial")
15701561
private final boolean waitForIdle(final long end) {
1562+
if (timeout(end) <= 0) {
1563+
return false;
1564+
}
15711565
flushPendingEvents();
15721566
final boolean queueWasEmpty;
15731567
final AtomicBoolean queueEmpty = new AtomicBoolean();

src/java.desktop/unix/classes/sun/awt/X11/XToolkit.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
import java.util.SortedMap;
127127
import java.util.TreeMap;
128128
import java.util.Vector;
129+
import java.util.concurrent.TimeUnit;
129130

130131
import javax.swing.LookAndFeel;
131132
import javax.swing.UIDefaults;
@@ -2583,7 +2584,7 @@ public static long getEventNumber() {
25832584
* @inheritDoc
25842585
*/
25852586
@Override
2586-
protected boolean syncNativeQueue(final long timeout) {
2587+
protected boolean syncNativeQueue(long timeout) {
25872588
if (timeout <= 0) {
25882589
return false;
25892590
}
@@ -2608,31 +2609,33 @@ public void dispatchEvent(XEvent e) {
26082609

26092610
oops_updated = false;
26102611
long event_number = getEventNumber();
2611-
// Generate OOPS ConfigureNotify event
2612-
XlibWrapper.XMoveWindow(getDisplay(), win.getWindow(),
2613-
win.scaleUp(++oops_position), 0);
26142612
// Change win position each time to avoid system optimization
2613+
oops_position += 5;
26152614
if (oops_position > 50) {
26162615
oops_position = 0;
26172616
}
2617+
// Generate OOPS ConfigureNotify event
2618+
XlibWrapper.XMoveWindow(getDisplay(), win.getWindow(),
2619+
oops_position, 0);
26182620

26192621
XSync();
26202622

26212623
eventLog.finer("Generated OOPS ConfigureNotify event");
26222624

2623-
long start = System.currentTimeMillis();
2625+
long end = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) + timeout;
2626+
// This "while" is a protection from spurious wake-ups.
2627+
// However, we shouldn't wait for too long.
26242628
while (!oops_updated) {
2629+
timeout = timeout(end);
2630+
if (timeout <= 0) {
2631+
break;
2632+
}
26252633
try {
26262634
// Wait for OOPS ConfigureNotify event
26272635
awtLockWait(timeout);
26282636
} catch (InterruptedException e) {
26292637
throw new RuntimeException(e);
26302638
}
2631-
// This "while" is a protection from spurious
2632-
// wake-ups. However, we shouldn't wait for too long
2633-
if ((System.currentTimeMillis() - start > timeout) && timeout >= 0) {
2634-
throw new OperationTimedOut(Long.toString(System.currentTimeMillis() - start));
2635-
}
26362639
}
26372640
// Don't take into account OOPS ConfigureNotify event
26382641
return getEventNumber() - event_number > 1;

0 commit comments

Comments
 (0)