8152683: Deadlock when resuming from sleep with different monitor setup
Reviewed-by: serb, vadim
Contributed-by: Karl von Randow <karl@xk72.com>
--- a/jdk/src/java.desktop/macosx/classes/sun/awt/CGraphicsEnvironment.java Mon Mar 06 22:52:45 2017 +0300
+++ b/jdk/src/java.desktop/macosx/classes/sun/awt/CGraphicsEnvironment.java Tue Mar 07 13:00:23 2017 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, 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
@@ -79,6 +79,10 @@
/** Available CoreGraphics displays. */
private final Map<Integer, CGraphicsDevice> devices = new HashMap<>(5);
+ /**
+ * The key in the {@link #devices} for the main display.
+ */
+ private int mainDisplayID;
/** Reference to the display reconfiguration callback context. */
private final long displayReconfigContext;
@@ -136,15 +140,15 @@
final Map<Integer, CGraphicsDevice> old = new HashMap<>(devices);
devices.clear();
- int mainID = getMainDisplayID();
+ mainDisplayID = getMainDisplayID();
// initialization of the graphics device may change
// list of displays on hybrid systems via an activation
// of discrete video.
// So, we initialize the main display first, and then
// retrieve actual list of displays.
- if (!old.containsKey(mainID)) {
- old.put(mainID, new CGraphicsDevice(mainID));
+ if (!old.containsKey(mainDisplayID)) {
+ old.put(mainDisplayID, new CGraphicsDevice(mainDisplayID));
}
for (final int id : getDisplayIDs()) {
@@ -157,7 +161,6 @@
@Override
public synchronized GraphicsDevice getDefaultScreenDevice() throws HeadlessException {
- final int mainDisplayID = getMainDisplayID();
CGraphicsDevice d = devices.get(mainDisplayID);
if (d == null) {
// we do not expect that this may happen, the only response