Skip to content

Commit 395243e

Browse files
committed
Revert "JBR-5497: follow-up fix"
This reverts commit 06f15d6.
1 parent 50be626 commit 395243e

File tree

7 files changed

+225
-370
lines changed

7 files changed

+225
-370
lines changed

src/java.desktop/macosx/classes/sun/lwawt/LWToolkit.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private void waitForRunState(int state) {
152152
wait();
153153
}
154154
} catch (InterruptedException ie) {
155-
log.fine("LWToolkit.waitForRunState: interrupted");
155+
log.fine("LWToolkit.run: interrupted");
156156
break;
157157
}
158158
}

src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java

+24-119
Original file line numberDiff line numberDiff line change
@@ -1185,9 +1185,9 @@ public long getLayerPtr() {
11851185

11861186
private final static int INVOKE_LATER_FLUSH_BUFFERS = getInvokeLaterMode();
11871187

1188+
@SuppressWarnings("removal")
11881189
private static int getInvokeLaterMode() {
11891190
final String invokeLaterKey = "awt.mac.flushBuffers.invokeLater";
1190-
@SuppressWarnings("removal")
11911191
final String invokeLaterArg = AccessController.doPrivileged(
11921192
new GetPropertyAction(invokeLaterKey));
11931193
final int result;
@@ -1215,33 +1215,9 @@ private static int getInvokeLaterMode() {
12151215
return result;
12161216
}
12171217

1218-
@SuppressWarnings("removal")
1219-
private final static boolean INVOKE_LATER_USE_PWM = getInvokeLaterUsePWM();
1220-
1221-
private static boolean getInvokeLaterUsePWM() {
1222-
final String usePwmKey = "awt.mac.flushBuffers.pwm";
1223-
@SuppressWarnings("removal")
1224-
final String usePwmArg = AccessController.doPrivileged(
1225-
new GetPropertyAction(usePwmKey));
1226-
final boolean result;
1227-
if (usePwmArg == null) {
1228-
// default = 'false':
1229-
result = false;
1230-
} else {
1231-
result = "true".equalsIgnoreCase(usePwmArg);
1232-
logger.info("CPlatformWindow: property \"{0}={1}\", using usePWM={2}.",
1233-
usePwmKey, usePwmArg, result);
1234-
}
1235-
return result;
1236-
}
1237-
/* 10s period arround reference times (sleep/wake-up...)
1238-
* to ensure all displays are awaken properly */
1239-
private final static long NANOS_PER_SEC = 1000000000L;
1240-
private final static long STATE_CHANGE_PERIOD = 10L * NANOS_PER_SEC;
1241-
1242-
private final AtomicBoolean mirroringState = new AtomicBoolean(false);
1243-
/** per window timestamp of disabling mirroring */
1244-
private final AtomicLong mirroringDisablingTime = new AtomicLong(0L);
1218+
private final static int INVOKE_LATER_COUNT = 5;
1219+
/** per window counter of remaining invokeLater calls */
1220+
private final AtomicInteger invokeLaterCount = new AtomicInteger();
12451221

12461222
// Specific class needed to get obvious stack traces:
12471223
private final class EmptyRunnable implements Runnable {
@@ -1257,10 +1233,7 @@ public void run() {
12571233
private final EmptyRunnable emptyTask = new EmptyRunnable();
12581234

12591235
void flushBuffers() {
1260-
// Only 1 usage by deliverMoveResizeEvent():
1261-
// System-dependent appearance optimization.
1262-
// May be blocking so postpone this event processing:
1263-
1236+
// only 1 usage by deliverMoveResizeEvent():
12641237
if (isVisible() && !nativeBounds.isEmpty() && !isFullScreenMode) {
12651238
// use the system property 'awt.mac.flushBuffers.invokeLater' to true/auto (default: auto)
12661239
// to avoid deadlocks caused by the LWCToolkit.invokeAndWait() call below:
@@ -1273,68 +1246,38 @@ void flushBuffers() {
12731246
default:
12741247
case INVOKE_LATER_AUTO:
12751248
useInvokeLater = false;
1276-
1277-
// JBR-5497: force using invokeLater() when computer returns from sleep or displayChanged()
1278-
// (mirroring case especially) to avoid deadlocks until solved definitely:
1279-
1280-
boolean mirroring = false;
12811249
if (peer != null) {
12821250
final GraphicsDevice device = peer.getGraphicsConfiguration().getDevice();
12831251
if (device instanceof CGraphicsDevice) {
12841252
// JBR-5497: avoid deadlock in mirroring mode (laptop + external screen):
1285-
// Note: the CGraphicsDevice instance will be recreated when mirroring is enabled/disabled.
1286-
mirroring = ((CGraphicsDevice)device).isMirroring();
1253+
useInvokeLater = ((CGraphicsDevice)device).isMirroring();
12871254
if (logger.isLoggable(PlatformLogger.Level.FINE)) {
1288-
logger.fine("CPlatformWindow.flushBuffers[auto]: CGraphicsDevice.isMirroring = {0}",
1289-
mirroring);
1255+
logger.fine("CPlatformWindow.flushBuffers: CGraphicsDevice.isMirroring = {0}",
1256+
useInvokeLater);
12901257
}
12911258
}
12921259
}
1293-
if (mirroring) {
1294-
mirroringState.set(true);
1295-
} else if (mirroringState.get()) {
1296-
// mirroringState trigger enabled but mirroring=false:
1297-
// keep mirroring enabled for some time (STATE_CHANGE_PERIOD):
1298-
mirroring = true;
1299-
final long now = System.nanoTime(); // timestamp
1300-
1301-
// should disable mirroring now ? check timestamp:
1302-
final long lastTime = mirroringDisablingTime.get();
1303-
final long delta;
1304-
if (lastTime == 0L) {
1305-
delta = 0L;
1306-
// unset: set timestamp of disabling mirroring:
1307-
mirroringDisablingTime.set(now);
1308-
} else {
1309-
delta = Math.abs(now - lastTime);
1310-
if (delta > STATE_CHANGE_PERIOD) {
1311-
// disable mirroring as period is elapsed:
1312-
mirroring = false;
1313-
mirroringState.set(false);
1314-
// reset timestamp:
1315-
mirroringDisablingTime.set(0L);
1316-
}
1317-
}
1318-
if (logger.isLoggable(PlatformLogger.Level.FINE)) {
1319-
logger.fine("CPlatformWindow.flushBuffers[auto]: mirroring = {0} (mirroring = {1} delta = {2} ms)",
1320-
mirroring, mirroringState.get(), delta * 1e-6);
1260+
// JBR-5497: keep few more invokeLater() when computer returns from sleep or displayChanged()
1261+
// to avoid deadlocks until solved definitely:
1262+
if (useInvokeLater) {
1263+
// reset to max count:
1264+
invokeLaterCount.set(INVOKE_LATER_COUNT);
1265+
} else {
1266+
final int prev = invokeLaterCount.get();
1267+
if (prev > 0) {
1268+
invokeLaterCount.compareAndSet(prev, prev - 1);
1269+
useInvokeLater = true;
13211270
}
13221271
}
1323-
useInvokeLater = mirroring;
1272+
if (logger.isLoggable(PlatformLogger.Level.FINE)) {
1273+
logger.fine("CPlatformWindow.flushBuffers: useInvokeLater = {0} (count = {1})",
1274+
useInvokeLater, invokeLaterCount.get());
1275+
}
13241276
break;
13251277
case INVOKE_LATER_ENABLED:
13261278
useInvokeLater = true;
13271279
break;
13281280
}
1329-
if (!useInvokeLater && INVOKE_LATER_USE_PWM) {
1330-
// If the system property 'awt.mac.flushBuffers.pwm' is true,
1331-
// invokeLater is enforced during power transitions.
1332-
final boolean inTransition = LWCToolkit.isWithinPowerTransition();
1333-
if (inTransition) {
1334-
logger.fine("CPlatformWindow.flushBuffers[pwm]: inTransition = true");
1335-
useInvokeLater = true;
1336-
}
1337-
}
13381281
try {
13391282
// check invokeAndWait: KO (operations require AWTLock and main thread)
13401283
// => use invokeLater as it is an empty event to force refresh ASAP
@@ -1347,13 +1290,7 @@ void flushBuffers() {
13471290
getIdentifier(target));
13481291
}
13491292

1350-
/* Ensure >500ms = 666ms timeout to avoid any deadlock among
1351-
* appkit, EDT, Flusher & a11y threads, locks
1352-
* and various synchronization patterns... */
1353-
final double timeoutSeconds = 0.666; // seconds
1354-
1355-
// FUCK: appKit is calling this method !
1356-
LWCToolkit.invokeAndWait(emptyTask, target, timeoutSeconds);
1293+
LWCToolkit.invokeAndWait(emptyTask, target);
13571294

13581295
if (logger.isLoggable(PlatformLogger.Level.FINE)) {
13591296
logger.fine("CPlatformWindow.flushBuffers: exit " +
@@ -1362,9 +1299,7 @@ void flushBuffers() {
13621299
}
13631300
}
13641301
} catch (InvocationTargetException ite) {
1365-
if (logger.isLoggable(PlatformLogger.Level.FINE)) {
1366-
logger.fine("CPlatformWindow.flushBuffers: timeout or LWCToolkit.invoke failure: ", ite);
1367-
}
1302+
logger.severe("CPlatformWindow.flushBuffers: exception occurred: ", ite);
13681303
}
13691304
}
13701305
}
@@ -1399,16 +1334,10 @@ private void deliverWindowFocusEvent(boolean gained, CPlatformWindow opposite){
13991334
responder.handleWindowFocusEvent(gained, oppositePeer);
14001335
}
14011336

1402-
/* useless ? */
14031337
public void doDeliverMoveResizeEvent() {
1404-
if (logger.isLoggable(PlatformLogger.Level.FINE)) {
1405-
logger.fine("CPlatformWindow.doDeliverMoveResizeEvent() called by {0}",
1406-
Thread.currentThread());
1407-
}
14081338
execute(ptr -> nativeCallDeliverMoveResizeEvent(ptr));
14091339
}
14101340

1411-
/* native call by AWTWindow._deliverMoveResizeEvent() */
14121341
protected void deliverMoveResizeEvent(int x, int y, int width, int height,
14131342
boolean byUser) {
14141343
AtomicBoolean ref = new AtomicBoolean();
@@ -1422,17 +1351,9 @@ protected void deliverMoveResizeEvent(int x, int y, int width, int height,
14221351
nativeBounds = new Rectangle(x, y, width, height);
14231352
if (peer != null) {
14241353
peer.notifyReshape(x, y, width, height);
1425-
1426-
if (logger.isLoggable(PlatformLogger.Level.FINE)) {
1427-
logger.fine("CPlatformWindow.deliverMoveResizeEvent(): byUser = {0} " +
1428-
"isFullScreenAnimationOn = {1}", byUser, isFullScreenAnimationOn);
1429-
}
1430-
14311354
// System-dependent appearance optimization.
14321355
if ((byUser && !oldB.getSize().equals(nativeBounds.getSize()))
14331356
|| isFullScreenAnimationOn) {
1434-
1435-
// May be blocking so postpone this event processing:
14361357
flushBuffers();
14371358
}
14381359
}
@@ -1661,46 +1582,30 @@ private long createNSWindow(long nsViewPtr,
16611582
// ----------------------------------------------------------------------
16621583

16631584
private void windowWillMiniaturize() {
1664-
logger.fine("windowWillMiniaturize");
16651585
isIconifyAnimationActive = true;
16661586
}
16671587

16681588
private void windowDidBecomeMain() {
1669-
logger.fine("windowDidBecomeMain");
16701589
lastBecomeMainTime = System.currentTimeMillis();
16711590
checkBlockingAndOrder();
16721591
}
16731592

16741593
private void windowWillEnterFullScreen() {
16751594
isFullScreenAnimationOn = true;
1676-
if (logger.isLoggable(PlatformLogger.Level.FINE)) {
1677-
logger.fine("windowWillEnterFullScreen: isFullScreenAnimationOn = {0}", isFullScreenAnimationOn);
1678-
}
16791595
}
16801596

16811597
private void windowDidEnterFullScreen() {
16821598
isInFullScreen = true;
16831599
isFullScreenAnimationOn = false;
1684-
if (logger.isLoggable(PlatformLogger.Level.FINE)) {
1685-
logger.fine("windowWillEnterFullScreen: isFullScreenAnimationOn = {0} isInFullScreen = {1}",
1686-
isFullScreenAnimationOn, isInFullScreen);
1687-
}
16881600
}
16891601

16901602
private void windowWillExitFullScreen() {
16911603
isFullScreenAnimationOn = true;
1692-
if (logger.isLoggable(PlatformLogger.Level.FINE)) {
1693-
logger.fine("windowWillExitFullScreen: isFullScreenAnimationOn = {0}", isFullScreenAnimationOn);
1694-
}
16951604
}
16961605

16971606
private void windowDidExitFullScreen() {
16981607
isInFullScreen = false;
16991608
isFullScreenAnimationOn = false;
1700-
if (logger.isLoggable(PlatformLogger.Level.FINE)) {
1701-
logger.fine("windowDidExitFullScreen: isFullScreenAnimationOn = {0} isInFullScreen = {1}",
1702-
isFullScreenAnimationOn, isInFullScreen);
1703-
}
17041609
}
17051610

17061611
@JBRApi.Provides("java.awt.Window.CustomTitleBarPeer#update")

src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java

+5-26
Original file line numberDiff line numberDiff line change
@@ -815,33 +815,16 @@ public String toString() {
815815
public static void invokeAndWait(Runnable runnable, Component component)
816816
throws InvocationTargetException
817817
{
818-
invokeAndWait(runnable, component, false, 0.0);
818+
invokeAndWait(runnable, component, -1);
819819
}
820820

821-
/* 25.01.25: keep public methods with (int timeoutSeconds) */
822-
@Deprecated(since = "25")
823821
public static void invokeAndWait(Runnable runnable, Component component, int timeoutSeconds)
824822
throws InvocationTargetException
825823
{
826824
invokeAndWait(runnable, component, false, timeoutSeconds);
827825
}
828826

829-
@Deprecated(since = "25")
830827
public static void invokeAndWait(Runnable runnable, Component component, boolean processEvents, int timeoutSeconds)
831-
throws InvocationTargetException {
832-
final double timeout = (timeoutSeconds > 0) ? timeoutSeconds : 0.0;
833-
invokeAndWait(runnable, component, processEvents, timeout);
834-
}
835-
836-
/* 25.01.25: added public methods with (double timeoutSeconds) to have timeouts between 0.0 and 1.0 */
837-
838-
public static void invokeAndWait(Runnable runnable, Component component, double timeoutSeconds)
839-
throws InvocationTargetException
840-
{
841-
invokeAndWait(runnable, component, false, timeoutSeconds);
842-
}
843-
844-
public static void invokeAndWait(Runnable runnable, Component component, boolean processEvents, double timeoutSeconds)
845828
throws InvocationTargetException
846829
{
847830
if (log.isLoggable(PlatformLogger.Level.FINE)) {
@@ -905,10 +888,6 @@ public static void invokeAndWait(Runnable runnable, Component component, boolean
905888

906889
private static native boolean isBlockingEventDispatchThread();
907890

908-
static native String getThreadTraceContexts();
909-
910-
static native boolean isWithinPowerTransition();
911-
912891
public static void invokeLater(Runnable event, Component component)
913892
throws InvocationTargetException {
914893
Objects.requireNonNull(component, "Null component provided to invokeLater");
@@ -1094,13 +1073,13 @@ public boolean canPopupOverlapTaskBar() {
10941073
* if false - all events come after exit form the nested loop
10951074
*/
10961075
static void doAWTRunLoop(long mediator, boolean processEvents) {
1097-
doAWTRunLoop(mediator, processEvents, 0.0);
1076+
doAWTRunLoop(mediator, processEvents, -1);
10981077
}
10991078

11001079
/**
1101-
* Starts run-loop with the provided timeout. Use (<=0.0) for the infinite value.
1080+
* Starts run-loop with the provided timeout. Use (-1) for the infinite value.
11021081
*/
1103-
static boolean doAWTRunLoop(long mediator, boolean processEvents, double timeoutSeconds) {
1082+
static boolean doAWTRunLoop(long mediator, boolean processEvents, int timeoutSeconds) {
11041083
if (log.isLoggable(PlatformLogger.Level.FINE)) {
11051084
log.fine("doAWTRunLoop: enter: mediator: " + mediator + " processEvents: "+ processEvents + " timeoutSeconds: " + timeoutSeconds);
11061085
}
@@ -1112,7 +1091,7 @@ static boolean doAWTRunLoop(long mediator, boolean processEvents, double timeout
11121091
}
11131092
}
11141093
}
1115-
private static native boolean doAWTRunLoopImpl(long mediator, boolean processEvents, boolean inAWT, double timeoutSeconds);
1094+
private static native boolean doAWTRunLoopImpl(long mediator, boolean processEvents, boolean inAWT, int timeoutSeconds);
11161095
static native void stopAWTRunLoop(long mediator);
11171096

11181097
private native boolean nativeSyncQueue(long timeout);

0 commit comments

Comments
 (0)