]> gcc.gnu.org Git - gcc.git/commitdiff
no-gc.h (_Jv_IsThreadSuspended): Declare.
authorKeith Seitz <kseitz@gcc.gnu.org>
Mon, 23 Apr 2007 21:12:10 +0000 (21:12 +0000)
committerKeith Seitz <kseitz@gcc.gnu.org>
Mon, 23 Apr 2007 21:12:10 +0000 (21:12 +0000)
        * include/no-gc.h (_Jv_IsThreadSuspended): Declare.
        * include/boehm-gc.h (_Jv_IsThreadSuspended): Likewise.
        * boehm.cc (_Jv_IsThreadSuspended): New function.
        * nogc.cc (_Jv_IsThreadSuspended): Likewise.
        * jvmti.cc (_Jv_JVMTI_GetThreadState): New function.
        (_Jv_JVMTI_Interface): Define GetThreadState.

From-SVN: r124082

libjava/boehm.cc
libjava/include/boehm-gc.h
libjava/include/no-gc.h
libjava/jvmti.cc
libjava/nogc.cc

index 66860dd50daaeab5ed71a43a21530f56836154a3..3aa0acba987199a847c20a59d1e1141d5576c421 100644 (file)
@@ -722,6 +722,17 @@ _Jv_ResumeThread (_Jv_Thread_t *thread)
 #endif
 }
 
