2008/11/30 Gili <[EMAIL PROTECTED]>

>
> Hey Stuart,
>
> Just curious: how did you figure this out? What tools did you use and
> what operations did you invoke? I tried analyzing basic heap dumps and
> it only provided the "find nearest GC root" feature. I assume you used
> something else?
>

well, I typically try to use the IBM JDK, as I'm more familiar with it's
heapdump
and overall problem diagnostics (disclaimer: I helped write some of them ;)

but in this case I had trouble getting GlassFish v2 running on the latest
IBM JDK
so I switched to the Sun JDK - I had a very simple servlet that used Guice
to look
up an implementation, which I deployed and undeployed to test unloading.

then I just followed this procedure:

  1.  start GlassFish, access admin page
  2.  attach jconsole, force GC few times and take a heap dump via JMX
       (you could also use "jmap -dump:format=b,file=heap.dmp <pid>")
  3.  deploy test war-file, access page a few times
  4.  undeploy war-file, force GC several times with jconsole
  5.  see if Finalizer thread is still alive, take new heap dump with JMX
  6.  analyze dumps
  7.  tweak code + rebuild
  8.  rinse and repeat...

I used the jhat tool (which is much better these days) to analyze the dumps,
with
the first heap dump as a baseline: "jhat -J-Xmx1024m -baseline a.dmp b.dmp"

jhat has a web interface (typically localhost:7000) which I used to find my
servlet
class, I then browsed to its classloader and scrolled to the end of the page
to the
"Reference Chains from Rootset" section.

I clicked "Exclude weak refs" which produces potential leak candidates -
this can
be a huge page, but I know to ignore anything inside the same web-app, such
as
static fields, as they will only be alive while the classloader is alive.

The culprits are often at the bottom of the page where jhat lists system
class refs
and thread related refs. I also had an idea of what might be leaking because
it was
unloading in a normal app, and one main difference in JEE is the security
manager.

in the end it came down to scanning through the list looking for familiar
candidates,
so unfortunately no magic tool - just a bit of inspiration and a lot of luck
+ coffee ;)

Thanks,
> Gili
>
> On Nov 28, 11:00 am, "Stuart McCulloch" <[EMAIL PROTECTED]> wrote:
> > Hi folks,
> >
> > I spent a bit of time hunting through heapdumps and I found out why Guice
> > wasn't being cleanly unloaded:
> >
> >    http://code.google.com/p/google-collections/issues/detail?id=92#c6
> >
> > Unfortunately, I couldn't find a good way around some of these references
> > and had to resort to reflection
> > to clear some internal fields - so if anyone knows of better solutions,
> feel
> > free to comment on that issue!
> > (perhaps a public shutdown API for the google-collections Finalizer
> thread
> > would actually be better?)
> >
> > Anyway, I've uploaded a new _unofficial_ snapshot in case anyone wants to
> > test it themselves:
> >
> > http://peaberry.googlecode.com/svn/branches/spike/lib/build/google-gu...
> >
> > I also tagged the version stamp with peaberry to make clear this isn't a
> > regular snapshot, just in case...
> >
> > This jar will now allow Guice to be cleanly undeployed... as long as
> there
> > are no other leaks inside your
> > web application ;)  I tested it on GlassFish v2 and it works - although
> GC
> > can be slow to unload classes
> > if you're not using much of your heap - but you can always force GC via
> > jconsole, etc.
> >
> > PS. users of GlassFish v3 prelude may still see a leak because their
> > web-container thread pool appears
> > to have a bug where they don't clear the thread-context-classloader
> before
> > returning threads to the pool
> > which keeps the web-application around until that thread is re-used:
> >
> >    https://glassfish.dev.java.net/issues/show_bug.cgi?id=6082
> >
> > Have a good weekend!
> >
> > --
> > Cheers, Stuart
> >
>


-- 
Cheers, Stuart

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to