Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8266949: Check possibility to disable OperationTimedOut on Unix #4038

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions src/java.desktop/share/classes/sun/awt/SunToolkit.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -1405,15 +1405,6 @@ public static boolean isLightweightOrUnknown(Component comp) {
|| 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) {
Expand All @@ -1431,7 +1422,7 @@ public IllegalThreadException() {
/**
* Parameterless version of realsync which uses default timout (see DEFAUL_WAIT_TIME).
*/
public void realSync() throws OperationTimedOut {
public void realSync() {
realSync(DEFAULT_WAIT_TIME);
}

Expand Down Expand Up @@ -1480,7 +1471,7 @@ public void realSync() throws OperationTimedOut {
*
* @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).");
}
Expand Down Expand Up @@ -1536,7 +1527,7 @@ public void realSync(final long timeout) throws OperationTimedOut {
&& bigLoop < MAX_ITERS);
}

private long timeout(long end){
protected long timeout(long end){
return end - TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
}

Expand Down Expand Up @@ -1566,6 +1557,9 @@ private boolean isEQEmpty() {
*/
@SuppressWarnings("serial")
private final boolean waitForIdle(final long end) {
if (timeout(end) <= 0) {
return false;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the timeout is ended we will exit at the end of this method immediately, but let's post one less event to the EDT.

flushPendingEvents();
final boolean queueWasEmpty;
final AtomicBoolean queueEmpty = new AtomicBoolean();
Expand Down
23 changes: 13 additions & 10 deletions src/java.desktop/unix/classes/sun/awt/X11/XToolkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
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;
Expand Down Expand Up @@ -2393,7 +2394,7 @@ public static long getEventNumber() {
* @inheritDoc
*/
@Override
protected boolean syncNativeQueue(final long timeout) {
protected boolean syncNativeQueue(long timeout) {
if (timeout <= 0) {
return false;
}
Expand All @@ -2418,31 +2419,33 @@ public void dispatchEvent(XEvent e) {

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;
Expand Down