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

REGRESSION:GridBagLayout causes an extreme slowdown during doLayout on Liunx

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 5.0
    • client-libs
    • x86
    • linux

      ###@###.### 2004-07-27

      J2SE Version (please include all output from java -version flag):
       java version "1.5.0-beta3"
       Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta3-b59)
       Java HotSpot(TM) Client VM (build 1.5.0-beta3-b59, mixed mode)

      Does this problem occur on J2SE 1.3, 1.4 or 1.4.1? Yes / No (pick one)
       Works fine with windows machine or on Linux under JDK1.3.
       But slowness happen on Linux JDK1.4.2 and the latest JDK1.5 beta.

      Operating System Configuration Information (be specific):
       Linux

      Bug Description:
        Found a problem with GridBagLayout which causes an extreme
        slowdown (up to a minute) during the doLayout method. It occurs on
        Linux, JDK1.4.2 and the latest JDK1.5 beta. It does not occur on Windows
        or on Linux under JDK1.3 and the performance of layout is almost
        instantaneous.
       
        We have a window, which is a JComponent, which includes a canvas which
        is also a JComponent and two JScrollbars. We initialize the window like
        this:
       
        GridBagConstraints constraints = new GridBagConstraints();
       
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.weightx = 1;
        constraints.weighty = 1;
        constraints.fill = GridBagConstraints.BOTH;
       
        this.add(canvas, constraints);
       
        this.horizontalScrollBar = new JScrollBar(SwingConstants.HORIZONTAL);
       
        this.verticalScrollBar = new JScrollBar(SwingConstants.VERTICAL);
       
        GridBagConstraints constraints = new GridBagConstraints();
       
         constraints.gridx = 1;
         constraints.gridy = 0;
         
       
         constraints.weightx = 0;
         constraints.weighty = 0;
         constraints.fill = GridBagConstraints.VERTICAL;
       
         this.add(this.verticalScrollBar, constraints);
       
         constraints.gridx = 0;
         constraints.gridy = 1;
         
          constraints.weightx = 0;
         constraints.weighty = 0;
         constraints.fill = GridBagConstraints.HORIZONTAL;
       
         this.add(this.horizontalScrollBar, constraints);
       
       
        At this point everything shows up ok.
       
        Then, when a certain action happens, we need to hide the scrollbars. We
        do it like this:
       
          horizontalScrollBar.setVisible(false);
          verticalScrollBar.setVisible(false);
         
          this.doLayout();
          
           SwingUtilities.invokeLater(
            new Runnable()
            {
             public void run()
             {
              getHorizontalScrollBar().revalidate();
              getVerticalScrollBar().revalidate();
             }
            });
         }
       
        This is when the slowdown occurs and it takes up to a minute for
        scrollbars to disappear. It's almost instantaneous on JDK1.3 and on
        Windows platform, but very slow on Linux JDK1.4.2_04 and 1.5 beta build 58
       
        There is additional factor which may or may not be relevant. When
        the canvas is resized (as happens during the doLayout call) we need to
        repaint the drawing that is painted on it. So we override the setBounds
        method like this:
       
        public void setBounds(int x, int y, int width, int height)
         {
          super.setBounds(x, y, width, height);
          Image buffer = this.createImage(width, height);
          draw(buffer.getGraphics());

         }
       
        The draw routine is pretty complicated, but our customer who initially
        found the problem gave us a snapshot stack of the thread when the
        slowdown occurs. Here is the relevant portion:
       
        at sun.awt.image.DataBufferNative.setElem(Native Method)
        at sun.awt.image.DataBufferNative.setElem(DataBufferNative.java:71)
        at java.awt.image.DataBuffer.setElem(DataBuffer.java:244)
        at
      java.awt.image.SinglePixelPackedSampleModel.setDataElements(SinglePixelPackedSampleModel.java:605)
        at java.awt.image.WritableRaster.setDataElements(WritableRaster.java:265)
        at sun.java2d.loops.SolidPixelWriter.writePixel(GeneralRenderer.java:863)
        at sun.java2d.loops.GeneralRenderer.doSetRect(GeneralRenderer.java:141)
        at sun.java2d.loops.SetFillRectANY.FillRect(GeneralRenderer.java:615)
        at sun.java2d.pipe.LoopPipe.fillRect(LoopPipe.java:106)
        at sun.java2d.pipe.ValidatePipe.fillRect(ValidatePipe.java:46)
        at sun.java2d.SunGraphics2D.fillRect(SunGraphics2D.java:2066)
       

      Steps to Reproduce (be specific):
       - Add attached tsall.jar to the classpath
       - Compile SimpleEditor.java
       - run SimpleEditor

      You will see a window with a grey rectangle. Drag the grey rectangle to the
      edge of the window.

      Result: scrollbars will appear. On Windows and Linux JDK1.3.1 this is
      instantaneious, but on Linux JDK1.4+ it will take some time.

            son Oleg Sukhodolsky (Inactive)
            tyao Ting-Yun Ingrid Yao (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: