Navigation Menu

Skip to content

Commit

Permalink
8266949: Check possibility to disable OperationTimedOut on Unix
Browse files Browse the repository at this point in the history
Backport-of: e6705c0
  • Loading branch information
GoeLin committed Sep 28, 2021
1 parent d896cda commit 654ad1c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
20 changes: 7 additions & 13 deletions src/java.desktop/share/classes/sun/awt/SunToolkit.java
@@ -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 @@ -1407,15 +1407,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 @@ -1433,7 +1424,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 @@ -1482,7 +1473,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 @@ -1538,7 +1529,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 @@ -1568,6 +1559,9 @@ private boolean isEQEmpty() {
*/
@SuppressWarnings("serial")
private final boolean waitForIdle(final long end) {
if (timeout(end) <= 0) {
return false;
}
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
Expand Up @@ -126,6 +126,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 @@ -2583,7 +2584,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 @@ -2608,31 +2609,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

1 comment on commit 654ad1c

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.