Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 48f53ef

Browse files
author
Yuri Nesterenko
committed
8266949: Check possibility to disable OperationTimedOut on Unix
Backport-of: e6705c0e4b548a83197c3ea70bdef25ec65d4c00
1 parent d17731b commit 48f53ef

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
@@ -125,6 +125,7 @@
125125
import java.util.SortedMap;
126126
import java.util.TreeMap;
127127
import java.util.Vector;
128+
import java.util.concurrent.TimeUnit;
128129

129130
import javax.swing.LookAndFeel;
130131
import javax.swing.UIDefaults;
@@ -2588,7 +2589,7 @@ public static long getEventNumber() {
25882589
* @inheritDoc
25892590
*/
25902591
@Override
2591-
protected boolean syncNativeQueue(final long timeout) {
2592+
protected boolean syncNativeQueue(long timeout) {
25922593
if (timeout <= 0) {
25932594
return false;
25942595
}
@@ -2613,31 +2614,33 @@ public void dispatchEvent(XEvent e) {
26132614

26142615
oops_updated = false;
26152616
long event_number = getEventNumber();
2616-
// Generate OOPS ConfigureNotify event
2617-
XlibWrapper.XMoveWindow(getDisplay(), win.getWindow(),
2618-
win.scaleUp(++oops_position), 0);
26192617
// Change win position each time to avoid system optimization
2618+
oops_position += 5;
26202619
if (oops_position > 50) {
26212620
oops_position = 0;
26222621
}
2622+
// Generate OOPS ConfigureNotify event
2623+
XlibWrapper.XMoveWindow(getDisplay(), win.getWindow(),
2624+
oops_position, 0);
26232625

26242626
XSync();
26252627

26262628
eventLog.finer("Generated OOPS ConfigureNotify event");
26272629

2628-
long start = System.currentTimeMillis();
2630+
long end = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) + timeout;
2631+
// This "while" is a protection from spurious wake-ups.
2632+
// However, we shouldn't wait for too long.
26292633
while (!oops_updated) {
2634+
timeout = timeout(end);
2635+
if (timeout <= 0) {
2636+
break;
2637+
}
26302638
try {
26312639
// Wait for OOPS ConfigureNotify event
26322640
awtLockWait(timeout);
26332641
} catch (InterruptedException e) {
26342642
throw new RuntimeException(e);
26352643
}
2636-
// This "while" is a protection from spurious
2637-
// wake-ups. However, we shouldn't wait for too long
2638-
if ((System.currentTimeMillis() - start > timeout) && timeout >= 0) {
2639-
throw new OperationTimedOut(Long.toString(System.currentTimeMillis() - start));
2640-
}
26412644
}
26422645
// Don't take into account OOPS ConfigureNotify event
26432646
return getEventNumber() - event_number > 1;

0 commit comments

Comments
 (0)