+int
+_Jv_IsThreadSuspended (_Jv_Thread_t *thread)
+{
+#if defined(GC_PTHREADS) && !defined(GC_SOLARIS_THREADS) \
+     && !defined(GC_WIN32_THREADS) && !defined(GC_DARWIN_THREADS)
+  return GC_is_thread_suspended (_Jv_GetPlatformThreadID (thread));
+#else
+  return 0;
+#endif
+}
+
 void
 _Jv_GCAttachThread ()
 {
index 7e61b8e48fbbbfb8d95a6b3cc60379003ecd6117..ed8ac6aa2e34b6d298bc2496de279aa7b97829b7 100644 (file)
@@ -1,7 +1,7 @@
 // -*- c++ -*-
 // boehm-gc.h - Defines for Boehm collector.
 
-/* Copyright (C) 1998, 1999, 2002, 2004, 2006  Free Software Foundation
+/* Copyright (C) 1998, 1999, 2002, 2004, 2006, 2007  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -93,4 +93,6 @@ extern "C" void _Jv_SuspendThread (_Jv_Thread_t *);
 // Resume a suspended thread.
 extern "C" void _Jv_ResumeThread (_Jv_Thread_t *);
 
+// Is the given thread suspended?
+extern "C" int _Jv_IsThreadSuspended (_Jv_Thread_t *);
 #endif /* __JV_BOEHM_GC__ */
index 193b8ea4d05c9ddc0c5086d3dcc4d700392d06e3..ce0ffb81017582b870f8179568ce4a5500d5488a 100644 (file)
@@ -1,7 +1,7 @@
 // -*- c++ -*-
 // no-gc.h - Defines for no garbage collector.
 
-/* Copyright (C) 1998, 1999, 2006  Free Software Foundation
+/* Copyright (C) 1998, 1999, 2006, 2007  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -18,4 +18,6 @@ extern "C" void _Jv_SuspendThread (_Jv_Thread_t *);
 // Resume a suspended thread.
 extern "C" void _Jv_ResumeThread (_Jv_Thread_t *);
 
+// Is the given thread suspended?
+extern "C" int _Jv_IsThreadSuspended (_Jv_Thread_t *);
 #endif /* __JV_NO_GC__ */
index c13bb5aa3970b029bbb19edaaedd056431d10cf5..d9bcc806074fd7196bbcd5af6b384ac9691f1055 100644 (file)
@@ -30,6 +30,7 @@ details.  */
 #include <java/lang/OutOfMemoryError.h>
 #include <java/lang/Thread.h>
 #include <java/lang/ThreadGroup.h>
+#include <java/lang/Thread$State.h>
 #include <java/lang/Throwable.h>
 #include <java/lang/VMClassLoader.h>
 #include <java/lang/reflect/Field.h>
@@ -520,6 +521,66 @@ _Jv_JVMTI_GetFrameCount (MAYBE_UNUSED jvmtiEnv *env, jthread thread,
   return JVMTI_ERROR_NONE;
 }
 
+static jvmtiError JNICALL
+_Jv_JVMTI_GetThreadState (MAYBE_UNUSED jvmtiEnv *env, jthread thread,
+                         jint *thread_state_ptr)
+{
+  REQUIRE_PHASE (env, JVMTI_PHASE_LIVE);
+
+  THREAD_DEFAULT_TO_CURRENT (thread);
+  THREAD_CHECK_VALID (thread);
+  NULL_CHECK (thread_state_ptr);
+
+  jint state = 0;
+  if (thread->isAlive ())
+    {
+      state |= JVMTI_THREAD_STATE_ALIVE;
+
+      _Jv_Thread_t *data = _Jv_ThreadGetData (thread);
+      if (_Jv_IsThreadSuspended (data))
+       state |= JVMTI_THREAD_STATE_SUSPENDED;
+
+      if (thread->isInterrupted ())
+       state |= JVMTI_THREAD_STATE_INTERRUPTED;
+
+      _Jv_Frame *frame = reinterpret_cast<_Jv_Frame *> (thread->frame);
+      if (frame != NULL && frame->frame_type == frame_native)
+       state |= JVMTI_THREAD_STATE_IN_NATIVE;
+
+      using namespace java::lang;
+      Thread$State *ts = thread->getState ();
+      if (ts == Thread$State::RUNNABLE)
+       state |= JVMTI_THREAD_STATE_RUNNABLE;
+      else if (ts == Thread$State::BLOCKED)
+       state |= JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER;
+      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);
+
+         /* FIXME: We don't have a way to tell
+            the caller why the thread is suspended,
+            i.e., JVMTI_THREAD_STATE_SLEEPING,
+            JVMTI_THREAD_STATE_PARKED, and
+            JVMTI_THREAD_STATE_IN_OBJECT_WAIT
+            are never set. */
+       }
+    }
+  else
+    {
+      using namespace java::lang;
+      Thread$State *ts = thread->getState ();
+      if (ts == Thread$State::TERMINATED)
+       state |= JVMTI_THREAD_STATE_TERMINATED;
+    }
+
+  *thread_state_ptr = state;
+  return JVMTI_ERROR_NONE;
+}
+
 static jvmtiError JNICALL
 _Jv_JVMTI_CreateRawMonitor (MAYBE_UNUSED jvmtiEnv *env, const char *name,
                            jrawMonitorID *result)
@@ -2004,7 +2065,7 @@ struct _Jv_jvmtiEnv _Jv_JVMTI_Interface =
   UNIMPLEMENTED,               // GetThreadGroupInfo
   UNIMPLEMENTED,               // GetThreadGroupChildren
   _Jv_JVMTI_GetFrameCount,             // GetFrameCount
-  UNIMPLEMENTED,               // GetThreadState
+  _Jv_JVMTI_GetThreadState,    // GetThreadState
   RESERVED,                    // reserved18
   UNIMPLEMENTED,               // GetFrameLocation
   UNIMPLEMENTED,               // NotifyPopFrame
index 126e4de5c2b559b5178150ba39f3bf5aa07f928f..079422d0911d1e0a47c21e9c564e76910f5ddadb 100644 (file)
@@ -184,3 +184,9 @@ void
 _Jv_ResumeThread (_Jv_Thread_t *thread)
 {
 }
+
+int
+_Jv_IsThreadSuspended (_Jv_Thread_t *thread)
+{
+  return 0;
+}
This page took 0.067822 seconds and 5 git commands to generate.