Skip to content

Commit 4e3d9e3

Browse files
author
Anton Litvinov
committedAug 31, 2020
8249183: JVM crash in "AwtFrame::WmSize" method
Reviewed-by: serb, aivanov
1 parent 62cc45c commit 4e3d9e3

File tree

5 files changed

+57
-33
lines changed

5 files changed

+57
-33
lines changed
 

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

+36
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.awt.Container;
3333
import java.awt.Dialog;
3434
import java.awt.Dimension;
35+
import java.awt.Frame;
3536
import java.awt.Graphics;
3637
import java.awt.GraphicsConfiguration;
3738
import java.awt.GraphicsDevice;
@@ -58,6 +59,7 @@
5859
import sun.awt.AppContext;
5960
import sun.awt.DisplayChangedListener;
6061
import sun.awt.SunToolkit;
62+
import sun.awt.TimedWindowEvent;
6163
import sun.awt.Win32GraphicsConfig;
6264
import sun.awt.Win32GraphicsDevice;
6365
import sun.awt.Win32GraphicsEnvironment;
@@ -387,6 +389,40 @@ void preprocessPostEvent(AWTEvent event) {
387389
}
388390
}
389391

392+
private void notifyWindowStateChanged(int oldState, int newState) {
393+
int changed = oldState ^ newState;
394+
if (changed == 0) {
395+
return;
396+
}
397+
if (log.isLoggable(PlatformLogger.Level.FINE)) {
398+
log.fine("Reporting state change %x -> %x", oldState, newState);
399+
}
400+
401+
if (target instanceof Frame) {
402+
// Sync target with peer.
403+
AWTAccessor.getFrameAccessor().setExtendedState((Frame) target,
404+
newState);
405+
}
406+
407+
// Report (de)iconification to old clients.
408+
if ((changed & Frame.ICONIFIED) > 0) {
409+
if ((newState & Frame.ICONIFIED) > 0) {
410+
postEvent(new TimedWindowEvent((Window) target,
411+
WindowEvent.WINDOW_ICONIFIED, null, 0, 0,
412+
System.currentTimeMillis()));
413+
} else {
414+
postEvent(new TimedWindowEvent((Window) target,
415+
WindowEvent.WINDOW_DEICONIFIED, null, 0, 0,
416+
System.currentTimeMillis()));
417+
}
418+
}
419+
420+
// New (since 1.4) state change event.
421+
postEvent(new TimedWindowEvent((Window) target,
422+
WindowEvent.WINDOW_STATE_CHANGED, null, oldState, newState,
423+
System.currentTimeMillis()));
424+
}
425+
390426
synchronized void addWindowListener(WindowListener l) {
391427
windowListener = AWTEventMulticaster.add(windowListener, l);
392428
}

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

+1-30
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ jfieldID AwtFrame::handleID;
9999

100100
jfieldID AwtFrame::undecoratedID;
101101
jmethodID AwtFrame::getExtendedStateMID;
102-
jmethodID AwtFrame::setExtendedStateMID;
103102

104103
jmethodID AwtFrame::activateEmbeddingTopLevelMID;
105104
jfieldID AwtFrame::isEmbeddedInIEID;
@@ -813,13 +812,6 @@ AwtFrame::Show()
813812
}
814813
}
815814

816-
void
817-
AwtFrame::SendWindowStateEvent(int oldState, int newState)
818-
{
819-
SendWindowEvent(java_awt_event_WindowEvent_WINDOW_STATE_CHANGED,
820-
NULL, oldState, newState);
821-
}
822-
823815
void
824816
AwtFrame::ClearMaximizedBounds()
825817
{
@@ -973,24 +965,7 @@ MsgRouting AwtFrame::WmSize(UINT type, int w, int h)
973965

974966
jint changed = oldState ^ newState;
975967
if (changed != 0) {
976-
DTRACE_PRINTLN2("AwtFrame::WmSize: reporting state change %x -> %x",
977-
oldState, newState);
978-
979-
// sync target with peer
980-
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
981-
env->CallVoidMethod(GetPeer(env), AwtFrame::setExtendedStateMID, newState);
982-
983-
// report (de)iconification to old clients
984-
if (changed & java_awt_Frame_ICONIFIED) {
985-
if (newState & java_awt_Frame_ICONIFIED) {
986-
SendWindowEvent(java_awt_event_WindowEvent_WINDOW_ICONIFIED);
987-
} else {
988-
SendWindowEvent(java_awt_event_WindowEvent_WINDOW_DEICONIFIED);
989-
}
990-
}
991-
992-
// New (since 1.4) state change event
993-
SendWindowStateEvent(oldState, newState);
968+
NotifyWindowStateChanged(oldState, newState);
994969
}
995970

996971
// If window is in iconic state, do not send COMPONENT_RESIZED event
@@ -1696,10 +1671,6 @@ Java_sun_awt_windows_WFramePeer_initIDs(JNIEnv *env, jclass cls)
16961671
{
16971672
TRY;
16981673

1699-
AwtFrame::setExtendedStateMID = env->GetMethodID(cls, "setExtendedState", "(I)V");
1700-
DASSERT(AwtFrame::setExtendedStateMID);
1701-
CHECK_NULL(AwtFrame::setExtendedStateMID);
1702-
17031674
AwtFrame::getExtendedStateMID = env->GetMethodID(cls, "getExtendedState", "()I");
17041675
DASSERT(AwtFrame::getExtendedStateMID);
17051676

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

-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ class AwtFrame : public AwtWindow {
5454
/* sun.awt.windows.WEmbeddedFrame fields and method IDs */
5555
static jfieldID handleID;
5656

57-
static jmethodID setExtendedStateMID;
5857
static jmethodID getExtendedStateMID;
5958

6059
/* method id for WEmbeddedFrame.requestActivate() method */
@@ -88,8 +87,6 @@ class AwtFrame : public AwtWindow {
8887
INLINE BOOL isZoomed() { return m_zoomed; }
8988
INLINE void setZoomed(BOOL b) { m_zoomed = b; }
9089

91-
void SendWindowStateEvent(int oldState, int newState);
92-
9390
void Show();
9491

9592
INLINE void DrawMenuBar() { VERIFY(::DrawMenuBar(GetHWnd())); }

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

+16
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ jfieldID AwtWindow::sysYID;
184184
jfieldID AwtWindow::sysWID;
185185
jfieldID AwtWindow::sysHID;
186186
jfieldID AwtWindow::windowTypeID;
187+
jmethodID AwtWindow::notifyWindowStateChangedMID;
187188

188189
jmethodID AwtWindow::getWarningStringMID;
189190
jmethodID AwtWindow::calculateSecurityWarningPositionMID;
@@ -1641,6 +1642,16 @@ void AwtWindow::SendWindowEvent(jint id, HWND opposite,
16411642
env->DeleteLocalRef(event);
16421643
}
16431644

1645+
void AwtWindow::NotifyWindowStateChanged(jint oldState, jint newState)
1646+
{
1647+
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
1648+
jobject peer = GetPeer(env);
1649+
if (peer != NULL) {
1650+
env->CallVoidMethod(peer, AwtWindow::notifyWindowStateChangedMID,
1651+
oldState, newState);
1652+
}
1653+
}
1654+
16441655
BOOL AwtWindow::AwtSetActiveWindow(BOOL isMouseEventCause, UINT hittest)
16451656
{
16461657
// We used to reject non mouse window activation if our app wasn't active.
@@ -3344,6 +3355,11 @@ Java_sun_awt_windows_WWindowPeer_initIDs(JNIEnv *env, jclass cls)
33443355
AwtWindow::windowTypeID = env->GetFieldID(cls, "windowType",
33453356
"Ljava/awt/Window$Type;");
33463357

3358+
AwtWindow::notifyWindowStateChangedMID =
3359+
env->GetMethodID(cls, "notifyWindowStateChanged", "(II)V");
3360+
DASSERT(AwtWindow::notifyWindowStateChangedMID);
3361+
CHECK_NULL(AwtWindow::notifyWindowStateChangedMID);
3362+
33473363
CATCH_BAD_ALLOC;
33483364
}
33493365

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

+4
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,17 @@ class AwtWindow : public AwtCanvas {
5757
static jfieldID securityWarningWidthID;
5858
static jfieldID securityWarningHeightID;
5959

60+
/* sun.awt.windows.WWindowPeer field and method IDs */
6061
// The coordinates at the peer.
6162
static jfieldID sysXID;
6263
static jfieldID sysYID;
6364
static jfieldID sysWID;
6465
static jfieldID sysHID;
6566

6667
static jfieldID windowTypeID;
68+
static jmethodID notifyWindowStateChangedMID;
6769

70+
/* java.awt.Window method IDs */
6871
static jmethodID getWarningStringMID;
6972
static jmethodID calculateSecurityWarningPositionMID;
7073
static jmethodID windowTypeNameMID;
@@ -149,6 +152,7 @@ class AwtWindow : public AwtCanvas {
149152
void SendComponentEvent(jint eventId);
150153
void SendWindowEvent(jint id, HWND opposite = NULL,
151154
jint oldState = 0, jint newState = 0);
155+
void NotifyWindowStateChanged(jint oldState, jint newState);
152156

153157
BOOL IsFocusableWindow();
154158

0 commit comments

Comments
 (0)
Please sign in to comment.