Skip to content

Commit

Permalink
8266949: Check possibility to disable OperationTimedOut on Unix
Browse files Browse the repository at this point in the history
Reviewed-by: azvegint, kizune
  • Loading branch information
mrserb committed May 18, 2021
1 parent b92c5a4 commit e6705c0
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
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;
}
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

3 comments on commit e6705c0

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@mrserb
Copy link
Member Author

@mrserb mrserb commented on e6705c0 Jan 12, 2023

Choose a reason for hiding this comment

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

/backport jdk8u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on e6705c0 Jan 12, 2023

Choose a reason for hiding this comment

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

@mrserb Could not automatically backport e6705c0e to openjdk/jdk8u-dev due to conflicts in the following files:

  • jdk/src/share/classes/sun/awt/SunToolkit.java
  • jdk/src/solaris/classes/sun/awt/X11/XToolkit.java

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk8u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk8u-dev master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b mrserb-backport-e6705c0e

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk e6705c0e4b548a83197c3ea70bdef25ec65d4c00

# Backport the commit
$ git cherry-pick --no-commit e6705c0e4b548a83197c3ea70bdef25ec65d4c00
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport e6705c0e4b548a83197c3ea70bdef25ec65d4c00'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk8u-dev with the title Backport e6705c0e4b548a83197c3ea70bdef25ec65d4c00.

Please sign in to comment.