This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA] JDWP ThreadStatus


This patch implements the JDWP side of the thread state/status command. It basically converts the JVMTI ThreadState info into one of the restrictive categories required by the JDWP spec. This should be pretty straightforward, but I had some questions about what to do in the case that a thread has been created but has not yet started. Clearly, it is not ZOMBIE, and the logic will eliminate WAIT, MONITOR, AND SLEEPING, so since the only possible status remaining is RUNNING (NEW doesn't exist), that's what I've set it to.

ChangeLog
2007-04-24  Kyle Galloway  <kgallowa@redhat.com>

* gnu/classpath/jdwp/natVMVirtualMachine.java (getThreadStatus): Implement.

Questions/comments/concerns?

- Kyle
Index: libjava/gnu/classpath/jdwp/natVMVirtualMachine.cc
===================================================================
--- libjava/gnu/classpath/jdwp/natVMVirtualMachine.cc	(revision 124075)
+++ libjava/gnu/classpath/jdwp/natVMVirtualMachine.cc	(working copy)
@@ -31,6 +31,7 @@
 #include <gnu/classpath/jdwp/Jdwp.h>
 #include <gnu/classpath/jdwp/JdwpConstants$StepDepth.h>
 #include <gnu/classpath/jdwp/JdwpConstants$StepSize.h>
+#include <gnu/classpath/jdwp/JdwpConstants$ThreadStatus.h>
 #include <gnu/classpath/jdwp/VMFrame.h>
 #include <gnu/classpath/jdwp/VMMethod.h>
 #include <gnu/classpath/jdwp/VMVirtualMachine.h>
@@ -622,9 +623,37 @@
 
 jint
 gnu::classpath::jdwp::VMVirtualMachine::
-getThreadStatus (MAYBE_UNUSED Thread *thread)
+getThreadStatus (Thread *thread)
 {
-  return 0;
+  jint thr_state, status;
+  
+  jvmtiError jerr = _jdwp_jvmtiEnv->GetThreadState (thread, &thr_state);
+  if (jerr != JVMTI_ERROR_NONE)
+    throw_jvmti_error (jerr);
+  
+  if (thr_state & JVMTI_THREAD_STATE_SLEEPING)
+    status = gnu::classpath::jdwp::JdwpConstants$ThreadStatus::SLEEPING;
+  else if (thr_state & JVMTI_THREAD_STATE_RUNNABLE)
+    status = gnu::classpath::jdwp::JdwpConstants$ThreadStatus::RUNNING;
+  else if (thr_state & JVMTI_THREAD_STATE_WAITING)
+    {
+      if (thr_state & (JVMTI_THREAD_STATE_IN_OBJECT_WAIT
+                       | JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER))
+        status = gnu::classpath::jdwp::JdwpConstants$ThreadStatus::MONITOR;
+      else
+        status = gnu::classpath::jdwp::JdwpConstants$ThreadStatus::WAIT;
+    }
+  else
+    {
+      // The thread is not SLEEPING, MONITOR, or WAIT.  It may, however, be
+      // alive but not yet started.
+      if (!(thr_state & (JVMTI_THREAD_STATE_ALIVE 
+                         | JVMTI_THREAD_STATE_TERMINATED)))
+        status = gnu::classpath::jdwp::JdwpConstants$ThreadStatus::RUNNING;
+      status = gnu::classpath::jdwp::JdwpConstants$ThreadStatus::ZOMBIE;     
+    }   
+
+  return status;
 }
 
 java::util::ArrayList *

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]