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_SHENANDOAHCONCURRENTMARK_HPP
  25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHCONCURRENTMARK_HPP
  26 
  27 #include "gc/shared/taskqueue.hpp"
  28 #include "gc/shared/workgroup.hpp"
  29 
  30 typedef OverflowTaskQueue<oop, mtGC> OopOverflowTaskQueue;
  31 typedef Padded<OopOverflowTaskQueue> SCMObjToScanQueue;
  32 typedef GenericTaskQueueSet<SCMObjToScanQueue, mtGC> SCMObjToScanQueueSet;
  33 
  34 class ShenandoahConcurrentMark;
  35 
  36 #ifdef ASSERT
  37 class ShenandoahVerifyRootsClosure1 : public OopClosure {
  38   void do_oop(oop* p);
  39 
  40   void do_oop(narrowOop* p) {
  41     Unimplemented();
  42   }
  43 };
  44 #endif
  45 
  46 class ShenandoahMarkRefsClosure : public MetadataAwareOopClosure {
  47   SCMObjToScanQueue* _queue;
  48   ShenandoahHeap* _heap;
  49   bool _update_refs;
  50   ShenandoahConcurrentMark* _scm;
  51 
  52 public:
  53   ShenandoahMarkRefsClosure(SCMObjToScanQueue* q, bool update_refs);
  54 
  55   void do_oop(narrowOop* p);
  56 
  57   inline void do_oop(oop* p);
  58 
  59 };
  60 
  61 class ShenandoahMarkObjsClosure : public ObjectClosure {
  62   ShenandoahHeap* _heap;
  63   size_t* _live_data;
  64   ShenandoahMarkRefsClosure _mark_refs;
  65 
  66 public:
  67   ShenandoahMarkObjsClosure(SCMObjToScanQueue* q, bool update_refs);
  68 
  69   ~ShenandoahMarkObjsClosure();
  70 
  71   inline void do_object(oop obj);
  72 };
  73 
  74 class ShenandoahConcurrentMark: public CHeapObj<mtGC> {
  75 
  76 private:
  77   // The per-worker-thread work queues
  78   SCMObjToScanQueueSet* _task_queues;
  79 
  80   bool                    _aborted;
  81   uint _max_conc_worker_id;
  82   ParallelTaskTerminator* _terminator;
  83 
  84 public:
  85   // We need to do this later when the heap is already created.
  86   void initialize();
  87 
  88   void mark_from_roots();
  89 
  90   // Prepares unmarked root objects by marking them and putting
  91   // them into the marking task queue.
  92   void prepare_unmarked_root_objs();
  93   void prepare_unmarked_root_objs_no_derived_ptrs(bool update_refs);
  94 
  95   void finish_mark_from_roots();
  96   // Those are only needed public because they're called from closures.
  97 
  98   SCMObjToScanQueue* get_queue(uint worker_id);
  99   inline bool try_queue(SCMObjToScanQueue* q, ShenandoahMarkObjsClosure* cl);
 100   inline bool try_to_steal(uint worker_id, ShenandoahMarkObjsClosure* cl, int *seed);
 101   inline bool try_draining_an_satb_buffer(uint worker_id);
 102   void drain_satb_buffers(uint worker_id, bool remark = false);
 103   SCMObjToScanQueueSet* task_queues() { return _task_queues;}
 104   uint max_conc_worker_id() { return _max_conc_worker_id; }
 105 
 106   void cancel();
 107 
 108 private:
 109 
 110 #ifdef ASSERT
 111   void verify_roots();
 112 #endif
 113 
 114   bool drain_one_satb_buffer(uint worker_id);
 115   void weak_refs_work();
 116 
 117   ParallelTaskTerminator* terminator() { return _terminator;}
 118 
 119 #if TASKQUEUE_STATS
 120   static void print_taskqueue_stats_hdr(outputStream* const st = gclog_or_tty);
 121   void print_taskqueue_stats(outputStream* const st = gclog_or_tty) const;
 122   void print_push_only_taskqueue_stats(outputStream* const st = gclog_or_tty) const;
 123   void reset_taskqueue_stats();
 124 #endif // TASKQUEUE_STATS
 125 
 126 };
 127 
 128 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHCONCURRENTMARK_HPP