Skip to content

Commit e6705c0

Browse files
committed
8266949: Check possibility to disable OperationTimedOut on Unix
Reviewed-by: azvegint, kizune
1 parent b92c5a4 commit e6705c0

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
@@ -1405,15 +1405,6 @@ public static boolean isLightweightOrUnknown(Component comp) {
14051405
|| comp instanceof Window);
14061406
}
14071407

1408-
@SuppressWarnings("serial")
1409-
public static class OperationTimedOut extends RuntimeException {
1410-
public OperationTimedOut(String msg) {
1411-
super(msg);
1412-
}
1413-
public OperationTimedOut() {
1414-
}
1415-
}
1416-
14171408
@SuppressWarnings("serial")
14181409
public static class IllegalThreadException extends RuntimeException {
14191410
public IllegalThreadException(String msg) {
@@ -1431,7 +1422,7 @@ public IllegalThreadException() {
14311422
/**
14321423
* Parameterless version of realsync which uses default timout (see DEFAUL_WAIT_TIME).
14331424
*/
1434-
public void realSync() throws OperationTimedOut {
1425+
public void realSync() {
14351426
realSync(DEFAULT_WAIT_TIME);
14361427
}
14371428

@@ -1480,7 +1471,7 @@ public void realSync() throws OperationTimedOut {
14801471
*
14811472
* @param timeout the maximum time to wait in milliseconds, negative means "forever".
14821473
*/
1483-
public void realSync(final long timeout) throws OperationTimedOut {
1474+
public void realSync(final long timeout) {
14841475
if (EventQueue.isDispatchThread()) {
14851476
throw new IllegalThreadException("The SunToolkit.realSync() method cannot be used on the event dispatch thread (EDT).");
14861477
}
@@ -1536,7 +1527,7 @@ public void realSync(final long timeout) throws OperationTimedOut {
15361527
&& bigLoop < MAX_ITERS);
15371528
}
15381529

1539-
private long timeout(long end){
1530+
protected long timeout(long end){
15401531
return end - TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
15411532
}
15421533

@@ -1566,6 +1557,9 @@ private boolean isEQEmpty() {
15661557
*/
15671558
@SuppressWarnings("serial")
15681559
private final boolean waitForIdle(final long end) {
1560+
if (timeout(end) <= 0) {
1561+
return false;
1562+
}
15691563
flushPendingEvents();
15701564
final boolean queueWasEmpty;
15711565
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
@@ -124,6 +124,7 @@
124124
import java.util.SortedMap;
125125
import java.util.TreeMap;
126126
import java.util.Vector;
127+
import java.util.concurrent.TimeUnit;
127128

128129
import javax.swing.LookAndFeel;
129130
import javax.swing.UIDefaults;
@@ -2393,7 +2394,7 @@ public static long getEventNumber() {
23932394
* @inheritDoc
23942395
*/
23952396
@Override
2396-
protected boolean syncNativeQueue(final long timeout) {
2397+
protected boolean syncNativeQueue(long timeout) {
23972398
if (timeout <= 0) {
23982399
return false;
23992400
}
@@ -2418,31 +2419,33 @@ public void dispatchEvent(XEvent e) {
24182419

24192420
oops_updated = false;
24202421
long event_number = getEventNumber();
2421-
// Generate OOPS ConfigureNotify event
2422-
XlibWrapper.XMoveWindow(getDisplay(), win.getWindow(),
2423-
win.scaleUp(++oops_position), 0);
24242422
// Change win position each time to avoid system optimization
2423+
oops_position += 5;
24252424
if (oops_position > 50) {
24262425
oops_position = 0;
24272426
}
2427+
// Generate OOPS ConfigureNotify event
2428+
XlibWrapper.XMoveWindow(getDisplay(), win.getWindow(),
2429+
oops_position, 0);
24282430

24292431
XSync();
24302432

24312433
eventLog.finer("Generated OOPS ConfigureNotify event");
24322434

2433-
long start = System.currentTimeMillis();
2435+
long end = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) + timeout;
2436+
// This "while" is a protection from spurious wake-ups.
2437+
// However, we shouldn't wait for too long.
24342438
while (!oops_updated) {
2439+
timeout = timeout(end);
2440+
if (timeout <= 0) {
2441+
break;
2442+
}
24352443
try {
24362444
// Wait for OOPS ConfigureNotify event
24372445
awtLockWait(timeout);
24382446
} catch (InterruptedException e) {
24392447
throw new RuntimeException(e);
24402448
}
2441-
// This "while" is a protection from spurious
2442-
// wake-ups. However, we shouldn't wait for too long
2443-
if ((System.currentTimeMillis() - start > timeout) && timeout >= 0) {
2444-
throw new OperationTimedOut(Long.toString(System.currentTimeMillis() - start));
2445-
}
24462449
}
24472450
// Don't take into account OOPS ConfigureNotify event
24482451
return getEventNumber() - event_number > 1;

0 commit comments

Comments
 (0)