8266949: Check possibility to disable OperationTimedOut on Unix

Reviewed-by: azvegint, kizune
This commit is contained in:
Sergey Bylokhov 2021-05-18 19:30:33 +00:00
parent b92c5a44f2
commit e6705c0e4b
2 changed files with 20 additions and 23 deletions
src/java.desktop
share/classes/sun/awt
unix/classes/sun/awt/X11

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -1405,15 +1405,6 @@ public abstract class SunToolkit extends Toolkit
|| comp instanceof Window);
}
@SuppressWarnings("serial")
public static class OperationTimedOut extends RuntimeException {
public OperationTimedOut(String msg) {
super(msg);
}
public OperationTimedOut() {
}
}
@SuppressWarnings("serial")
public static class IllegalThreadException extends RuntimeException {
public IllegalThreadException(String msg) {
@ -1431,7 +1422,7 @@ public abstract class SunToolkit extends Toolkit
/**
* Parameterless version of realsync which uses default timout (see DEFAUL_WAIT_TIME).
*/
public void realSync() throws OperationTimedOut {
public void realSync() {
realSync(DEFAULT_WAIT_TIME);
}
@ -1480,7 +1471,7 @@ public abstract class SunToolkit extends Toolkit
*
* @param timeout the maximum time to wait in milliseconds, negative means "forever".
*/
public void realSync(final long timeout) throws OperationTimedOut {
public void realSync(final long timeout) {
if (EventQueue.isDispatchThread()) {
throw new IllegalThreadException("The SunToolkit.realSync() method cannot be used on the event dispatch thread (EDT).");
}
@ -1536,7 +1527,7 @@ public abstract class SunToolkit extends Toolkit
&& bigLoop < MAX_ITERS);
}
private long timeout(long end){
protected long timeout(long end){
return end - TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
}
@ -1566,6 +1557,9 @@ public abstract class SunToolkit extends Toolkit
*/
@SuppressWarnings("serial")
private final boolean waitForIdle(final long end) {
if (timeout(end) <= 0) {
return false;
}
flushPendingEvents();
final boolean queueWasEmpty;
final AtomicBoolean queueEmpty = new AtomicBoolean();

@ -124,6 +124,7 @@ import java.util.Properties;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.Vector;
import java.util.concurrent.TimeUnit;
import javax.swing.LookAndFeel;
import javax.swing.UIDefaults;
@ -2393,7 +2394,7 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
* @inheritDoc
*/
@Override
protected boolean syncNativeQueue(final long timeout) {
protected boolean syncNativeQueue(long timeout) {
if (timeout <= 0) {
return false;
}
@ -2418,31 +2419,33 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
oops_updated = false;
long event_number = getEventNumber();
// Generate OOPS ConfigureNotify event
XlibWrapper.XMoveWindow(getDisplay(), win.getWindow(),
win.scaleUp(++oops_position), 0);
// Change win position each time to avoid system optimization
oops_position += 5;
if (oops_position > 50) {
oops_position = 0;
}
// Generate OOPS ConfigureNotify event
XlibWrapper.XMoveWindow(getDisplay(), win.getWindow(),
oops_position, 0);
XSync();
eventLog.finer("Generated OOPS ConfigureNotify event");
long start = System.currentTimeMillis();
long end = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) + timeout;
// This "while" is a protection from spurious wake-ups.
// However, we shouldn't wait for too long.
while (!oops_updated) {
timeout = timeout(end);
if (timeout <= 0) {
break;
}
try {
// Wait for OOPS ConfigureNotify event
awtLockWait(timeout);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// This "while" is a protection from spurious
// wake-ups. However, we shouldn't wait for too long
if ((System.currentTimeMillis() - start > timeout) && timeout >= 0) {
throw new OperationTimedOut(Long.toString(System.currentTimeMillis() - start));
}
}
// Don't take into account OOPS ConfigureNotify event
return getEventNumber() - event_number > 1;