changeset 3696:dc7902820c9b

Make NMethodSweeper work on any JavaThread
author Gilles Duboscq <gilles.m.duboscq@gmail.com>
date Thu, 24 Nov 2011 17:24:43 +0100
parents 60d31b1fada5
children 872e949a0827
files src/share/vm/runtime/sweeper.cpp src/share/vm/runtime/thread.cpp src/share/vm/runtime/thread.hpp
diffstat 3 files changed, 18 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/runtime/sweeper.cpp	Thu Nov 24 14:09:18 2011 +0100
+++ b/src/share/vm/runtime/sweeper.cpp	Thu Nov 24 17:24:43 2011 +0100
@@ -310,10 +310,10 @@
 
 class NMethodMarker: public StackObj {
  private:
-  CompilerThread* _thread;
+  JavaThread* _thread;
  public:
   NMethodMarker(nmethod* nm) {
-    _thread = CompilerThread::current();
+    _thread = JavaThread::current();
     _thread->set_scanned_nmethod(nm);
   }
   ~NMethodMarker() {
--- a/src/share/vm/runtime/thread.cpp	Thu Nov 24 14:09:18 2011 +0100
+++ b/src/share/vm/runtime/thread.cpp	Thu Nov 24 17:24:43 2011 +0100
@@ -1292,6 +1292,7 @@
   _do_not_unlock_if_synchronized = false;
   _cached_monitor_info = NULL;
   _parker = Parker::Allocate(this) ;
+  _scanned_nmethod = NULL;
 
 #ifndef PRODUCT
   _jmp_ring_index = 0;
@@ -2558,6 +2559,13 @@
   if (jvmti_thread_state() != NULL) {
     jvmti_thread_state()->oops_do(f);
   }
+
+  if (_scanned_nmethod != NULL && cf != NULL) {
+      // Safepoints can occur when the sweeper is scanning an nmethod so
+      // process it here to make sure it isn't unloaded in the middle of
+      // a scan.
+      cf->do_code_blob(_scanned_nmethod);
+    }
 }
 
 void JavaThread::nmethods_do(CodeBlobClosure* cf) {
@@ -2948,23 +2956,12 @@
   _task  = NULL;
   _queue = queue;
   _counters = counters;
-  _scanned_nmethod = NULL;
 
 #ifndef PRODUCT
   _ideal_graph_printer = NULL;
 #endif
 }
 
-void CompilerThread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
-  JavaThread::oops_do(f, cf);
-  if (_scanned_nmethod != NULL && cf != NULL) {
-    // Safepoints can occur when the sweeper is scanning an nmethod so
-    // process it here to make sure it isn't unloaded in the middle of
-    // a scan.
-    cf->do_code_blob(_scanned_nmethod);
-  }
-}
-
 // ======= Threads ========
 
 // The Threads class links together all active threads, and provides
--- a/src/share/vm/runtime/thread.hpp	Thu Nov 24 14:09:18 2011 +0100
+++ b/src/share/vm/runtime/thread.hpp	Thu Nov 24 17:24:43 2011 +0100
@@ -845,6 +845,8 @@
 
   StackGuardState        _stack_guard_state;
 
+  nmethod*      _scanned_nmethod;  // nmethod being scanned by the sweeper
+
   // Compiler exception handling (NOTE: The _exception_oop is *NOT* the same as _pending_exception. It is
   // used to temp. parsing values into and out of the runtime system during exception handling for compiled
   // code)
@@ -940,6 +942,12 @@
 
   void cleanup_failed_attach_current_thread();
 
+  // Track the nmethod currently being scanned by the sweeper
+  void          set_scanned_nmethod(nmethod* nm) {
+    assert(_scanned_nmethod == NULL || nm == NULL, "should reset to NULL before writing a new value");
+    _scanned_nmethod = nm;
+  }
+
   // Testers
   virtual bool is_Java_thread() const            { return true;  }
 
@@ -1714,7 +1722,6 @@
   CompileTask*  _task;
   CompileQueue* _queue;
 
-  nmethod*      _scanned_nmethod;  // nmethod being scanned by the sweeper
 
  public:
 
@@ -1738,11 +1745,6 @@
     _log = log;
   }
 
-  // GC support
-  // Apply "f->do_oop" to all root oops in "this".
-  // Apply "cf->do_code_blob" (if !NULL) to all code blobs active in frames
-  void oops_do(OopClosure* f, CodeBlobClosure* cf);
-
 #ifndef PRODUCT
 private:
   IdealGraphPrinter *_ideal_graph_printer;
@@ -1754,12 +1756,6 @@
   // Get/set the thread's current task
   CompileTask*  task()                           { return _task; }
   void          set_task(CompileTask* task)      { _task = task; }
-
-  // Track the nmethod currently being scanned by the sweeper
-  void          set_scanned_nmethod(nmethod* nm) {
-    assert(_scanned_nmethod == NULL || nm == NULL, "should reset to NULL before writing a new value");
-    _scanned_nmethod = nm;
-  }
 };
 
 inline CompilerThread* CompilerThread::current() {