Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 19 May 2000 02:01:47 -0400 (EDT)
From:      Sean Reilly <sreilly@seanreilly.com>
To:        Nate Williams <nate@yogotech.com>
Cc:        freebsd-java@FreeBSD.ORG
Subject:   Re: problem in 1.1.8
Message-ID:  <Pine.BSF.4.10.10005190128310.61564-100000@seanreilly.com>
In-Reply-To: <200005190425.WAA28735@nomad.yogotech.com>

next in thread | previous in thread | raw e-mail | index | archive | help

> "finalize" should *NEVER* be called from external threads, and is the
> domain of the GC thread.   Are you calling finalize by hand?

Nope, I'm not calling gc or finalize anywhere in the program.

> See above.  How are you loading the image?  Can you give a bit more
> details as to what exactly the program is doing.

No problem.  I'd send you the complete source code but it's probably too
big to be a useful example.  The program first loads a GIF file to be
displayed in a splash window.  I use something like:
  Image img = toolkit.getImage(someClass.getResource(...));
to load the image.  Then I create a MediaTracker, add the image to it,
then do a waitForID(..) to try to fully load the image:

      MediaTracker tracker = new MediaTracker(this);
      tracker.addImage(img,0);
      tracker.waitForID(0);

The next step is to set the window with the ImagePanel (my own simple
image component) to be visible, and then go to work loading the data file
for the program.  That's where the problem occurs... while the data file
is loading in the main thread (see the readUTF call) the image never
actually gets rendered to the screen.  I'm definitely not calling the
X11Graphics.finalize method (in the trace below it seems to be coming from
the String.<init> class which can't be right).

Is the stack getting screwed up?

> > Full thread dump:
> >         sun.awt.AWTFinalizer.run(AWTFinalizer.java:40)
> >     "Image Animator 0" (TID:0x2869aab0, sys_thread_t:0x29507f00, state:MW)
> > prio=3
> >         sun.awt.image.ImageDecoder.close(ImageDecoder.java:163)
> 
> Image Animator 0 is callig close and is waiting on the monitor.
> 
> >     "main" (TID:0x2866f0b0, sys_thread_t:0x8124a00, state:MW) prio=5
> >         sun.awt.motif.X11Graphics.finalize(X11Graphics.java:109)
> >         java.lang.String.<init>(String.java)
> >         java.io.DataInputStream.readUTF(DataInputStream.java)
> >         java.io.DataInputStream.readUTF(DataInputStream.java)
> 
> And the main thread is calling finalize, which is weird.
> 
> >     sun.awt.image.GifImageDecoder@2869AE78/286FB0E8: owner "Image Animator
> > 0" (0x29507f00, 1 entry)
> >     sun.awt.motif.MToolkit@286900B0/286DDD28: <unowned>
> >         Waiting to be notified:
> >             "AWT-Motif" (0x294e4f00)
> >     java.lang.Class@28699CD0/286F5140: owner "AWT-EventQueue-0"
> > (0x294a2f00, 1 entry)
> >     java.lang.Class@2869AE80/286FB070: owner "Image Animator 0"
> > (0x29507f00, 1 entry)
> >     java.lang.Class@28699EB8/286F58C8: owner "main" (0x8124a00, 1 entry)
> >     sun.awt.AWTFinalizer@2869AFC8/286DE6B0: <unowned>
> >         Waiting to be notified:
> >             "AWT-Finalizer" (0x29528f00)
> >     <unknown key> (0x29452f00): <unowned>
> >         Waiting to be notified:
> >             "Async Garbage Collector" (0x29452f00)
> 
> Interesting.  Why is readObject() calling the GC?  You're not making any
> explicity calls to the garbage collector, are you?

None at all.  readObject calling gc?  I don't have any readObject methods
in my code nor any type of object (de)serialization.

> > Registered Monitor Dump:
> >     Thread queue lock: <unowned>
> >     Name and type hash table lock: <unowned>
> >     String intern lock: <unowned>
> >     JNI pinning lock: <unowned>
> >     JNI global reference lock: <unowned>
> >     BinClass lock: <unowned>
> >     Class loading lock: owner "AWT-EventQueue-0" (0x294a2f00, 1 entry)
> >         Waiting to enter:
> >             "main" (0x8124a00)
> >             "Image Animator 0" (0x29507f00)
> 
> Ahh, this is a clue.  It turns out that there are races in the Java
> imaging code (which is a complete mess), and you may have stumbled on
> them.  Sometimes moving the code around and/or adding sleeps in places
> causes the races to go away.  *ESPECIALLY* when dealing with object
> serialization.
> 
> You aren't using any static class locks by chance are you?

Nope.  Maybe some of the underlying java.* classes do?  I already have a
one second sleep after the setVisible on the splash window before the app
starts to do its thing... taking that out doesn't seem to help.

It seems like the deadlock is between something in the
X11Graphics.finalize() method in the main thread and the
LightweightDispatcher.dispatchEvent() method in the AWT-EventQueue-0
thread.  The thing I don't understand is how the finalize method of
X11Graphics is getting called in the main thread when the nothing in
the stack trace up to that point ever calls it!

Thanks,
Sean





To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-java" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.10.10005190128310.61564-100000>