< prev index next >

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

Print this page
rev 10389 : imported patch webrev.01
rev 10390 : imported patch webrev.02
rev 10391 : [mq]: webrev.03
rev 10392 : imported patch webrev.04
rev 10393 : [mq]: web.05
   1 /*
   2  * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  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  public:
  41   virtual void run();
  42 
  43  private:
  44   static ConcurrentMarkSweepThread*     _cmst;
  45   static CMSCollector*                  _collector;
  46   static SurrogateLockerThread*         _slt;
  47   static SurrogateLockerThread::SLT_msg_type _sltBuffer;
  48   static Monitor*                       _sltMonitor;
  49 
  50   static bool _should_terminate;
  51 
  52   enum CMS_flag_type {
  53     CMS_nil             = NoBits,
  54     CMS_cms_wants_token = nth_bit(0),
  55     CMS_cms_has_token   = nth_bit(1),
  56     CMS_vm_wants_token  = nth_bit(2),
  57     CMS_vm_has_token    = nth_bit(3)
  58   };
  59 
  60   static int _CMS_flag;
  61 
  62   static bool CMS_flag_is_set(int b)        { return (_CMS_flag & b) != 0;   }
  63   static bool set_CMS_flag(int b)           { return (_CMS_flag |= b) != 0;  }
  64   static bool clear_CMS_flag(int b)         { return (_CMS_flag &= ~b) != 0; }
  65   void sleepBeforeNextCycle();
  66 
  67   // CMS thread should yield for a young gen collection and direct allocations
  68   static char _pad_1[64 - sizeof(jint)];    // prevent cache-line sharing
  69   static volatile jint _pending_yields;
  70   static char _pad_2[64 - sizeof(jint)];    // prevent cache-line sharing
  71 
  72   // debugging
  73   void verify_ok_to_terminate() const PRODUCT_RETURN;
  74 



  75  public:
  76   // Constructor
  77   ConcurrentMarkSweepThread(CMSCollector* collector);
  78 
  79   static void makeSurrogateLockerThread(TRAPS);
  80   static SurrogateLockerThread* slt() { return _slt; }
  81 
  82   static void threads_do(ThreadClosure* tc);
  83 
  84   // Printing
  85   static void print_all_on(outputStream* st);
  86   static void print_all()                             { print_all_on(tty); }
  87 
  88   // Returns the CMS Thread
  89   static ConcurrentMarkSweepThread* cmst()    { return _cmst; }
  90   static CMSCollector*         collector()    { return _collector;  }
  91 
  92   // Create and start the CMS Thread, or stop it on shutdown
  93   static ConcurrentMarkSweepThread* start(CMSCollector* collector);
  94   static void stop();
  95   static bool should_terminate() { return _should_terminate; }
  96 
  97   // Synchronization using CMS token
  98   static void synchronize(bool is_cms_thread);
  99   static void desynchronize(bool is_cms_thread);
 100   static bool vm_thread_has_cms_token() {
 101     return CMS_flag_is_set(CMS_vm_has_token);
 102   }
 103   static bool cms_thread_has_cms_token() {
 104     return CMS_flag_is_set(CMS_cms_has_token);
 105   }
 106   static bool vm_thread_wants_cms_token() {
 107     return CMS_flag_is_set(CMS_vm_wants_token);
 108   }
 109   static bool cms_thread_wants_cms_token() {
 110     return CMS_flag_is_set(CMS_cms_wants_token);
 111   }
 112 
 113   // Wait on CMS lock until the next synchronous GC
 114   // or given timeout, whichever is earlier. A timeout value
 115   // of 0 indicates that there is no upper bound on the wait time.


   1 /*
   2  * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  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   }
 100   static bool cms_thread_has_cms_token() {
 101     return CMS_flag_is_set(CMS_cms_has_token);
 102   }
 103   static bool vm_thread_wants_cms_token() {
 104     return CMS_flag_is_set(CMS_vm_wants_token);
 105   }
 106   static bool cms_thread_wants_cms_token() {
 107     return CMS_flag_is_set(CMS_cms_wants_token);
 108   }
 109 
 110   // Wait on CMS lock until the next synchronous GC
 111   // or given timeout, whichever is earlier. A timeout value
 112   // of 0 indicates that there is no upper bound on the wait time.


< prev index next >