1 /*
   2  * Copyright (c) 2013, 2020, Red Hat, Inc. 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_GC_SHENANDOAH_SHENANDOAHCONCURRENTMARK_HPP
  26 #define SHARE_GC_SHENANDOAH_SHENANDOAHCONCURRENTMARK_HPP
  27 
  28 #include "gc/shared/taskqueue.hpp"
  29 #include "gc/shared/taskTerminator.hpp"
  30 #include "gc/shenandoah/shenandoahOopClosures.hpp"
  31 #include "gc/shenandoah/shenandoahPhaseTimings.hpp"
  32 #include "gc/shenandoah/shenandoahTaskqueue.hpp"
  33 
  34 class ShenandoahStrDedupQueue;
  35 
  36 class ShenandoahConcurrentMark: public CHeapObj<mtGC> {
  37   friend class ShenandoahTraversalGC;
  38 private:
  39   ShenandoahHeap* _heap;
  40   ShenandoahObjToScanQueueSet* _task_queues;
  41 
  42 public:
  43   void initialize(uint workers);
  44   void cancel();
  45 
  46 // ---------- Marking loop and tasks
  47 //
  48 private:
  49   template <class T>
  50   inline void do_task(ShenandoahObjToScanQueue* q, T* cl, jushort* live_data, ShenandoahMarkTask* task);
  51 
  52   template <class T>
  53   inline void do_chunked_array_start(ShenandoahObjToScanQueue* q, T* cl, oop array);
  54 
  55   template <class T>
  56   inline void do_chunked_array(ShenandoahObjToScanQueue* q, T* cl, oop array, int chunk, int pow);
  57 
  58   inline void count_liveness(jushort* live_data, oop obj);
  59 
  60   template <class T, bool CANCELLABLE>
  61   void mark_loop_work(T* cl, jushort* live_data, uint worker_id, TaskTerminator *t);
  62 
  63   template <bool CANCELLABLE>
  64   void mark_loop_prework(uint worker_id, TaskTerminator *terminator, ReferenceProcessor *rp, bool strdedup);
  65 
  66 public:
  67   void mark_loop(uint worker_id, TaskTerminator* terminator, ReferenceProcessor *rp,
  68                  bool cancellable, bool strdedup) {
  69     if (cancellable) {
  70       mark_loop_prework<true>(worker_id, terminator, rp, strdedup);
  71     } else {
  72       mark_loop_prework<false>(worker_id, terminator, rp, strdedup);
  73     }
  74   }
  75 
  76   template<class T, UpdateRefsMode UPDATE_REFS, StringDedupMode STRING_DEDUP>
  77   static inline void mark_through_ref(T* p, ShenandoahHeap* heap, ShenandoahObjToScanQueue* q, ShenandoahMarkingContext* const mark_context);
  78 
  79   void mark_from_roots();
  80   void finish_mark_from_roots(bool full_gc);
  81 
  82   void mark_roots(ShenandoahPhaseTimings::Phase root_phase);
  83   void update_roots(ShenandoahPhaseTimings::Phase root_phase);
  84   void update_thread_roots(ShenandoahPhaseTimings::Phase root_phase);
  85   // Remark on stack nmethod's metadata
  86   void remark_thread_roots();
  87 
  88 // ---------- Weak references
  89 //
  90 private:
  91   void weak_refs_work(bool full_gc);
  92   void weak_refs_work_doit(bool full_gc);
  93 
  94 public:
  95   void preclean_weak_refs();
  96 
  97 // ---------- Concurrent code cache
  98 //
  99 private:
 100   ShenandoahSharedFlag _claimed_codecache;
 101 
 102 public:
 103   void concurrent_scan_code_roots(uint worker_id, ReferenceProcessor* rp);
 104   bool claim_codecache();
 105   void clear_claim_codecache();
 106 
 107 // ---------- Helpers
 108 // Used from closures, need to be public
 109 //
 110 public:
 111   ShenandoahObjToScanQueue* get_queue(uint worker_id);
 112   ShenandoahObjToScanQueueSet* task_queues() { return _task_queues; }
 113 
 114 };
 115 
 116 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHCONCURRENTMARK_HPP