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

[macosx] Program freeze when Swing is used with -XstartOnFirstThread

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 7u4
    • 7
    • client-libs
    • 2d
    • b11
    • generic
    • os_x
    • Verified

      Migrated from http://java.net/jira/browse/MACOSX_PORT-784:

      ------------------------------------------------------------
      There seems to be a deadlock when using Swing with -XstartOnFirstThread. Here's an example program:

      import javax.swing.UIManager;
      public class Java7Test {
      public static void main( String[] argv ) throws InterruptedException { System.out.println( "Before Swing" ); UIManager.getColor( "Panel.background" ); System.out.println( "After Swing" ); System.exit( 0 ); }
      }

      This works correctly:

      % java Java7Test
      Before Swing
      After Swing

      This never finishes:

      % java -XstartOnFirstThread Java7Test
      Before Swing
      ^C

      % java -version
      openjdk version "1.7.0-b222"
      OpenJDK Runtime Environment (build 1.7.0-b222-20111220)
      OpenJDK 64-Bit Server VM (build 21.0-b17, mixed mode)

      Switching to Apple's Java 1.6 works:
      % java -version
      java version "1.6.0_29"
      Java(TM) SE Runtime Environment (build 1.6.0_29-b11-402-11M3527)
      Java HotSpot(TM) 64-Bit Server VM (build 20.4-b02-402, mixed mode)

      % java -XstartOnFirstThread Java7Test
      Before Swing
      2011-12-29 07:24:35.096 java[1287:2007] [Java CocoaComponent compatibility mode]: Enabled
      2011-12-29 07:24:35.096 java[1287:2007] [Java CocoaComponent compatibility mode]: Setting timeout for SWT to 0.100000
      After Swing

      Debugging the above program (run with 1.7.0) in Eclipse shows the following stacktrace when it is frozen/deadlocked:

      Thread [main] (Suspended)
      Object.wait(long) line: not available [native method]
      OGLRenderQueue$QueueFlusher(Object).wait() line: 503
      OGLRenderQueue$QueueFlusher.flushNow() line: 167
      OGLRenderQueue$QueueFlusher.flushAndInvokeNow(Runnable) line: 180
      OGLRenderQueue.flushAndInvokeNow(Runnable) line: 125
      CGLGraphicsConfig.getConfig(CGraphicsDevice, int) line: 139
      CGraphicsDevice.<init>(int) line: 52
      CGraphicsEnvironment.initDevices() line: 146
      CGraphicsEnvironment.<init>() line: 103
      NativeConstructorAccessorImpl.newInstance0(Constructor, Object[]) line: not available [native method]
      NativeConstructorAccessorImpl.newInstance(Object[]) line: 57
      DelegatingConstructorAccessorImpl.newInstance(Object[]) line: 45
      Constructor<T>.newInstance(Object...) line: 525
      Class<T>.newInstance0() line: 372
      Class<T>.newInstance() line: 325
      GraphicsEnvironment.createGE() line: 109
      GraphicsEnvironment.getLocalGraphicsEnvironment() line: 81
      RepaintManager.<clinit>() line: 201
      UIManager.initialize() line: 1446 [local variables unavailable]
      UIManager.maybeInitialize() line: 1418
      UIManager.getDefaults() line: 653
      UIManager.getColor(Object) line: 695
      Java7Test.main(String[]) line: 6

      I need to use -XstartOnFirstThread because I'm using SWT. Swing only comes into play because I'm using JFreeChart with its SWT components as well. Drawing in JFreeChart SWT components is done with SWT GC, but there are some initializations and static components that use Swing.

      If I can help with testing or providing more information, please let me know.

            dcherepanov Dmitry Cherepanov
            dcherepanov Dmitry Cherepanov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: