8143316: Crash Trend in 1.9.0-ea-b93 (sun.awt.DefaultMouseInfoPeer.fillPointWithCoords)
authoralexsch
Mon, 11 Jan 2016 06:10:32 -0800
changeset 35666 d69b38870195
parent 35665 e90002447fd5
child 35667 ed476aba94de
8143316: Crash Trend in 1.9.0-ea-b93 (sun.awt.DefaultMouseInfoPeer.fillPointWithCoords) Reviewed-by: serb
jdk/src/java.desktop/share/classes/sun/awt/DefaultMouseInfoPeer.java
jdk/src/java.desktop/share/classes/sun/awt/SunToolkit.java
jdk/src/java.desktop/windows/classes/sun/awt/windows/WMouseInfoPeer.java
jdk/src/java.desktop/windows/classes/sun/awt/windows/WToolkit.java
jdk/src/java.desktop/windows/native/libawt/windows/MouseInfo.cpp
jdk/test/java/awt/MouseInfo/PointerInfoCrashTest.java
--- a/jdk/src/java.desktop/share/classes/sun/awt/DefaultMouseInfoPeer.java	Sat Jan 09 14:04:32 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2003, 2015, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package sun.awt;
-
-import java.awt.Point;
-import java.awt.Window;
-import java.awt.peer.MouseInfoPeer;
-
-public final class DefaultMouseInfoPeer implements MouseInfoPeer {
-
-    /**
-     * Package-private constructor to prevent instantiation.
-     */
-    DefaultMouseInfoPeer() {
-    }
-
-    public native int fillPointWithCoords(Point point);
-
-    public native boolean isWindowUnderMouse(Window w);
-
-}
--- a/jdk/src/java.desktop/share/classes/sun/awt/SunToolkit.java	Sat Jan 09 14:04:32 2016 +0100
+++ b/jdk/src/java.desktop/share/classes/sun/awt/SunToolkit.java	Mon Jan 11 06:10:32 2016 -0800
@@ -1159,17 +1159,6 @@
         return getStartupLocale();
     }
 
-    private static DefaultMouseInfoPeer mPeer = null;
-
-    @Override
-    public synchronized MouseInfoPeer getMouseInfoPeer() {
-        if (mPeer == null) {
-            mPeer = new DefaultMouseInfoPeer();
-        }
-        return mPeer;
-    }
-
-
     /**
      * Returns whether default toolkit needs the support of the xembed
      * from embedding host(if any).
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.desktop/windows/classes/sun/awt/windows/WMouseInfoPeer.java	Mon Jan 11 06:10:32 2016 -0800
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2003, 2015, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.awt.windows;
+
+import java.awt.GraphicsEnvironment;
+import java.awt.Point;
+import java.awt.Window;
+import java.awt.peer.MouseInfoPeer;
+
+public final class WMouseInfoPeer implements MouseInfoPeer {
+
+    static {
+        // initialize screen devices for the mouse coordinates scaling
+        GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
+    }
+
+    /**
+     * Package-private constructor to prevent instantiation.
+     */
+    WMouseInfoPeer() {
+    }
+
+    public native int fillPointWithCoords(Point point);
+
+    public native boolean isWindowUnderMouse(Window w);
+
+}
--- a/jdk/src/java.desktop/windows/classes/sun/awt/windows/WToolkit.java	Sat Jan 09 14:04:32 2016 +0100
+++ b/jdk/src/java.desktop/windows/classes/sun/awt/windows/WToolkit.java	Mon Jan 11 06:10:32 2016 -0800
@@ -558,6 +558,16 @@
         return WKeyboardFocusManagerPeer.getInstance();
     }
 
+    private static WMouseInfoPeer wPeer = null;
+
+    @Override
+    public synchronized MouseInfoPeer getMouseInfoPeer() {
+        if (wPeer == null) {
+            wPeer = new WMouseInfoPeer();
+        }
+        return wPeer;
+    }
+
     private native void setDynamicLayoutNative(boolean b);
 
     @Override
--- a/jdk/src/java.desktop/windows/native/libawt/windows/MouseInfo.cpp	Sat Jan 09 14:04:32 2016 +0100
+++ b/jdk/src/java.desktop/windows/native/libawt/windows/MouseInfo.cpp	Mon Jan 11 06:10:32 2016 -0800
@@ -33,12 +33,12 @@
 extern "C" {
 
 /*
- * Class:     sun_awt_DefaultMouseInfoPeer
+ * Class:     sun_awt_windows_WMouseInfoPeer
  * Method:    isWindowUnderMouse
  * Signature: (Ljava/awt/Window)Z
  */
 JNIEXPORT jboolean JNICALL
-Java_sun_awt_DefaultMouseInfoPeer_isWindowUnderMouse(JNIEnv *env, jclass cls,
+Java_sun_awt_windows_WMouseInfoPeer_isWindowUnderMouse(JNIEnv *env, jclass cls,
                                                         jobject window)
 {
     POINT pt;
@@ -73,12 +73,12 @@
 }
 
 /*
- * Class:     sun_awt_DefaultMouseInfoPeer
+ * Class:     sun_awt_windows_WMouseInfoPeer
  * Method:    fillPointWithCoords
  * Signature: (Ljava/awt/Point)I
  */
 JNIEXPORT jint JNICALL
-Java_sun_awt_DefaultMouseInfoPeer_fillPointWithCoords(JNIEnv *env, jclass cls, jobject point)
+Java_sun_awt_windows_WMouseInfoPeer_fillPointWithCoords(JNIEnv *env, jclass cls, jobject point)
 {
     static jclass pointClass = NULL;
     static jfieldID xID, yID;
@@ -95,7 +95,8 @@
         env->DeleteLocalRef(pointClassLocal);
     }
 
-    int screen = AwtWin32GraphicsDevice::GetDefaultDeviceIndex();
+    HMONITOR monitor = MonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
+    int screen = AwtWin32GraphicsDevice::GetScreenFromHMONITOR(monitor);
     Devices::InstanceAccess devices;
     AwtWin32GraphicsDevice *device = devices->GetDevice(screen);
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/MouseInfo/PointerInfoCrashTest.java	Mon Jan 11 06:10:32 2016 -0800
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2015, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.MouseInfo;
+import java.awt.Point;
+import java.awt.Toolkit;
+import java.awt.Window;
+import java.awt.peer.MouseInfoPeer;
+import sun.awt.ComponentFactory;
+
+/**
+ * @test
+ * @bug 8143316
+ * @modules java.desktop/java.awt.peer
+ *          java.desktop/sun.awt.peer
+ * @summary Crash Trend in 1.9.0-ea-b93 (sun.awt.DefaultMouseInfoPeer.fillPointWithCoords)
+ */
+public class PointerInfoCrashTest {
+
+    public static void main(String[] args) {
+        testMouseInfo();
+        testMouseInfoPeer();
+    }
+
+    private static void testMouseInfo() {
+        // call the getPointerInfo() before graphics devices initialization
+        MouseInfo.getPointerInfo();
+    }
+
+    private static void testMouseInfoPeer() {
+        Toolkit toolkit = Toolkit.getDefaultToolkit();
+        if (toolkit instanceof ComponentFactory) {
+            ComponentFactory componentFactory = (ComponentFactory) toolkit;
+
+            MouseInfoPeer mouseInfoPeer = componentFactory.getMouseInfoPeer();
+            mouseInfoPeer.fillPointWithCoords(new Point());
+
+            Window win = new Window(null);
+            win.setSize(300, 300);
+            win.setVisible(true);
+
+            mouseInfoPeer.isWindowUnderMouse(win);
+            win.dispose();
+        }
+    }
+}