changeset 13628:f4303cf0e9f9

8143316: Crash Trend in 1.9.0-ea-b93 (sun.awt.DefaultMouseInfoPeer.fillPointWithCoords) Reviewed-by: serb
author alexsch
date Mon, 11 Jan 2016 06:10:32 -0800
parents 70d3ec774d69
children 5bb70b2df494
files src/java.desktop/share/classes/sun/awt/DefaultMouseInfoPeer.java src/java.desktop/share/classes/sun/awt/SunToolkit.java src/java.desktop/windows/classes/sun/awt/windows/WMouseInfoPeer.java src/java.desktop/windows/classes/sun/awt/windows/WToolkit.java src/java.desktop/windows/native/libawt/windows/MouseInfo.cpp test/java/awt/MouseInfo/PointerInfoCrashTest.java
diffstat 6 files changed, 132 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/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/src/java.desktop/share/classes/sun/awt/SunToolkit.java	Sat Jan 09 14:04:32 2016 +0100
+++ b/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/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/src/java.desktop/windows/classes/sun/awt/windows/WToolkit.java	Sat Jan 09 14:04:32 2016 +0100
+++ b/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/src/java.desktop/windows/native/libawt/windows/MouseInfo.cpp	Sat Jan 09 14:04:32 2016 +0100
+++ b/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/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();
+        }
+    }
+}