[RFC] Implementing JVMTI's GetThreadState

Keith Seitz keiths@redhat.com
Wed Apr 11 18:37:00 GMT 2007


Hi,

I need to implement this function for JDWP. Sadly, this function is so 
bloated with information, that it appears pretty difficult to fully 
implement (at least in any "acceptable" way IMO).

For instance, it is not enough to simply know that a thread is alive as 
runnable, blocked (on monitor enter), or waiting. One must know _why_ a 
thread is waiting (sleeping, LockSupport.park, or Object.wait).

JDWP doesn't really need to know anything this specific, but since this 
is the JVMTI call, I thought I would try to implement the whole thing. 
[Hey, I'd be as happy as anyone to simply leave this specific 
information out of it until some later time when it proves useful. O:-)]

Right now, I have been playing with an implementation which does 
everything except figure out WHY a thread is waiting. My question of 
course: Does anyone see anything more elegant than adding a bunch of 
booleans in LockSupport.park, Object.wait, and Thread.sleep in order to 
divine said information?

Example of what I've been playing with:

       else if (ts == Thread$State::TIMED_WAITING
	       || ts == Thread$State::WAITING)
	{
	  state |= JVMTI_THREAD_STATE_WAITING;
	  state |= ((ts == Thread$State::WAITING)
		    ? JVMTI_THREAD_STATE_WAITING_INDEFINITELY
		    : JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT);

	  if (thread->asleep)
	    state |= JVMTI_THREAD_STATE_SLEEPING;
	  else if (_Jv_ThreadIsParked (thread))
	    state |= JVMTI_THREAD_STATE_PARKED;
	  else if (false /*in Object.wait HOW TO DO THIS?*/)
	    state |= JVMTI_THREAD_STATE_IN_OBJECT_WAIT;
        }

I would really appreciate some help on this...

Keith



More information about the Java-patches mailing list