1 /*
   2  * Copyright (c) 2013, 2015, Red Hat, Inc. and/or its affiliates.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.
   7  *
   8  * This code is distributed in the hope that it will be useful, but WITHOUT
   9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #ifndef SHARE_VM_GC_SHENANDOAH_SHENANDOAHCONCURRENTTHREAD_HPP
  25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHCONCURRENTTHREAD_HPP
  26 
  27 #include "gc/shared/concurrentGCThread.hpp"
  28 #include "gc/g1/suspendibleThreadSet.hpp"
  29 #include "gc/shared/gcCause.hpp"
  30 #include "memory/resourceArea.hpp"
  31 
  32 // For now we just want to have a concurrent marking thread.
  33 // Once we have that working we will build a concurrent evacuation thread.
  34 
  35 class ShenandoahConcurrentThread: public ConcurrentGCThread {
  36   friend class VMStructs;
  37 
  38  public:
  39   virtual void run();
  40 
  41  private:
  42   volatile bool                    _concurrent_mark_started;
  43   volatile bool                    _concurrent_mark_in_progress;
  44   volatile bool                    _concurrent_mark_aborted;
  45 
  46   int _epoch;
  47 
  48   static SurrogateLockerThread* _slt;
  49   static SuspendibleThreadSet _sts;
  50 
  51   bool _do_full_gc;
  52   GCCause::Cause _full_gc_cause;
  53 
  54   void sleepBeforeNextCycle();
  55 
  56  public:
  57   // Constructor
  58   ShenandoahConcurrentThread();
  59   ~ShenandoahConcurrentThread();
  60 
  61   static void makeSurrogateLockerThread(TRAPS);
  62   static SurrogateLockerThread* slt() { return _slt; }
  63 
  64   // Printing
  65   void print_on(outputStream* st) const;
  66   void print() const;
  67 
  68   void set_cm_started();
  69   void clear_cm_started();
  70   bool cm_started();
  71 
  72   void set_cm_in_progress();
  73   void clear_cm_in_progress();
  74   bool cm_in_progress();
  75 
  76   void cm_abort() { _concurrent_mark_aborted = true;}
  77   bool cm_has_aborted() { return _concurrent_mark_aborted;}
  78   void clear_cm_aborted() { _concurrent_mark_aborted = false;}
  79 
  80   void do_full_gc(GCCause::Cause cause);
  81 
  82   void schedule_full_gc();
  83 
  84   // This flag returns true from the moment a marking cycle is
  85   // initiated (during the initial-mark pause when started() is set)
  86   // to the moment when the cycle completes (just after the next
  87   // marking bitmap has been cleared and in_progress() is
  88   // cleared). While this flag is true we will not start another cycle
  89   // so that cycles do not overlap. We cannot use just in_progress()
  90   // as the CM thread might take some time to wake up before noticing
  91   // that started() is set and set in_progress().
  92   bool during_cycle()      { return cm_started() || cm_in_progress(); }
  93 
  94   char* name() const { return (char*)"ShenandoahConcurrentThread";}
  95   void start();
  96   void yield();
  97 
  98   static void safepoint_synchronize();
  99   static void safepoint_desynchronize();
 100 
 101   void shutdown();
 102 };
 103 
 104 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHCONCURRENTTHREAD_HPP