Hi Petr,
Here is the dump of the Appkit thread and the AWT Thread. As I indicated 
earlier our original application does not call invokeAndWait, it uses 
invokeLater to make changes to the frame once the frame is created in Appkit 
thread. Also I see this issue with SWT 3.7.2 as well as the latest 4.3.

"AWT-EventQueue-0" prio=5 tid=0x00007fcc9b357000 nid=0xbf03 runnable 
[0x0000000167cac000]
   java.lang.Thread.State: RUNNABLE
        at sun.lwawt.macosx.CCursorManager.nativeGetCursorPosition(Native 
Method)
        at 
sun.lwawt.macosx.CCursorManager.getCursorPosition(CCursorManager.java:54)
        at sun.lwawt.LWCursorManager.updateCursorImpl(LWCursorManager.java:79)
        at sun.lwawt.LWCursorManager.updateCursor(LWCursorManager.java:56)
        at 
sun.lwawt.LWComponentPeer.updateCursorImmediately(LWComponentPeer.java:852)
        at java.awt.Component.updateCursorImmediately(Component.java:3123)
        at java.awt.Component.hide(Component.java:1696)
        - locked <0x0000000158b7a4e0> (a java.awt.Component$AWTTreeLock)
        at java.awt.Window.hide(Window.java:1116)
        at sun.awt.EmbeddedFrame.hide(EmbeddedFrame.java:192)
        at java.awt.Component.show(Component.java:1653)
        at java.awt.Component.setVisible(Component.java:1603)
        at java.awt.Window.setVisible(Window.java:1014)
        at 
com.tibco.cep.studio.ui.overview.OverviewUtils.refreshOverview(OverviewUtils.java:122)
        at 
com.tibco.cep.studio.ui.overview.OverviewUtils$1.run(OverviewUtils.java:51)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
        at java.awt.EventQueue.access$200(EventQueue.java:103)
        at java.awt.EventQueue$3.run(EventQueue.java:694)
        at java.awt.EventQueue$3.run(EventQueue.java:692)
        at java.security.AccessController.doPrivileged(Native Method)
        at 
java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
        at 
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
        at 
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
        at 
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

   Locked ownable synchronizers:
        - None
 
"AppKit Thread" prio=5 tid=0x00007fcc9a803800 nid=0x707 waiting for monitor 
entry [0x00007fff58cb2000]
   java.lang.Thread.State: BLOCKED (on object monitor)
        at java.awt.Container.addImpl(Container.java:1077)
        - waiting to lock <0x0000000158b7a4e0> (a 
java.awt.Component$AWTTreeLock)
        at java.awt.Container.add(Container.java:966)
        at 
com.tomsawyer.canvas.swing.TSBaseSwingCanvas.setInnerCanvas(SourceFile:4258)
        at 
com.tomsawyer.interactive.swing.TSSwingCanvas.setInnerCanvas(SourceFile:798)
        at 
com.tomsawyer.canvas.swing.TSBaseSwingCanvas.createGUI(SourceFile:3870)
        at com.tomsawyer.canvas.swing.TSBaseSwingCanvas.<init>(SourceFile:138)
        at com.tomsawyer.interactive.swing.TSSwingCanvas.<init>(SourceFile:160)
        at com.tomsawyer.interactive.swing.TSSwingCanvas.<init>(SourceFile:138)
        at 
com.tibco.cep.diagramming.drawing.DrawingCanvas.<init>(DrawingCanvas.java:37)
        at 
com.tibco.cep.diagramming.drawing.DiagramManager.initialize(DiagramManager.java:233)
        at 
com.tibco.cep.diagramming.drawing.DiagramManager.<init>(DiagramManager.java:196)
        at 
com.tibco.cep.studio.ui.diagrams.EntityDiagramManager.<init>(EntityDiagramManager.java:135)
        at 
com.tibco.cep.studio.ui.diagrams.EventDiagramManager.<init>(EventDiagramManager.java:87)
        at 
com.tibco.cep.studio.ui.editors.events.EventDiagramEditor.getDiagramManager(EventDiagramEditor.java:24)
        at 
com.tibco.cep.studio.ui.editors.EntityDiagramEditor.addFormPage(EntityDiagramEditor.java:85)
        at 
com.tibco.cep.studio.ui.editors.EntityDiagramEditor.createUIEditorPage(EntityDiagramEditor.java:77)
        at 
com.tibco.cep.studio.ui.editors.EntityDiagramEditor.createPages(EntityDiagramEditor.java:54)
        at 
org.eclipse.ui.part.MultiPageEditorPart.createPartControl(MultiPageEditorPart.java:348)
        at 
org.eclipse.ui.internal.EditorReference.createPartHelper(EditorReference.java:670)
        at 
org.eclipse.ui.internal.EditorReference.createPart(EditorReference.java:465)
        at 
org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:595)
        at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:313)
        at 
org.eclipse.ui.internal.presentations.PresentablePart.setVisible(PresentablePart.java:180)
        at 
org.eclipse.ui.internal.presentations.util.PresentablePartFolder.select(PresentablePartFolder.java:270)
        at 
org.eclipse.ui.internal.presentations.util.LeftToRightTabOrder.select(LeftToRightTabOrder.java:65)
        at 
org.eclipse.ui.internal.presentations.util.TabbedStackPresentation.selectPart(TabbedStackPresentation.java:473)
        at 
org.eclipse.ui.internal.PartStack.refreshPresentationSelection(PartStack.java:1245)
        at org.eclipse.ui.internal.PartStack.setSelection(PartStack.java:1198)
        at 
org.eclipse.ui.internal.PartStack.presentationSelectionChanged(PartStack.java:834)
        at org.eclipse.ui.internal.PartStack.access$1(PartStack.java:823)
        at org.eclipse.ui.internal.PartStack$1.selectPart(PartStack.java:137)
        at 
org.eclipse.ui.internal.presentations.util.TabbedStackPresentation$1.handleEvent(TabbedStackPresentation.java:133)
        at 
org.eclipse.ui.internal.presentations.util.AbstractTabFolder.fireEvent(AbstractTabFolder.java:269)
        at 
org.eclipse.ui.internal.presentations.util.AbstractTabFolder.fireEvent(AbstractTabFolder.java:278)
        at 
org.eclipse.ui.internal.presentations.defaultpresentation.DefaultTabFolder.access$1(DefaultTabFolder.java:1)
        at 
org.eclipse.ui.internal.presentations.defaultpresentation.DefaultTabFolder$2.handleEvent(DefaultTabFolder.java:88)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
        at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4128)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1457)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1480)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1465)
        at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1270)
        at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:2746)
        at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:1433)
        at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:257)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
        at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4128)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1457)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1480)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1465)
        at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1270)
        at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3974)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3613)
        at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
        at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
        at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
        at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
        at 
org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
        at 
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
        at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
        at 
org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
        at 
org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
        at 
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
        at 
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
        at 
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
        at 
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
        at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
        at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
        at org.eclipse.equinox.launcher.Main.main(Main.java:1386)

   Locked ownable synchronizers:
        - None



On Nov 18, 2013, at 10:55 PM, Petr Pchelko <petr.pche...@oracle.com> wrote:

> Hello, Viral.
> 
> It's known that there are some deadlocks in SWT_AWT bridge on Mac. Here's an 
> example:
> https://bugs.openjdk.java.net/browse/JDK-8020165
> 
> It would be useful if you also post the dump of an Appkit thread to identify 
> your particular case.
> 
> The deadlock occurs because AWT is called on the main thread. So the main 
> thread get blocked
> on some internal AWT lock, while the EventDispatchThread is trying to perform 
> a synchronous operation
> on the main thread. It's not quite obvious how to fix that internally, 
> because for the normal AWT application
> we have a strict rule not to acquire locks on the Appkit thread. 
> 
> For now the workaround could be to wrap all the usages of AWT inside 
> invokeLater (except the initial  
> SWT_AWT.new_Frame(composite) call). This should fix your deadlock. 
> 
> Also, which version of SWT are you using? The newer versions are patched so 
> that you could not set the 
> embeddedFrameClass explicitly. That patch also contains additional changes in 
> bridge initialization,
> so the bridge does not work quite well with older versions. This could be 
> another reason of your deadlock.
> 
> With best regards. Petr.
> 
> On 19.11.2013, at 2:51, Viral Barot <vba...@tibco.com> wrote:
> 
>> Accessing AWT frame from a thread causes the application to freeze when 
>> executed with JRE 7. The AWT frame is created with SWT_AWT bridge.
>> 
>> Below is the test case in which call to frame.setVisible(true); from the AWT 
>> event dispatching thread does not return.
>> 
>> Test Case:
>> import java.awt.Button;
>> import java.awt.Color;
>> import java.awt.event.ActionEvent;
>> import java.awt.event.ActionListener;
>> import java.lang.reflect.InvocationTargetException;
>> 
>> import javax.swing.JOptionPane;
>> import javax.swing.SwingUtilities;
>> 
>> import org.eclipse.swt.SWT;
>> import org.eclipse.swt.awt.SWT_AWT;
>> import org.eclipse.swt.layout.GridLayout;
>> import org.eclipse.swt.widgets.Display;
>> import org.eclipse.swt.widgets.Shell;
>> import org.eclipse.swt.widgets.Composite;
>> 
>> public class Main {
>> 
>> public static void main(String[] args) {
>> 
>> 
>> 
>> if(System.getProperty("os.name").toLowerCase().startsWith("mac")){
>> SWT_AWT.embeddedFrameClass = "sun.lwawt.macosx.CViewEmbeddedFrame";
>> }
>> 
>> 
>>   Display display = new Display();
>>   Shell shell = new Shell(display);
>>   shell.setText("Shell");
>>   shell.setSize(200, 200);
>>   shell.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLUE));
>> 
>> 
>> 
>>   final Composite composite = new Composite(shell, SWT.EMBEDDED);
>>   GridLayout gridLayout = new GridLayout();
>>   gridLayout.numColumns = 1;
>>   composite.setLayout(gridLayout);
>>   composite.setSize(200,200);
>>   
>> composite.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
>> 
>> 
>> 
>>   final java.awt.Frame frame  = SWT_AWT.new_Frame(composite);
>> frame.setVisible(false);
>> frame.setBackground(Color.red);
>> frame.setSize(200, 200);
>>   Button button = new Button("Submit");
>>   button.addActionListener(new ActionListener() {
>> 
>> 
>> @Override
>> public void actionPerformed(ActionEvent e) {
>> 
>> 
>> JOptionPane.showMessageDialog(null, "Hello");
>> }
>> });
>>   frame.add(button);
>>   frame.doLayout();
>> 
>> 
>> 
>>   try {
>> SwingUtilities.invokeAndWait(new Runnable() {
>> 
>> 
>> @Override
>> public void run() {
>> frame.setVisible(true);
>> }
>> });
>> } catch (InterruptedException e1) {
>> e1.printStackTrace();
>> } catch (InvocationTargetException e1) {
>> e1.printStackTrace();
>> }
>>   shell.open();
>> 
>> 
>> 
>>   while (!shell.isDisposed()) {
>>     if (!display.readAndDispatch())
>>       display.sleep();
>>   }
>>   display.dispose();
>> 
>> 
>> 
>> }
>> }
>> 
>> Below is the thread dump for this.
>> 
>> "AWT-EventQueue-0" prio=5 tid=0x00007f8d0b087000 nid=0x8703 runnable 
>> [0x0000000195e40000]
>>  java.lang.Thread.State: RUNNABLE
>> at sun.lwawt.macosx.CCursorManager.nativeGetCursorPosition(Native Method)
>> at sun.lwawt.macosx.CCursorManager.getCursorPosition(CCursorManager.java:54)
>> at sun.lwawt.LWCursorManager.updateCursorImpl(LWCursorManager.java:79)
>> at sun.lwawt.LWCursorManager.updateCursor(LWCursorManager.java:56)
>> at 
>> sun.lwawt.LWComponentPeer.updateCursorImmediately(LWComponentPeer.java:852)
>> at java.awt.Component.updateCursorImmediately(Component.java:3123)
>> at java.awt.Component.show(Component.java:1626)
>> - locked <0x0000000160c5b8c8> (a java.awt.Component$AWTTreeLock)
>> at java.awt.Window.show(Window.java:1042)
>> at sun.awt.EmbeddedFrame.show(EmbeddedFrame.java:179)
>> at java.awt.Component.show(Component.java:1651)
>> at java.awt.Component.setVisible(Component.java:1603)
>> at java.awt.Window.setVisible(Window.java:1014)
>> at Main$2.run(Main.java:60)
>> at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:241)
>> at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
>> at java.awt.EventQueue.access$200(EventQueue.java:103)
>> at java.awt.EventQueue$3.run(EventQueue.java:694)
>> at java.awt.EventQueue$3.run(EventQueue.java:692)
>> at java.security.AccessController.doPrivileged(Native Method)
>> at 
>> java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
>> at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
>> at 
>> java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
>> at 
>> java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
>> at 
>> java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
>> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
>> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
>> at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
>> 
>>  Locked ownable synchronizers:
>> - None
>> 
>> While in the above test case if invokeLater is called instead of 
>> invokeAndWait, the test case runs fine. But in my application the 
>> invokeLater calls also freeze at same location.
>> 
>> This behavoir happens with SWT 3.7.2 as well as 4.3.
>> 
>> 
>> 
>> 
> 

Reply via email to