Attach Api and agent unloading

View: New views
2 Messages — Rating Filter:   Alert me  

Attach Api and agent unloading

by Ishaaq Chandy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,
Not sure if this is the right forum to ask this, if you know of a more appropriate one please direct me there.

I am using the awesome Attach API http://java.sun.com/javase/6/docs/jdk/api/attach/spec/index.html to attach an java-based agent to a running app. All working perfectly, great API!

Now, I want to know if there is a way to "unattach" the agent. i.e., does the agent run in a child classloader that can be unloaded on demand thus freeing up any resources the agent was using?

What I'm trying to get to is an attaching tool that can be run on demand to attach to a production app - do whatever it needs to do and then clean up after itself - i.e. stop any new threads it started, close all resources, unload any new classes it may have loaded up, free up memory it was using etc, so that the production app can continue running at normal operation mode, almost as if we never attached to it in the first place. Obviously, there can be caveats here - if the attached code is written in such a way that makes it impossible for the classloader to release the classes for GC then all bets are off.

Looking at the API, it looks like this is not possible, but I just thought I'd ask on the offchance I am missing something  here.

Thanks,
Ishaaq

Re: Attach Api and agent unloading

by alan.bateman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ishaaq Chandy wrote:
> Hi all,
> Not sure if this is the right forum to ask this, if you know of a more
> appropriate one please direct me there.
>  
This mailing lists is the general discussion list. The "Monitoring,
Management, Debugging, and Profiling APIs" forum [1] is a useful place
for questions on this (and related) APIs. If this is a JVM TI agent then
the agent library will not be unloaded until the VM exits (in a
multi-threaded environment it's usually not feasible to unload a shared
library mid-flight). If this is a j.l.instrument agent then the agent's
JAR is added to the system class path (details are in the j.l.instrument
package description).

-Alan.

[1] http://forums.sun.com/forum.jspa?forumID=539