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/shenandoah/shenandoahHeap.hpp"
  28 #include "gc/shared/concurrentGCThread.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 private:
  39   Monitor _full_gc_lock;
  40 
  41 public:
  42   void run_service();
  43   void stop_service();
  44 
  45 private:
  46   volatile jbyte _do_full_gc;
  47   volatile jbyte _graceful_shutdown;
  48   GCCause::Cause _full_gc_cause;
  49 
  50   void sleepBeforeNextCycle();
  51 
  52   bool check_cancellation();
  53   void service_normal_cycle();
  54   void service_fullgc_cycle();
  55 
  56 public:
  57   // Constructor
  58   ShenandoahConcurrentThread();
  59   ~ShenandoahConcurrentThread();
  60 
  61   // Printing
  62   void print_on(outputStream* st) const;
  63   void print() const;
  64 
  65   void do_full_gc(GCCause::Cause cause);
  66 
  67   bool try_set_full_gc();
  68   void reset_full_gc();
  69   bool is_full_gc();
  70 
  71   char* name() const { return (char*)"ShenandoahConcurrentThread";}
  72   void start();
  73 
  74   void prepare_for_graceful_shutdown();
  75   bool in_graceful_shutdown();
  76 };
  77 
  78 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHCONCURRENTTHREAD_HPP