Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8189934

[macos] Component.getMousePosition() is slow

    Details

    • Subcomponent:
    • Introduced In Version:
    • CPU:
      x86_64
    • OS:
      os_x

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_152"
      Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
      Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      macOS 10.13 (17A405)

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      MacBook Pro (13-inch, 2016, Four Thunderbolt 3 Ports)
      2,9 GHz Intel Core i5
      16 GB 2133 MHz LPDDR3
      Intel Iris Graphics 550 1536 MB

      A DESCRIPTION OF THE PROBLEM :
      Calling of Component.getMousePosition() became about 100 times slower compared to the previous versions of java.

      The first version in which I observe this behaviour is:

      java version "1.8.0_131"
      Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
      Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

      This is possibly related to the fix of the bug JDK-8169589 that was fixed in this version.

      Works fine with:

      java version "1.8.0_121"
      Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

      REGRESSION. Last worked in version 7u80

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.8.0_121"
      Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run this code:



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The time for 10 calls of getMousePosition() is calculated and printed every second.
      On the previous versions of java this was about 1-2 milliseconds.
      ACTUAL -
      For the latest version of java 1.8.0_152 I see time about 70 milliseconds when I do not move the mouse within the window and about 200 milliseconds if I move the mouse within the window



      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------


      import java.awt.Dimension;
      import java.awt.GridLayout;
      import java.awt.Point;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;

      import javax.swing.BorderFactory;
      import javax.swing.JFrame;
      import javax.swing.JPanel;
      import javax.swing.JTextArea;
      import javax.swing.Timer;

      public class MousePositionTest extends JPanel {

      JTextArea textArea;
      Timer timer;

      public static void main(String[] args) {
      javax.swing.SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
      JFrame frame = new JFrame("MousePositionTest");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setContentPane(new MousePositionTest());
      frame.pack();
      frame.setVisible(true);
      }
      });
      }

      public MousePositionTest() {
      super(new GridLayout(0, 1));
      textArea = new JTextArea();
      textArea.setEditable(false);
      add(textArea);
      setPreferredSize(new Dimension(400, 400));
      setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
      timer = new Timer(1000, new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
      long time = System.currentTimeMillis();
      Point pos = null;
      for (int i = 1; i < 10; i++) {
      pos = getMousePosition();
      }
      time -= System.currentTimeMillis();
      textArea.setText("pos = " + pos + " [" + -time + "ms]");
      }
      });
      timer.start();
      }

      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use Java 1.8.0_121 or earlier

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                serb Sergey Bylokhov
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated: