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

Plasma program deadlocks AWT

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 1.2.1
    • client-libs
    • None
    • 2d
    • sparc
    • solaris_7

      awt.image.MemoryImageSource.removeConsumer(MemoryImageSource.java:231)
      [2] sun.awt.image.ImageRepresentation.abort(ImageRepresentation.java:783)
      [3] sun.awt.image.Image.flush(Image.java:275)
      [4] Plasma.update(Plasma.java:53)
      [5] Plasma.run(Plasma.java:89)
      [6] Plasma.main(Plasma.java:129)
      -------------------
      Choose an index (1 to 11) to dump thread stack.
      12 or greater dumps all stacks;
      0 returns you to the previous menu: 1

      "AWT-Finalizer" (TID:0x5240f4, sys_thread_t:0x524040, state:CW, thread_t: t@13, threadID:0xfaa21dc8, stack_bottom:0xfaa22000, stack_size:0x20000) prio=9

      [1] java.lang.Object.wait(Object.java:424)
      [2] sun.awt.AWTFinalizer.run(AWTFinalizer.java:43)
      -------------------
      Choose an index (1 to 11) to dump thread stack.
      12 or greater dumps all stacks;
      0 returns you to the previous menu: 0



      ---------
      Do you want to:
        [ 0 ] continue program
        [ 1 ] check & print one deadlock
        [ 2 ] check & print all deadlocks
        [ 3 ] dump thread stacks
        [ 4 ] dump lock registry
        [ 5 ] heap inspection
        [ 6 ] hprof dump
        [ 7 ] terminate program
      Select action: 7
      Terminating Program
      Sam's Plasma program deadlocks the AWT using the following platforms...

         OS JDK
        ---- -------
        Windows98 (Gateway 450) 1.2-V
        Solaris 2.6 (Ultra1 Creator) 1.1.8D (when exposure tested)
        Solaris 2.7 (Ultra5_10) 1.1.8D, 1.2-V, 1.2.1-L, Solaris JDK 1.2_01
        Solaris 2.7 (Gateway 450) 1.1.8D, 1.2-V, 1.2.1-L, Solaris JDK 1.2_01


      Here is the program source. Compile and run the program as an application.
      It will deadlock on its own. I've also reproduced this by covering the GUI
      with another window and then removing it (may take 2-3 tries). Sometimes
      the deadlock is immediate, other times it may take a minute or two. All
      systems used are uniprocessor.


      Plasma.java

      import java.awt.*;
      import java.awt.image.*;

      public class Plasma extends java.applet.Applet implements Runnable {
        Image img;
        Thread runThread;
        long firstFrame, frames, fps;
        int width, height;
        int w,h,size;
        int scale=3;
        boolean showFPS = true;
        IndexColorModel icm;
        int[] waveTable;
        byte[][] paletteTable;
        byte[] pixels;

        public void init() {
           width = size().width;
           height = size().height;
           //String p = getParameter("scale");
           //if (p != null)
              scale = Integer.parseInt("2");
           //p = getParameter("showfps");
           //if (p != null)
               showFPS = true;
           w = width/scale;
           h = w;
           size = (int) ((w+h)/2)*4;
           pixels = new byte[w*h];
           waveTable = new int[size];
           paletteTable = new byte[3][256];
           calculatePaletteTable();
           img=createImage(new MemoryImageSource(w,h,icm,pixels,0,w));
        }

        public void start() {
           if (runThread == null) {
             runThread=new Thread(this);
             runThread.start();
             firstFrame=System.currentTimeMillis();
             frames = 0;
           };
        }

        public void stop() {
          if (runThread != null) {
             runThread.stop();
             runThread=null;
          }
        }

        public void update(Graphics g) {
           img.flush();
           g.drawImage(img, 0, 0, width, height, null);
           if (showFPS) {
              frames++;
              fps = (frames*10000) / (System.currentTimeMillis()-firstFrame);
              g.drawString(fps/10 + "." + fps%10 + " fps", 2, height - 2);
           }
        }

        void calculateWaveTable() {
          for(int i=0;i<size;i++)
             waveTable[i]=(int)(32*(1+Math.sin(((double)i*2*Math.PI)/size)));
        }

        int FadeBetween(int start,int end,int proportion) {
          return ((end-start)*proportion)/128+start;
        }

        void calculatePaletteTable() {
           for(int i=0;i<128;i++) {
              paletteTable[0][i]=(byte)FadeBetween(0,255,i);
              paletteTable[1][i]=(byte)0;
              paletteTable[2][i]=(byte)FadeBetween(255,0,i);
           }
           for(int i=0;i<128;i++) {
              paletteTable[0][i+128]=(byte)FadeBetween(255,0,i);
              paletteTable[1][i+128]=(byte)0;
              paletteTable[2][i+128]=(byte)FadeBetween(0,255,i);
           }
           icm = new IndexColorModel(8, 256, paletteTable[0], paletteTable[1], paletteTable[2]);
        }

        public void run() {
          int x,y;
          int index;
          int tempval,result;
          int spd1=2,spd2=5,spd3=1,spd4=4;
          int pos1=0,pos2=0,pos3=0,pos4=0;
          int tpos1,tpos2,tpos3,tpos4;
          int inc1=6,inc2=3,inc3=3,inc4=9;

          runThread.setPriority(Thread.MIN_PRIORITY);
          calculateWaveTable();
          while(true) {
            index=0;
            tpos1=pos1; tpos2=pos2;
            for(y=0;y<h;y++) {
              tpos3=pos3; tpos4=pos4;
              tpos1%=size; tpos2%=size;
              tempval=waveTable[tpos1] + waveTable[tpos2];
              for(x=0;x<w;x++) {
                tpos3%=size; tpos4%=size;
                result=tempval + waveTable[tpos3] + waveTable[tpos4];
                pixels[index++]=(byte)result;
                tpos3+=inc3; tpos4+=inc4;
              }
              tpos1+=inc1; tpos2+=inc2;
            }
            pos1+=spd1; pos2+=spd2; pos3+=spd3; pos4+=spd4;
            update(getGraphics());
            Thread.yield();
            //try {Thread.sleep(10);}
            //catch (InterruptedException e) { }
          }
        }

        public static void main (String [] argv) {

          Frame frame = new Frame();
          frame.setSize(new Dimension(320,240));
          frame.setLayout(new BorderLayout());
          Plasma plasma = new Plasma();
          frame.add(plasma,"Center");
          frame.setVisible(true);
          plasma.init();
          plasma.start();
          plasma.run();

        }

      }


      Here is a stacktrace from JDK1.2.1-L on Solaris 2.7...

      oxe 30 => jdk latest
      java full version "JDK-1.2.1-L"
      oxe 31 => java Plasma
      Font specified in font.properties not found [-monotype-arial-regular-r-normal--*-%d-*-*-p-*-iso8859-1]
      Font specified in font.properties not found [-monotype-courier new-bold-i---*-%d-*-*-m-*-iso8859-1]
      Font specified in font.properties not found [-monotype-times new roman-bold-r---*-%d-*-*-p-*-iso8859-1]
      Font specified in font.properties not found [-monotype-times new roman-regular-r---*-%d-*-*-p-*-iso8859-1]
      Font specified in font.properties not found [-monotype-courier new-regular-i---*-%d-*-*-m-*-iso8859-1]
      Font specified in font.properties not found [-monotype-courier new-regular-i---*-%d-*-*-m-*-iso8859-1]
      Font specified in font.properties not found [-monotype-arial-bold-i-normal--*-%d-*-*-p-*-iso8859-1]
      Font specified in font.properties not found [-monotype-courier new-regular-r---*-%d-*-*-m-*-iso8859-1]
      Font specified in font.properties not found [-monotype-arial-regular-i-normal--*-%d-*-*-p-*-iso8859-1]
      Font specified in font.properties not found [-monotype-arial-bold-r-normal--*-%d-*-*-p-*-iso8859-1]
      Font specified in font.properties not found [-monotype-courier new-bold-i---*-%d-*-*-m-*-iso8859-1]
      Font specified in font.properties not found [-monotype-arial-bold-i-normal--*-%d-*-*-p-*-iso8859-1]
      Font specified in font.properties not found [-monotype-times new roman-regular-i---*-%d-*-*-p-*-iso8859-1]
      Font specified in font.properties not found [-monotype-arial-regular-i-normal--*-%d-*-*-p-*-iso8859-1]
      Font specified in font.properties not found [-monotype-times new roman-bold-i---*-%d-*-*-p-*-iso8859-1]
      Font specified in font.properties not found [-monotype-courier new-bold-r---*-%d-*-*-m-*-iso8859-1]
      Font specified in font.properties not found [-monotype-courier new-bold-r---*-%d-*-*-m-*-iso8859-1]
      Font specified in font.properties not found [-monotype-courier new-regular-r---*-%d-*-*-m-*-iso8859-1]
      Font specified in font.properties not found [-monotype-arial-regular-r-normal--*-%d-*-*-p-*-iso8859-1]
      Font specified in font.properties not found [-monotype-arial-bold-r-normal--*-%d-*-*-p-*-iso8859-1]
      SIGQUIT

      Full thread dump Classic VM (JDK-1.2.1-L, green threads):
          "Screen Updater" (TID:0xfb8b6ac0, sys_thread_t:0x53c730, state:CW) prio=4
              at java.lang.Object.wait(Native Method)
              at java.lang.Object.wait(Object.java, Compiled Code)
              at sun.awt.ScreenUpdater.nextEntry(ScreenUpdater.java, Compiled Code)
              at sun.awt.ScreenUpdater.run(ScreenUpdater.java, Compiled Code)
          "Thread-0" (TID:0xfb8ab260, sys_thread_t:0x4467c0, state:MW) prio=1
              at sun.awt.image.ImageRepresentation.setPixels(ImageRepresentation.java, Compiled Code)
              at java.awt.image.MemoryImageSource.sendPixels(MemoryImageSource.java, Compiled Code)
              at java.awt.image.MemoryImageSource.addConsumer(MemoryImageSource.java, Compiled Code)
              at java.awt.image.MemoryImageSource.startProduction(MemoryImageSource.java, Compiled Code)
              at sun.awt.image.ImageRepresentation.startProduction(ImageRepresentation.java, Compiled Code)
              at sun.awt.image.ImageRepresentation.drawToBufImage(ImageRepresentation.java, Compiled Code)
              at sun.awt.motif.X11Graphics.drawImage(X11Graphics.java, Compiled Code)
              at Plasma.update(Plasma.java, Compiled Code)
              at Plasma.run(Plasma.java, Compiled Code)
              at java.lang.Thread.run(Thread.java, Compiled Code)
          "AWT-Motif" (TID:0xfb8b6858, sys_thread_t:0x3e4ca0, state:CW) prio=5
              at sun.awt.motif.MToolkit.run(Native Method)
              at java.lang.Thread.run(Thread.java, Compiled Code)
          "SunToolkit.PostEventQueue-0" (TID:0xfb8b6d00, sys_thread_t:0x3be3d8, state:CW) prio=5
              at java.lang.Object.wait(Native Method)
              at java.lang.Object.wait(Object.java, Compiled Code)
              at sun.awt.PostEventQueue.run(SunToolkit.java, Compiled Code)
          "AWT-EventQueue-0" (TID:0xfb8b6cd0, sys_thread_t:0x3be2a0, state:CW) prio=6
              at java.lang.Object.wait(Native Method)
              at java.lang.Object.wait(Object.java, Compiled Code)
              at java.awt.EventQueue.getNextEvent(EventQueue.java, Compiled Code)
              at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java, Compiled Code)
              at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java, Compiled Code)
              at java.awt.EventDispatchThread.run(EventDispatchThread.java, Compiled Code)
          "Finalizer" (TID:0xfb898320, sys_thread_t:0x69808, state:CW) prio=8
              at java.lang.Object.wait(Native Method)
              at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java, Compiled Code)
              at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java, Compiled Code)
              at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:174)
          "Reference Handler" (TID:0xfb8983b0, sys_thread_t:0x653f0, state:CW) prio=10
              at java.lang.Object.wait(Native Method)
              at java.lang.Object.wait(Object.java, Compiled Code)
              at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:114)
          "Signal dispatcher" (TID:0xfb8983e0, sys_thread_t:0x5e508, state:R) prio=5
          "main" (TID:0xfb8981e0, sys_thread_t:0x268c8, state:MW) prio=5
              at java.awt.image.MemoryImageSource.removeConsumer(MemoryImageSource.java, Compiled Code)
              at sun.awt.image.ImageRepresentation.abort(ImageRepresentation.java, Compiled Code)
              at sun.awt.image.Image.flush(Image.java, Compiled Code)
              at Plasma.update(Plasma.java, Compiled Code)
              at Plasma.run(Plasma.java, Compiled Code)
              at Plasma.main(Plasma.java, Compiled Code)
      Monitor Cache Dump:
          sun.awt.ScreenUpdater@FB8B6AC0/FB9B5A30: <unowned>
              Waiting to be notified:
                  "Screen Updater" (0x53c730)
          java.awt.EventQueue@FB8B6C38/FB9B4F90: <unowned>
              Waiting to be notified:
                  "AWT-EventQueue-0" (0x3be2a0)
          sun.awt.image.ImageRepresentation@FB89EF08/FBA0E7D8: owner "main" (0x268c8) 1 entry
              Waiting to enter:
                  "Thread-0" (0x4467c0)
          java.lang.ref.ReferenceQueue$Lock@FB898338/FB8CDD68: <unowned>
              Waiting to be notified:
                  "Finalizer" (0x69808)
          sun.awt.PostEventQueue@FB8B6D00/FB9B5398: <unowned>
              Waiting to be notified:
                  "SunToolkit.PostEventQueue-0" (0x3be3d8)
          java.lang.ref.Reference$Lock@FB8983C0/FB8CD8A8: <unowned>
              Waiting to be notified:
                  "Reference Handler" (0x653f0)
          java.awt.image.MemoryImageSource@FB8AB890/FB9E9478: owner "Thread-0" (0x4467c0) 1 entry
              Waiting to enter:
                  "main" (0x268c8)
      Registered Monitor Dump:
          PCMap lock: <unowned>
          utf8 hash table: <unowned>
          JNI pinning lock: <unowned>
          JNI global reference lock: <unowned>
          BinClass lock: <unowned>
          Class linking lock: <unowned>
          System class loader lock: <unowned>
          Code rewrite lock: <unowned>
          Heap lock: <unowned>
          Monitor cache lock: owner "Signal dispatcher" (0x5e508) 1 entry
          Dynamic loading lock: <unowned>
          Monitor IO lock: <unowned>
          User signal monitor: <unowned>
          Child death monitor: <unowned>
          I/O monitor: <unowned>
              Waiting to be notified:
                  "AWT-Motif" (0x3e4ca0)
          Alarm monitor: <unowned>
              Waiting to be notified:
                  <unknown thread> (0x2bbb8)
          Thread queue lock: owner "Signal dispatcher" (0x5e508) 1 entry
          Monitor registry: owner "Signal dispatcher" (0x5e508) 1 entry





      Here is a stack trace using Solaris JDK 1.2_01...

      java_g Plasma
      [Warning: Native method sun/awt/font/NativeFontWrapper.getGlyphJustificationInfo not found at class load time]
      [Warning: Native method sun/awt/motif/MFramePeer.addTextComponent not found at class load time]
      [Warning: Native method sun/awt/EmbeddedFrame.setPeer not found at class load time]
      [Warning: Native method sun/java2d/loops/ImageData.allocNativeICMData not found at class load time]
      SIGQUIT
      A SIGQUIT has been received. Do you want to:
        [ 0 ] continue program
        [ 1 ] check & print one deadlock
        [ 2 ] check & print all deadlocks
        [ 3 ] dump thread stacks
        [ 4 ] dump lock registry
        [ 5 ] heap inspection
        [ 6 ] hprof dump
        [ 7 ] terminate program
      Select action: 2

      FOUND A JAVA LEVEL DEADLOCK:
      ---------------------------
      t@11 waiting to lock object@0xfc070c20:"sun/awt/image/ImageRepresentation"
               which is locked by t@1
      t@1 waiting to lock object@0x373b8:"java/awt/image/MemoryImageSource"
               which is locked by t@11

      JAVA STACK INFORMATION FOR THREADS LISTED ABOVE:
      -----------------------------------------------

      Java Stack for t@11 (EE = 0x411c40) "Thread-1" :
      ==========
      [1] sun.awt.image.ImageRepresentation.setPixels(ImageRepresentation.java:317)
      [2] java.awt.image.MemoryImageSource.sendPixels(MemoryImageSource.java:471)
      [3] java.awt.image.MemoryImageSource.addConsumer(MemoryImageSource.java:198)
      [4] java.awt.image.MemoryImageSource.startProduction(MemoryImageSource.java:241)
      [5] sun.awt.image.ImageRepresentation.startProduction(ImageRepresentation.java:594)
      [6] sun.awt.image.ImageRepresentation.drawToBufImage(ImageRepresentation.java:702)
      [7] sun.awt.motif.X11Graphics.drawImage(X11Graphics.java:429)
      [8] Plasma.update(Plasma.java:53)
      [9] Plasma.run(Plasma.java:89)
      [10] java.lang.Thread.run(Thread.java:485)

      Java Stack for t@1 (EE = 0x399b0) "main" :
      ==========
      [1] java.awt.image.MemoryImageSource.removeConsumer(MemoryImageSource.java:231)
      [2] sun.awt.image.ImageRepresentation.abort(ImageRepresentation.java:783)
      [3] sun.awt.image.Image.flush(Image.java:275)
      [4] Plasma.update(Plasma.java:53)
      [5] Plasma.run(Plasma.java:89)
      [6] Plasma.main(Plasma.java:129)
      -----------------------------------------------
      Found 1 deadlock

      ---------
      Do you want to:
        [ 0 ] continue program
        [ 1 ] check & print one deadlock
        [ 2 ] check & print all deadlocks
        [ 3 ] dump thread stacks
        [ 4 ] dump lock registry
        [ 5 ] heap inspection
        [ 6 ] hprof dump
        [ 7 ] terminate program
      Select action: 3

      List of Java Threads:
      --------------------

      [Thread# 1] t@13: "AWT-Finalizer"
      [Thread# 2] t@12: <GC-like thread>
      [Thread# 3] t@11: "Thread-1"
      [Thread# 4] t@10: "Screen Updater"
      [Thread# 5] t@9: "AWT-Motif"
      [Thread# 6] t@8: "SunToolkit.PostEventQueue-0"
      [Thread# 7] t@7: "AWT-EventQueue-0"
      [Thread# 8] t@6: "Finalizer"
      [Thread# 9] t@5: "Reference Handler"
      [Thread# 10] t@4: "Signal dispatcher"
      [Thread# 11] t@1: "main"

      Choose an index (1 to 11) to dump thread stack.
      12 or greater dumps all stacks;
      0 returns you to the previous menu: 11

      "main" (TID:0x39a64, sys_thread_t:0x399b0, state:MW, thread_t: t@1, threadID:0x24b18, stack_bottom:0xffbf0000, stack_size:0x20000) prio=5

      [1] java.

            Unassigned Unassigned
            jmelvin James Melvin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: