< prev index next >

src/share/vm/gc/cms/concurrentMarkSweepThread.hpp

Print this page




  24 
  25 #ifndef SHARE_VM_GC_CMS_CONCURRENTMARKSWEEPTHREAD_HPP
  26 #define SHARE_VM_GC_CMS_CONCURRENTMARKSWEEPTHREAD_HPP
  27 
  28 #include "gc/cms/concurrentMarkSweepGeneration.hpp"
  29 #include "gc/shared/concurrentGCThread.hpp"
  30 #include "runtime/thread.hpp"
  31 
  32 class ConcurrentMarkSweepGeneration;
  33 class CMSCollector;
  34 
  35 // The Concurrent Mark Sweep GC Thread
  36 class ConcurrentMarkSweepThread: public ConcurrentGCThread {
  37   friend class VMStructs;
  38   friend class ConcurrentMarkSweepGeneration;   // XXX should remove friendship
  39   friend class CMSCollector;
  40 
  41  private:
  42   static ConcurrentMarkSweepThread*     _cmst;
  43   static CMSCollector*                  _collector;
  44   static SurrogateLockerThread*         _slt;
  45   static SurrogateLockerThread::SLT_msg_type _sltBuffer;
  46   static Monitor*                       _sltMonitor;
  47 
  48   enum CMS_flag_type {
  49     CMS_nil             = NoBits,
  50     CMS_cms_wants_token = nth_bit(0),
  51     CMS_cms_has_token   = nth_bit(1),
  52     CMS_vm_wants_token  = nth_bit(2),
  53     CMS_vm_has_token    = nth_bit(3)
  54   };
  55 
  56   static int _CMS_flag;
  57 
  58   static bool CMS_flag_is_set(int b)        { return (_CMS_flag & b) != 0;   }
  59   static bool set_CMS_flag(int b)           { return (_CMS_flag |= b) != 0;  }
  60   static bool clear_CMS_flag(int b)         { return (_CMS_flag &= ~b) != 0; }
  61   void sleepBeforeNextCycle();
  62 
  63   // CMS thread should yield for a young gen collection and direct allocations
  64   static char _pad_1[64 - sizeof(jint)];    // prevent cache-line sharing
  65   static volatile jint _pending_yields;
  66   static char _pad_2[64 - sizeof(jint)];    // prevent cache-line sharing
  67 
  68   // debugging
  69   void verify_ok_to_terminate() const PRODUCT_RETURN;
  70 
  71   void run_service();
  72   void stop_service();
  73 
  74  public:
  75   // Constructor
  76   ConcurrentMarkSweepThread(CMSCollector* collector);
  77 
  78   static void makeSurrogateLockerThread(TRAPS);
  79   static SurrogateLockerThread* slt() { return _slt; }
  80 
  81   static void threads_do(ThreadClosure* tc);
  82 
  83   // Printing
  84   static void print_all_on(outputStream* st);
  85   static void print_all()                             { print_all_on(tty); }
  86 
  87   // Returns the CMS Thread
  88   static ConcurrentMarkSweepThread* cmst()    { return _cmst; }
  89   static CMSCollector*         collector()    { return _collector;  }
  90 
  91   // Create and start the CMS Thread, or stop it on shutdown
  92   static ConcurrentMarkSweepThread* start(CMSCollector* collector);
  93 
  94   // Synchronization using CMS token
  95   static void synchronize(bool is_cms_thread);
  96   static void desynchronize(bool is_cms_thread);
  97   static bool vm_thread_has_cms_token() {
  98     return CMS_flag_is_set(CMS_vm_has_token);
  99   }




  24 
  25 #ifndef SHARE_VM_GC_CMS_CONCURRENTMARKSWEEPTHREAD_HPP
  26 #define SHARE_VM_GC_CMS_CONCURRENTMARKSWEEPTHREAD_HPP
  27 
  28 #include "gc/cms/concurrentMarkSweepGeneration.hpp"
  29 #include "gc/shared/concurrentGCThread.hpp"
  30 #include "runtime/thread.hpp"
  31 
  32 class ConcurrentMarkSweepGeneration;
  33 class CMSCollector;
  34 
  35 // The Concurrent Mark Sweep GC Thread
  36 class ConcurrentMarkSweepThread: public ConcurrentGCThread {
  37   friend class VMStructs;
  38   friend class ConcurrentMarkSweepGeneration;   // XXX should remove friendship
  39   friend class CMSCollector;
  40 
  41  private:
  42   static ConcurrentMarkSweepThread* _cmst;
  43   static CMSCollector*              _collector;



  44 
  45   enum CMS_flag_type {
  46     CMS_nil             = NoBits,
  47     CMS_cms_wants_token = nth_bit(0),
  48     CMS_cms_has_token   = nth_bit(1),
  49     CMS_vm_wants_token  = nth_bit(2),
  50     CMS_vm_has_token    = nth_bit(3)
  51   };
  52 
  53   static int _CMS_flag;
  54 
  55   static bool CMS_flag_is_set(int b)        { return (_CMS_flag & b) != 0;   }
  56   static bool set_CMS_flag(int b)           { return (_CMS_flag |= b) != 0;  }
  57   static bool clear_CMS_flag(int b)         { return (_CMS_flag &= ~b) != 0; }
  58   void sleepBeforeNextCycle();
  59 
  60   // CMS thread should yield for a young gen collection and direct allocations
  61   static char _pad_1[64 - sizeof(jint)];    // prevent cache-line sharing
  62   static volatile jint _pending_yields;
  63   static char _pad_2[64 - sizeof(jint)];    // prevent cache-line sharing
  64 
  65   // debugging
  66   void verify_ok_to_terminate() const PRODUCT_RETURN;
  67 
  68   void run_service();
  69   void stop_service();
  70 
  71  public:
  72   // Constructor
  73   ConcurrentMarkSweepThread(CMSCollector* collector);



  74 
  75   static void threads_do(ThreadClosure* tc);
  76 
  77   // Printing
  78   static void print_all_on(outputStream* st);
  79   static void print_all()                             { print_all_on(tty); }
  80 
  81   // Returns the CMS Thread
  82   static ConcurrentMarkSweepThread* cmst()    { return _cmst; }
  83   static CMSCollector*         collector()    { return _collector;  }
  84 
  85   // Create and start the CMS Thread, or stop it on shutdown
  86   static ConcurrentMarkSweepThread* start(CMSCollector* collector);
  87 
  88   // Synchronization using CMS token
  89   static void synchronize(bool is_cms_thread);
  90   static void desynchronize(bool is_cms_thread);
  91   static bool vm_thread_has_cms_token() {
  92     return CMS_flag_is_set(CMS_vm_has_token);
  93   }


< prev index next >