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

AWT object being painted and disposed in race condition causing hang/assert fail

    XMLWordPrintable

Details

    • b01
    • x86
    • windows_nt
    • Not verified

    Description

      (GuiHang - see below) application can be made to hang or throw assertion failures (in java_g) quite easily.

      The problem is that the java code is (indirectly) disposing some objects
      while they're being painted. The AWT code for NT appears to have been
      written very carefully to
        a) make sure messages are handled before the Windows object is
           destroyed, and
        b) make sure that if the Java and C++ objects have been destroyed,
           the message is handled safely.

      The problem is that there is no lock to prevent painting (or any other
      message handling) from occurring at the same time, on the same object,
      that is being disposed.
      The 60 line program below causes the user interface to freeze if you hit
      the "Hurt Me" button enough times (somewhere between 2 and 20 for us on our
      NT machines).
       
      Some relevant facts are:
       
      1. Windows NT, JDK 1.1.1 and JRE 1.1.1 fail; AIX 1.1 does not fail
      2. Press the "Hurt Me" button faster than the screen can repaint
      3. When the failure occurs, the jdb info is shown below. Note that threads
      5 and 6 are "running", and thread 5 is in
      sun.awt.windows.WComponentPeer.dispose (WComponentPeer:121). It never
      comes back.
      4. When I try to kill the java process running GuiHang, it dumps the stuff
      shown
      in the last snippet below. If I understand it correctly, the
      "AWT-EventQueue-0" thread and the "Debugger Agent" are the only threads
      holding monitors, so it
      doesn't look like a deadly embrace of monitors.
      5. Our product has seen other failure symptoms including the one shown by
      GuiHang.
      They all seem to relate to the AWT. See the last section of this note for
      some more info.
       
      ------ the test program
      -----------------------------------------------------------
      import java.awt.*;
      import java.awt.event.*;
       
      public class GuiHang {
        public Frame frame;
        public BigPanel bp;
        public static final int Rows = 50;
       
        private void init() {
          frame = new Frame("GUI Hang");
          frame.setLayout(new BorderLayout());
       
          Button button = new Button("Hurt Me");
          button.addActionListener(new NavigateListener());
          frame.add("West", button);
       
          bp = new BigPanel(Rows);
          frame.add("Center", bp);
          frame.setBounds(50, 50, 400, 600);
          frame.show();
        }
       
        public void navigate() {
          frame.remove(bp);
          bp = new BigPanel(Rows);
          frame.add("Center", bp);
          frame.invalidate();
          frame.validate();
        }
       
        public class NavigateListener implements ActionListener {
          public void actionPerformed(ActionEvent e) {
            navigate();
          }
        }
       
        public static void main(String argv[]) {
          GuiHang gh;
       
          gh = new GuiHang();
          gh.init();
        }
      }
       
      class BigPanel extends Panel {
        public BigPanel(int numRows) {
          setLayout(new GridLayout(numRows, 2));
          for(int i = 0; i < numRows; i++) {
            add(new Label("Row "+(i+1)));
            TextField field = new TextField();
            field.setColumns(30);
            add(field);
          }
        }
      }
       


      Attachments

        Activity

          People

            jlockesunw Jonathan Locke (Inactive)
            rschiavisunw Richard Schiavi (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: