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

AWT hang occurrs when sequenced events arrive out of sequence

XMLWordPrintable

    • b07
    • x86_64
    • windows_7

        FULL PRODUCT VERSION :
        java version "1.8.0_66"
        Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
        Java HotSpot(TM) Client VM (build 25.66-b17, mixed mode)

        Also seen with 8u51x86

        ADDITIONAL OS VERSION INFORMATION :
        Windows 7 Enterprise 64-bit (6.1, Build 7601) Service Pack 1 (7601.win7sp1_gdr.151230-0600)

        EXTRA RELEVANT SYSTEM CONFIGURATION :
        User systems I've seen this on tend to have a fair bit extra software (antivirus, skype, VNC server, etc, etc)

        A DESCRIPTION OF THE PROBLEM :
        As best as we can determine, system generated SequencedEvent(s) for window focus events (Focus Gained/Focus lost) are arriving into the event queue out of sequence.
        I have a SSCE that demonstrates that out of sequence SequencedEvents generate a hang.
        I'm not sure why the window events are arriving in the event queue out of sequence, timestamps between the first and second event have been seen to place the second event as having been created more than 20 seconds _before_ the first sequenced event, and also fewer than 200ms before.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Create two sequenced events. Submit them to the event queue in reverse order.

        We're seeing this happen with system generated Window Focus events (Focus Gained/Focus Lost) on 8u51 and 8u66. We're testing 8u74 (no results yet).

        The hang occurs every time the events arrive out of order, but they only arrive out of order infrequently. Often enough to be a significant problem to users. Rare enough to make troubleshooting difficult. Thus far, the faulty events have all been observed to be window focus events.


        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Sequenced Event lives up to its stated design:

        A mechanism for ensuring that a series of AWTEvents are executed in a
         precise order, even across multiple AppContexts. The nested events will be
        dispatched in the order in which their wrapping SequencedEvents were
        constructed.

        The second event to be submitted is processed first
        ACTUAL -
        The AWT Event Queue continues to queue events, but stops all event processing. The application is effectively hung.

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        Stack of the event thread - it always contains a SequencedEvent in the stack.
        Thread [AWT-EventQueue-0] (Suspended)
        Unsafe.park(boolean, long) line: not available [native method]
        LockSupport.park(Object) line: 175
        AbstractQueuedSynchronizer$ConditionObject.await() line: 2039
        EventQueue.getNextEvent(int) line: 608
        EventDispatchThread.pumpOneEventForFilters(int) line: 170
        EventDispatchThread.pumpEventsForFilter(int, Conditional, EventFilter) line: 116
        EventDispatchThread.pumpEventsForHierarchy(int, Conditional, Component) line: 105
        EventDispatchThread.pumpEvents(int, Conditional) line: 101
        SequencedEvent.dispatch() line: 107
        EventQueue.dispatchEventImpl(AWTEvent, Object) line: 756
        EventQueue.access$500(EventQueue, AWTEvent, Object) line: 97
        EventQueue$3.run() line: 709
        EventQueue$3.run() line: 703
        AccessController.doPrivileged(PrivilegedAction<T>, AccessControlContext) line: not available [native method]
        ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(PrivilegedAction<T>, AccessControlContext, AccessControlContext) line: 76
        ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(PrivilegedAction<T>, AccessControlContext) line: 86
        EventQueue$4.run() line: 731
        EventQueue$4.run() line: 729
        AccessController.doPrivileged(PrivilegedAction<T>, AccessControlContext) line: not available [native method]
        ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(PrivilegedAction<T>, AccessControlContext, AccessControlContext) line: 76
        EventQueue.dispatchEvent(AWTEvent) line: 728
        EventDispatchThread.pumpOneEventForFilters(int) line: 201
        EventDispatchThread.pumpEventsForFilter(int, Conditional, EventFilter) line: 116
        EventDispatchThread.pumpEventsForHierarchy(int, Conditional, Component) line: 105
        EventDispatchThread.pumpEvents(int, Conditional) line: 101
        EventDispatchThread.pumpEvents(Conditional) line: 93
        EventDispatchThread.run() line: 82


        REPRODUCIBILITY :
        This bug can be reproduced often.

        ---------- BEGIN SOURCE ----------
        package test.unsequenced;

        import java.awt.AWTEvent;
        import java.awt.FlowLayout;
        import java.awt.Toolkit;
        import java.awt.event.ActionEvent;
        import java.awt.event.ActionListener;
        import java.lang.reflect.Constructor;

        import javax.swing.JButton;
        import javax.swing.JFrame;
        import javax.swing.JTextArea;

        public class DummyWindow extends JFrame implements ActionListener
        {

            private static final long serialVersionUID = 1L;
            private JButton spamMeButton;

            public static void main(String[] args)
            {
                new DummyWindow().show();
            }
            
            public DummyWindow()
            {
                super("Test Window");
                
                setLayout(new FlowLayout());
                JTextArea textBlock = new JTextArea("Lorem ipsum dolor sit amet...");
                add(textBlock);

                spamMeButton = new JButton("Press me!");
                spamMeButton.addActionListener(this);
                add(spamMeButton);
                
                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                pack();
            }

            @Override
            public void actionPerformed(ActionEvent e)
            {
                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                if(e.getSource() == spamMeButton)
                {
                    AWTEvent eventOne = getSequencedEvent();
                    AWTEvent eventTwo = getSequencedEvent();

                    Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(eventTwo);
                    Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(eventOne);
                }
                
            }
            
            private AWTEvent getSequencedEvent()
            {
                AWTEvent wrapMe = new AWTEvent(this, AWTEvent.RESERVED_ID_MAX+1) {};
                try
                {
                    @SuppressWarnings("unchecked")
                    Class<? extends AWTEvent> seqClass = (Class<? extends AWTEvent>) Class.forName("java.awt.SequencedEvent");
                    Constructor<? extends AWTEvent> seqConst = seqClass.getConstructor(AWTEvent.class);
                    seqConst.setAccessible(true);
                    AWTEvent instance = seqConst.newInstance(wrapMe);
                    return instance;
                } catch (Throwable err)
                {
                    throw new Error("Unable to instantiate SequencedEvent",err);
                }
            }
        }

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

        CUSTOMER SUBMITTED WORKAROUND :
        None yet (still trying).

              kaddepalli Krishna Addepalli
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

                Created:
                Updated:
                Resolved: