GenericDialog and imagej lockups

Posted by Fred Damen on
URL: http://imagej.273.s1.nabble.com/GenericDialog-and-imagej-lockups-tp5023908.html

Greetings,

I am able to consitently get imagej to lock up, and I am a loss at what I
am directly or indirectly doing to cause this.  The scenario is:
my plugin DICOM_open creates a GenericDialog with an addDialogListener,
which displays and after showDialog returns opens a set of DICOM files as
a hyperstack.  After this I run another plugin, Diffusion_Multimodal,
which creates a GenericDialog and after the showDialog processes this
hyperstack creating a set of images in windows; these windows have
listeners - method that add and removes listener is below. Closing the
hyperstack and running DICOM_open again causes imagej to lockup within
showDialog, see first entry in thread stack traces.

I can run DICOM_open only, over and over again, without any lockup.  I can
run Diffusion_Multimodal, after the first DICOM_open, over and over again
without any lockup.  Although, running DICOM_open after
Diffusion_Multimodal lockups everytime.  I have run this code lots and
lots in the past and do not remember this scenario ever happening.

I discovered this on release 1.52u14 and confirmed it still happens on
1.53e14.  Any insites and / or suggestion on how to debug this would be
greatly appriciated.

Thanks in advance,

Fred

relevant code from DICOM_open.run
===============
      DirectoryChooser dc = new DirectoryChooser("Select Root Directory of
your DICOM datasets");
      String sdir = dc.getDirectory();
IJ.log("sdir = "+sdir);
      if (sdir == null) return;
      path = new File(sdir);

      loc = (Point)IJ.getProperty("PreferedLocation");
      GenericDialog gd = new GenericDialog("Select DICOM dataset");
IJ.log("GenericDialog new");
      if (loc != null) gd.setLocation(loc.x, loc.y);
      gd.addMessage(path.getAbsolutePath(), new Font("Monospaced",
Font.BOLD, 12));
      where = (Label)gd.getMessage();

IJ.log("GenericDialog Choice");
      gd.addChoice("", scan(path),"");
      which = (Choice)gd.getChoices().get(0);
      gd.addToSameRow();
      gd.addCheckbox("Info",false);
      ((Checkbox)gd.getCheckboxes().get(0)).setEnabled(false);

      gd.addMessage(padR("Subject",50)+"\n"+
                    padR("Date",50)+"\n"+
                    padR("Description",50), new Font("Monospaced",
Font.BOLD, 12));
      info = (MultiLineLabel)gd.getMessage();
      updateFields(path);

IJ.log("GenericDialog Choice");
      gd.addChoice("Diffusion", new String[]{"<Nope>","Trace","X", "Y",
"Z"},"<Nope>");
      diff = (Choice)gd.getChoices().get(1);
      gd.addToSameRow();
      gd.addStringField("Var",""); gd.addToSameRow();
gd.addStringField("Tag","",10);
      var = (TextField)gd.getStringFields().get(0);
      tag = (TextField)gd.getStringFields().get(1);

      gd.addRadioButtonGroup("Format:", new String[]{"Float","Scaled",
"16-bit fixed", "16-bit broken"}, 1, 4, "16-bit fixed");

      gd.addDialogListener(this);
      gd.setOKLabel("Tell Me More");
IJ.log("GenericDialog showDialog");
      gd.showDialog();
      if (gd.wasCanceled())
         return;

===============

assumed relevant code from Diffusion_Multimodal:
===============
   private void setupPlotting(ImagePlus imp, ImagePlus[] Rimps) {
      imp.getWindow().addWindowListener(this);
      imp.getWindow().getCanvas().addMouseListener(this);
      imp.getWindow().getCanvas().addMouseMotionListener(this);
      imp.getWindow().getCanvas().addKeyListener(this);

      engaged = true;

      for(ImagePlus rimp : Rimps)
         rimp.setZ(imp.getZ());
      for(ImagePlus rimp : Rimps)
         rimp.getWindow().addWindowListener(this);
      }

    boolean engaged = false;
    void disengage(ImageWindow iw) {
       if (!engaged) return;

       if (Rimps == null) {
          IJ.log("MultiModal_diffusion.disengage called with Rimps == null");
          return;
          }

       boolean oneOfUs = false;
       for(ImagePlus imp : Rimps)
          if (iw.getImagePlus() == imp)
             oneOfUs = true;
       if (!oneOfUs)
          return;

       if (dimp == null)
          IJ.showStatus("diffusion_MultiModal disengage DWI null");
       else {
          dimp.getWindow().getCanvas().removeMouseListener(this);
          dimp.getWindow().getCanvas().removeMouseMotionListener(this);
          dimp.getWindow().getCanvas().removeKeyListener(this);
          dimp.getWindow().removeWindowListener(this);

          engaged = false;
          IJ.showStatus("Multimodal Diffusion Disengaged");
          IJ.log("Multimodal Diffusion Disengaged");
          }

       if (Rimps != null) {
          for(ImagePlus rimp : Rimps)
             rimp.getWindow().removeWindowListener(this);
          for(ImagePlus imp : Rimps) {
             IJ.log("Closing: "+imp.getTitle());
             if (imp != null && imp.getWindow() != null)
imp.getWindow().close();
             }
          }

       for(int i=0; i<pwv.size(); i++)
          pwv.get(i).close();
       }
===============

$ imagej -x2048

Image display and analysis program. Opens formats including:
UNC, Analyze, Dicom, NIFTI, Tiff, Jpeg, Gif, PNG ...

imagej [options] image [ image2 ... image3 ]
    -h        print help and more options
    -o        open images in an open ImageJ panel
    -p <N>    open images in ImageJ panel number <N>
    -x <MB>   set available memory (default=2048 max=32023)

Open other images in this ImageJ panel as follows:
  imagej -p 11 <image1> [<image2> ... <imageN>]

^\2020-09-04 12:28:26
Full thread dump OpenJDK 64-Bit Server VM (25.232-b09 mixed mode):

"DICOM open" #272 prio=4 os_prio=0 tid=0x00007f294c154000 nid=0x14c054 in
Object.wait() [0x00007f29ac932000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        at java.lang.Object.wait(Object.java:502)
        at java.awt.WaitDispatchSupport.enter(WaitDispatchSupport.java:264)
        - locked <0x00000000800a4318> (a java.awt.Component$AWTTreeLock)
        at java.awt.Dialog.show(Dialog.java:1084)
        at java.awt.Component.show(Component.java:1671)
        at java.awt.Component.setVisible(Component.java:1623)
        at java.awt.Window.setVisible(Window.java:1014)
        at java.awt.Dialog.setVisible(Dialog.java:1005)
        at ij.gui.GenericDialog.showDialog(GenericDialog.java:1381)
        at DICOM_open.run(DICOM_open.java:80)
        at ij.IJ.runUserPlugIn(IJ.java:240)
        at ij.IJ.runUserPlugIn(IJ.java:255)
        at ij.IJ.runPlugIn(IJ.java:203)
        at ij.Executer.runCommand(Executer.java:150)
        at ij.Executer.run(Executer.java:68)
        at java.lang.Thread.run(Thread.java:748)

"Close" #270 prio=4 os_prio=0 tid=0x00007f294c121800 nid=0x14c027 in
Object.wait() [0x00007f29adb44000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        at java.lang.Object.wait(Object.java:502)
        at java.awt.EventQueue.invokeAndWait(EventQueue.java:1343)
        - locked <0x00000000e2936900> (a java.awt.EventQueue$1AWTInvocationLock)
        at java.awt.Window.doDispose(Window.java:1210)
        at java.awt.Window.dispose(Window.java:1147)
        at ij.gui.ImageWindow.close(ImageWindow.java:444)
        at ij.gui.StackWindow.close(StackWindow.java:204)
        at ij.ImagePlus.close(ImagePlus.java:447)
        at ij.plugin.Commands.closeImage(Commands.java:138)
        at ij.plugin.Commands.close(Commands.java:83)
        at ij.plugin.Commands.run(Commands.java:29)
        at ij.IJ.runPlugIn(IJ.java:209)
        at ij.Executer.runCommand(Executer.java:150)
        at ij.Executer.run(Executer.java:68)
        at java.lang.Thread.run(Thread.java:748)

"TimerQueue" #24 daemon prio=5 os_prio=0 tid=0x00007f294c170000
nid=0x14bebd waiting on condition [0x00007f29ad53b000]
   java.lang.Thread.State: WAITING (parking)
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0x00000000801b2368> (a
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
        at
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
        at java.util.concurrent.DelayQueue.take(DelayQueue.java:211)
        at javax.swing.TimerQueue.run(TimerQueue.java:174)
        at java.lang.Thread.run(Thread.java:748)

"DestroyJavaVM" #20 prio=5 os_prio=0 tid=0x00007f29e804c800 nid=0x14be83
waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Run$_AWT-EventQueue-0" #17 prio=6 os_prio=0 tid=0x00007f29e8527000
nid=0x14be9e waiting on condition [0x00007f29ae038000]
   java.lang.Thread.State: WAITING (parking)
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0x00000000801d2088> (a
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
        at
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
        at java.awt.EventQueue.getNextEvent(EventQueue.java:554)
        at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:187)
        at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
        at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:109)
        at java.awt.WaitDispatchSupport$2.run(WaitDispatchSupport.java:190)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
        at java.awt.EventQueue.access$500(EventQueue.java:97)
        at java.awt.EventQueue$3.run(EventQueue.java:709)
        at java.awt.EventQueue$3.run(EventQueue.java:703)
        at java.security.AccessController.doPrivileged(Native Method)
        at
java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
        at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
        at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
        at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

"AWT-Shutdown" #18 prio=5 os_prio=0 tid=0x00007f29e8525800 nid=0x14be9d in
Object.wait() [0x00007f29ae13a000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        at java.lang.Object.wait(Object.java:502)
        at sun.awt.AWTAutoShutdown.run(AWTAutoShutdown.java:295)
        - locked <0x00000000801d9e78> (a java.lang.Object)
        at java.lang.Thread.run(Thread.java:748)

"AWT-XAWT" #16 daemon prio=6 os_prio=0 tid=0x00007f29e8428800 nid=0x14be9c
runnable [0x00007f29ae43b000]
   java.lang.Thread.State: RUNNABLE
        at sun.awt.X11.XToolkit.waitForEvents(Native Method)
        at sun.awt.X11.XToolkit.run(XToolkit.java:574)
        at sun.awt.X11.XToolkit.run(XToolkit.java:538)
        at java.lang.Thread.run(Thread.java:748)

"Java2D Disposer" #14 daemon prio=10 os_prio=0 tid=0x00007f29e83fc000
nid=0x14be9b in Object.wait() [0x00007f29ae53c000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144)
        - locked <0x00000000801d2310> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:165)
        at sun.java2d.Disposer.run(Disposer.java:148)
        at java.lang.Thread.run(Thread.java:748)

"GC Daemon" #13 daemon prio=2 os_prio=0 tid=0x00007f29e83ae000
nid=0x14be9a in Object.wait() [0x00007f29c020e000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x0000000080001c78> (a sun.misc.GC$LatencyLock)
        at sun.misc.GC$Daemon.run(GC.java:117)
        - locked <0x0000000080001c78> (a sun.misc.GC$LatencyLock)

"RMI Reaper" #12 prio=5 os_prio=0 tid=0x00007f29e83a8800 nid=0x14be99 in
Object.wait() [0x00007f29c030f000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x0000000080008698> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144)
        - locked <0x0000000080008698> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:165)
        at sun.rmi.transport.ObjectTable$Reaper.run(ObjectTable.java:351)
        at java.lang.Thread.run(Thread.java:748)

"RMI TCP Accept-0" #11 daemon prio=5 os_prio=0 tid=0x00007f29e83a4000
nid=0x14be98 runnable [0x00007f29c0410000]
   java.lang.Thread.State: RUNNABLE
        at java.net.PlainSocketImpl.socketAccept(Native Method)
        at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:409)
        at java.net.ServerSocket.implAccept(ServerSocket.java:560)
        at java.net.ServerSocket.accept(ServerSocket.java:528)
        at
sun.rmi.transport.tcp.TCPTransport$AcceptLoop.executeAcceptLoop(TCPTransport.java:405)
        at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.run(TCPTransport.java:377)
        at java.lang.Thread.run(Thread.java:748)

"Service Thread" #9 daemon prio=9 os_prio=0 tid=0x00007f29e8143800
nid=0x14be96 runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C1 CompilerThread3" #8 daemon prio=9 os_prio=0 tid=0x00007f29e8130800
nid=0x14be95 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread2" #7 daemon prio=9 os_prio=0 tid=0x00007f29e812e800
nid=0x14be94 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread1" #6 daemon prio=9 os_prio=0 tid=0x00007f29e812c800
nid=0x14be93 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread0" #5 daemon prio=9 os_prio=0 tid=0x00007f29e811d800
nid=0x14be92 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Signal Dispatcher" #4 daemon prio=9 os_prio=0 tid=0x00007f29e811b800
nid=0x14be91 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Finalizer" #3 daemon prio=8 os_prio=0 tid=0x00007f29e80f1000 nid=0x14be90
in Object.wait() [0x00007f29c0fd3000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144)
        - locked <0x0000000080018348> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:165)
        at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:216)

"Reference Handler" #2 daemon prio=10 os_prio=0 tid=0x00007f29e80ec800
nid=0x14be8f in Object.wait() [0x00007f29c10d4000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        at java.lang.Object.wait(Object.java:502)
        at java.lang.ref.Reference.tryHandlePending(Reference.java:191)
        - locked <0x0000000080010b18> (a java.lang.ref.Reference$Lock)
        at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)

"VM Thread" os_prio=0 tid=0x00007f29e80e2800 nid=0x14be8e runnable

"GC task thread#0 (ParallelGC)" os_prio=0 tid=0x00007f29e805f800
nid=0x14be84 runnable

"GC task thread#1 (ParallelGC)" os_prio=0 tid=0x00007f29e8061800
nid=0x14be85 runnable

"GC task thread#2 (ParallelGC)" os_prio=0 tid=0x00007f29e8063000
nid=0x14be86 runnable

"GC task thread#3 (ParallelGC)" os_prio=0 tid=0x00007f29e8065000
nid=0x14be87 runnable

"GC task thread#4 (ParallelGC)" os_prio=0 tid=0x00007f29e8066800
nid=0x14be88 runnable

"GC task thread#5 (ParallelGC)" os_prio=0 tid=0x00007f29e8068800
nid=0x14be89 runnable

"GC task thread#6 (ParallelGC)" os_prio=0 tid=0x00007f29e806a000
nid=0x14be8a runnable

"GC task thread#7 (ParallelGC)" os_prio=0 tid=0x00007f29e806c000
nid=0x14be8b runnable

"GC task thread#8 (ParallelGC)" os_prio=0 tid=0x00007f29e806d800
nid=0x14be8c runnable

"GC task thread#9 (ParallelGC)" os_prio=0 tid=0x00007f29e806f800
nid=0x14be8d runnable

"VM Periodic Task Thread" os_prio=0 tid=0x00007f29e8150000 nid=0x14be97
waiting on condition

JNI global references: 786

Heap
 PSYoungGen      total 593408K, used 241815K [0x00000000d5580000,
0x00000000ffc80000, 0x0000000100000000)
  eden space 495104K, 46% used
[0x00000000d5580000,0x00000000e35e5d10,0x00000000f3900000)
  from space 98304K, 12% used
[0x00000000f3900000,0x00000000f44c0140,0x00000000f9900000)
  to   space 95232K, 0% used
[0x00000000f9f80000,0x00000000f9f80000,0x00000000ffc80000)
 ParOldGen       total 324096K, used 153537K [0x0000000080000000,
0x0000000093c80000, 0x00000000d5580000)
  object space 324096K, 47% used
[0x0000000080000000,0x00000000895f05a0,0x0000000093c80000)
 Metaspace       used 23563K, capacity 23804K, committed 24240K, reserved
1071104K
  class space    used 2370K, capacity 2463K, committed 2480K, reserved
1048576K

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html