Skip to content

Commit e1967d5

Browse files
committedJan 31, 2025
8348625: [21u, 17u] Revert JDK-8185862 to restore old java.awt.headless behavior on Windows
Reviewed-by: sgehwolf
1 parent b79136f commit e1967d5

File tree

7 files changed

+53
-119
lines changed

7 files changed

+53
-119
lines changed
 

‎src/java.desktop/windows/classes/sun/awt/PlatformGraphicsInfo.java

+5-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -28,41 +28,20 @@
2828
import java.awt.GraphicsEnvironment;
2929
import java.awt.Toolkit;
3030

31-
import sun.awt.windows.WToolkit;
32-
3331
public class PlatformGraphicsInfo {
3432

35-
private static final boolean hasDisplays;
36-
37-
static {
38-
loadAWTLibrary();
39-
hasDisplays = hasDisplays0();
40-
}
41-
42-
@SuppressWarnings("removal")
43-
private static void loadAWTLibrary() {
44-
java.security.AccessController.doPrivileged(
45-
new java.security.PrivilegedAction<Void>() {
46-
public Void run() {
47-
System.loadLibrary("awt");
48-
return null;
49-
}
50-
});
51-
}
52-
53-
private static native boolean hasDisplays0();
54-
5533
public static GraphicsEnvironment createGE() {
5634
return new Win32GraphicsEnvironment();
5735
}
5836

5937
public static Toolkit createToolkit() {
60-
return new WToolkit();
38+
return new sun.awt.windows.WToolkit();
6139
}
6240

6341
public static boolean getDefaultHeadlessProperty() {
64-
// If we don't find usable displays, we run headless.
65-
return !hasDisplays;
42+
// On Windows, we assume we can always create headful apps.
43+
// Here is where we can add code that would actually check.
44+
return false;
6645
}
6746

6847
/*

‎src/java.desktop/windows/classes/sun/awt/Win32GraphicsEnvironment.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -60,8 +60,7 @@ public final class Win32GraphicsEnvironment extends SunGraphicsEnvironment {
6060
WToolkit.loadLibraries();
6161
// setup flags before initializing native layer
6262
WindowsFlags.initFlags();
63-
64-
initDisplay();
63+
initDisplayWrapper();
6564

6665
// Install correct surface manager factory.
6766
SurfaceManagerFactory.setInstance(new WindowsSurfaceManagerFactory());
@@ -89,6 +88,14 @@ public final class Win32GraphicsEnvironment extends SunGraphicsEnvironment {
8988
*/
9089
private static native void initDisplay();
9190

91+
private static boolean displayInitialized; // = false;
92+
public static void initDisplayWrapper() {
93+
if (!displayInitialized) {
94+
displayInitialized = true;
95+
initDisplay();
96+
}
97+
}
98+
9299
public Win32GraphicsEnvironment() {
93100
}
94101

‎src/java.desktop/windows/native/libawt/windows/Devices.cpp

+33-48
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -85,75 +85,60 @@
8585
#include "Trace.h"
8686
#include "D3DPipelineManager.h"
8787

88-
typedef struct {
89-
int monitorCounter;
90-
int monitorLimit;
91-
HMONITOR* hmpMonitors;
92-
} MonitorData;
9388

89+
/* Some helper functions (from awt_MMStub.h/cpp) */
9490

95-
// Only monitors where CreateDC does not fail are valid
96-
static BOOL IsValidMonitor(HMONITOR hMon)
97-
{
98-
MONITORINFOEX mieInfo;
99-
memset((void*)(&mieInfo), 0, sizeof(MONITORINFOEX));
100-
mieInfo.cbSize = sizeof(MONITORINFOEX);
101-
if (!::GetMonitorInfo(hMon, (LPMONITORINFOEX)(&mieInfo))) {
102-
J2dTraceLn1(J2D_TRACE_INFO, "Devices::IsValidMonitor: GetMonitorInfo failed for monitor with handle %p", hMon);
103-
return FALSE;
104-
}
105-
106-
HDC hDC = CreateDC(mieInfo.szDevice, NULL, NULL, NULL);
107-
if (NULL == hDC) {
108-
J2dTraceLn2(J2D_TRACE_INFO, "Devices::IsValidMonitor: CreateDC failed for monitor with handle %p, device: %S", hMon, mieInfo.szDevice);
109-
return FALSE;
110-
}
111-
112-
::DeleteDC(hDC);
113-
return TRUE;
114-
}
91+
int g_nMonitorCounter;
92+
int g_nMonitorLimit;
93+
HMONITOR* g_hmpMonitors;
11594

11695
// Callback for CountMonitors below
117-
static BOOL WINAPI clb_fCountMonitors(HMONITOR hMon, HDC hDC, LPRECT rRect, LPARAM lpMonitorCounter)
96+
BOOL WINAPI clb_fCountMonitors(HMONITOR hMon, HDC hDC, LPRECT rRect, LPARAM lP)
11897
{
119-
if (IsValidMonitor(hMon)) {
120-
(*((int *)lpMonitorCounter))++;
121-
}
122-
98+
g_nMonitorCounter ++;
12399
return TRUE;
124100
}
125101

126102
int WINAPI CountMonitors(void)
127103
{
128-
int monitorCounter = 0;
129-
::EnumDisplayMonitors(NULL, NULL, clb_fCountMonitors, (LPARAM)&monitorCounter);
130-
return monitorCounter;
104+
g_nMonitorCounter = 0;
105+
::EnumDisplayMonitors(NULL, NULL, clb_fCountMonitors, 0L);
106+
return g_nMonitorCounter;
107+
131108
}
132109

133110
// Callback for CollectMonitors below
134-
static BOOL WINAPI clb_fCollectMonitors(HMONITOR hMon, HDC hDC, LPRECT rRect, LPARAM lpMonitorData)
111+
BOOL WINAPI clb_fCollectMonitors(HMONITOR hMon, HDC hDC, LPRECT rRect, LPARAM lP)
135112
{
136-
MonitorData* pMonitorData = (MonitorData *)lpMonitorData;
137-
if ((pMonitorData->monitorCounter < pMonitorData->monitorLimit) && (IsValidMonitor(hMon))) {
138-
pMonitorData->hmpMonitors[pMonitorData->monitorCounter] = hMon;
139-
pMonitorData->monitorCounter++;
113+
114+
if ((g_nMonitorCounter < g_nMonitorLimit) && (NULL != g_hmpMonitors)) {
115+
g_hmpMonitors[g_nMonitorCounter] = hMon;
116+
g_nMonitorCounter ++;
140117
}
141118

142119
return TRUE;
143120
}
144121

145-
static int WINAPI CollectMonitors(HMONITOR* hmpMonitors, int nNum)
122+
int WINAPI CollectMonitors(HMONITOR* hmpMonitors, int nNum)
146123
{
124+
int retCode = 0;
125+
147126
if (NULL != hmpMonitors) {
148-
MonitorData monitorData;
149-
monitorData.monitorCounter = 0;
150-
monitorData.monitorLimit = nNum;
151-
monitorData.hmpMonitors = hmpMonitors;
152-
::EnumDisplayMonitors(NULL, NULL, clb_fCollectMonitors, (LPARAM)&monitorData);
153-
return monitorData.monitorCounter;
154-
} else {
155-
return 0;
127+
128+
g_nMonitorCounter = 0;
129+
g_nMonitorLimit = nNum;
130+
g_hmpMonitors = hmpMonitors;
131+
132+
::EnumDisplayMonitors(NULL, NULL, clb_fCollectMonitors, 0L);
133+
134+
retCode = g_nMonitorCounter;
135+
136+
g_nMonitorCounter = 0;
137+
g_nMonitorLimit = 0;
138+
g_hmpMonitors = NULL;
139+
156140
}
141+
return retCode;
157142
}
158143

159144
BOOL WINAPI MonitorBounds(HMONITOR hmMonitor, RECT* rpBounds)

‎src/java.desktop/windows/native/libawt/windows/Devices.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -74,6 +74,4 @@ static CriticalSection arrayLock;
7474

7575
BOOL WINAPI MonitorBounds (HMONITOR, RECT*);
7676

77-
int WINAPI CountMonitors (void);
78-
7977
#endif // _DEVICES_H_

‎src/java.desktop/windows/native/libawt/windows/awt_PlatformGraphicsInfo.cpp

-37
This file was deleted.

‎test/jdk/java/awt/font/JNICheck/FreeTypeScalerJNICheck.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2021, JetBrains s.r.o.. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -24,6 +24,7 @@
2424

2525
/* @test
2626
* @bug 8269223
27+
* @requires !vm.debug | os.family != "windows"
2728
* @summary Verifies that -Xcheck:jni issues no warnings from freetypeScaler.c
2829
* @library /test/lib
2930
* @run main FreeTypeScalerJNICheck

‎test/jdk/javax/swing/reliability/HangDuringStaticInitialization.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -33,6 +33,7 @@
3333
/**
3434
* @test
3535
* @bug 8189604 8208702
36+
* @requires !vm.debug | os.family != "windows"
3637
* @run main/othervm -Djava.awt.headless=false HangDuringStaticInitialization
3738
* @run main/othervm -Djava.awt.headless=true HangDuringStaticInitialization
3839
*/

0 commit comments

Comments
 (0)