Skip to content
Permalink
Browse files
8266949: Check possibility to disable OperationTimedOut on Unix
Reviewed-by: azvegint, kizune
  • Loading branch information
mrserb committed May 18, 2021
1 parent b92c5a4 commit e6705c0e4b548a83197c3ea70bdef25ec65d4c00
Showing with 20 additions and 23 deletions.
  1. +7 −13 src/java.desktop/share/classes/sun/awt/SunToolkit.java
  2. +13 −10 src/java.desktop/unix/classes/sun/awt/X11/XToolkit.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
@@ -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) {
@@ -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);
}

@@ -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).");
}
@@ -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());
}

@@ -1566,6 +1557,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();
@@ -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;
@@ -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;
}
@@ -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;

0 comments on commit e6705c0

Please sign in to comment.