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

Commit 803cd33

Browse files
author
Yuri Nesterenko
committed
8266949: Check possibility to disable OperationTimedOut on Unix
Backport-of: e6705c0e4b548a83197c3ea70bdef25ec65d4c00
1 parent b940e5d commit 803cd33

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;
@@ -2587,7 +2588,7 @@ public static long getEventNumber() {
25872588
* @inheritDoc
25882589
*/
25892590
@Override
2590-
protected boolean syncNativeQueue(final long timeout) {
2591+
protected boolean syncNativeQueue(long timeout) {
25912592
if (timeout <= 0) {
25922593
return false;
25932594
}
@@ -2612,31 +2613,33 @@ public void dispatchEvent(XEvent e) {
26122613

26132614
oops_updated = false;
26142615
long event_number = getEventNumber();
2615-
// Generate OOPS ConfigureNotify event
2616-
XlibWrapper.XMoveWindow(getDisplay(), win.getWindow(),
2617-
win.scaleUp(++oops_position), 0);
26182616
// Change win position each time to avoid system optimization
2617+
oops_position += 5;
26192618
if (oops_position > 50) {
26202619
oops_position = 0;
26212620
}
2621+
// Generate OOPS ConfigureNotify event
2622+
XlibWrapper.XMoveWindow(getDisplay(), win.getWindow(),
2623+
oops_position, 0);
26222624

26232625
XSync();
26242626

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

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

0 commit comments

Comments
 (0)