Suspend all thread when a requested event occurs (like SUSPEND_ALL in jdi)
Hi!
I'd like to write a jvmti agent that can make a threadtree(it can find the parent of the current thread).
// I make the B thread in the A thread. A will be the parent of the B.
I made it in JDI. I catch the methodStartEvent of start0 method (It's called to start the new thread - This is the parent). I get the threadid of this event. Then I catch the threadStartEvent. Here I get the child's threadid.
And I set these two events' suspendPolicies to SUSPEND_ALL. It results sequential execution: start0 is the father and the next threadStart is the child.
But in JVMTI I can't do that :( I can't find suspendPolicy!
Perhaps at the begining of the event I can get the list of threads and suspend all them and the end of the event I start them again, But I'm not sure while I'm receiving the threadlist and suspending the threads there isn't any of threads that makes an event :( .
[935 byte] By [
pet_a] at [2007-11-26 14:57:54]

# 2
Hello,
Thanks for your answer!
I tried it and I have a problem with jvmti. I get AllThreadList, then suspend all threads of the list. And at the same time I suspend the thread that is running the event code (so my application is waiting for the resume signe forever :(
I tried to delete from the list the current thread, but I couldn't compare the thread (I tried to use the memory address, but it was impossible for me)
How can I compare the threads?
I don't understand the working of the jvmti threads and the events. I need some confirmation :). If I have two thread: A and B. And if A generate a methodentry event, then A execute the jvmti native function that I implement in the c file. And during this B generate a startthread event (in the java file I make a new thread thats run method starts a new another thread(this is C) )
So the B thread execute the callbackStartThread jvmti native function. And if I write to the output in both native functions I will get mixed output.
I have an another question:
How can I use JDWP SuspendPolicy Constants? Can I implement it into the jvmti client?
Could you give me a link about an example?
pet_a at 2007-7-8 8:46:41 >

# 3
> Hello,
>
> Thanks for your answer!
> I tried it and I have a problem with jvmti. I get
> AllThreadList, then suspend all threads of the list.
> And at the same time I suspend the thread that is
> running the event code (so my application is waiting
> for the resume signe forever :(
Create debug thread and control the suspend and resume using this agent thread. Take a look at RunAgentThread() api.
>
> I tried to delete from the list the current thread,
> but I couldn't compare the thread (I tried to use the
> memory address, but it was impossible for me)
> How can I compare the threads?
You can compare using jni IsSameObject function.
>
> I don't understand the working of the jvmti threads
> and the events. I need some confirmation :). If I
> have two thread: A and B. And if A generate a
> methodentry event, then A execute the jvmti native
> function that I implement in the c file. And during
> this B generate a startthread event (in the java file
> I make a new thread thats run method starts a new
> another thread(this is C) )
> So the B thread execute the callbackStartThread jvmti
> native function. And if I write to the output in both
> native functions I will get mixed output.
I guess you are asking about thread synchronization.
OS has control which thread to run not the jvmti or
java. Which thread runs depends on the thread
scheduling. If you need to control the mix of output
use locks or jvmti raw monitors.
>
> I have an another question:
> How can I use JDWP SuspendPolicy Constants? Can I
> implement it into the jvmti client?
> Could you give me a link about an example?
I think Sun will open source the jdk soon and you
can see how JDWP is used to implement the
the jdi. If I come across any link I will let you know.