From: Ian R. <ian...@ma...> - 2007-12-17 01:06:30
|
Athul Acharya wrote: > Hi, > > I originally asked this a few weeks ago, but since then I've run into > some issues, and I'm hoping someone on this list can clarify things > for me :-) > > On Dec 1, 2007 11:59 AM, Ian Rogers <ian...@ma...> wrote: > >> Athul Acharya wrote: >> >>> This is along the lines of what I was looking for - to suspend a >>> thread from inside the VM temporarily, and I think I found it in the >>> form of VM_Thread.suspend() (right?). >>> > > >> Yep, you can use the java.lang.Thread interface to this of course :-) >> > > As far as I can tell, using the java.lang.Thread interface would call > VMThread.suspend() (right?), which immediately calls > VM_Thread.suspend() anyway. Also as far as I can tell, > VMThread.suspend() is the /only/ thing that calls VM_Thread.suspend(), > and nothing within the rvm calls VMThread.suspend() (right?). The > reason I ask is because I suspect VM_Thread.suspend() doesn't > actuallly work as advertised. > The suspend/resume mechanism is also used by on stack replacement (OSR) to suspend a thread and resume it when the method is recompiled. > Assuming the VM_Thread is a green thread, VM_Thread.suspend() calls > VM_GreenThread.suspendInternal() to change a flag to let the process > dispatch code know that it needs to be suspended. Additionally, if it > sees that it is the current thread on this processor, it goes ahead > and yield()s. I don't see anywhere that suspend() will signal the > thread if it's on a different processor, or wait to return until the > thread is actually suspended, i.e. no guarantee the thread is > suspended when the call to suspend() returns. This may or may not be > intended behavior, I'm not sure. > You're right iirc that suspended threads aren't placed on any queues, they should support interruption and other mechanisms. > Additionally, the function that checks the suspend flag is > VM_GreenThread.suspendIfPending(). This function clears the suspend > flag if it's set and returns true, and ostensibly any caller that sees > it return a true should dequeue that thread. Eclipse shows that the > only place that calls suspendIfPending() is > VM_GreenProcessor.dispatch(), and this function does _not_ dequeue > when suspendIfPending() returns true. So I'm not sure a thread that's > been suspend()ed ever actually gets suspended. Please let me know if > I'm missing something here :-) > Is the thread already dequeued as part of the dispatch? > All that being said, is there a function somewhere that /will/ > guarantee the thread in question is suspended when it returns? Where > do mutator threads get suspended for GC? > I'm not sure what you mean by your first question, you can't arbitrarily just suspend a thread as it needs to run to a yield point - this is why the actual suspension occurs in dispatch. Iirc the mutator threads run into a barrier in VM_HandShake for stop-the-world GC. Regards, Ian > Thanks, > > Athul Acharya > Purdue University |