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 private:
38   ShenandoahHeap* _heap;
39   ShenandoahObjToScanQueueSet* _task_queues;
40 
41 public:
42   void initialize(uint workers);
43   void cancel();
44 
45 // ---------- Marking loop and tasks
46 //
47 private:
48   template <class T>
49   inline void do_task(ShenandoahObjToScanQueue* q, T* cl, ShenandoahLiveData* live_data, ShenandoahMarkTask* task);
50 
51   template <class T>
52   inline void do_chunked_array_start(ShenandoahObjToScanQueue* q, T* cl, oop array);
53 
54   template <class T>
55   inline void do_chunked_array(ShenandoahObjToScanQueue* q, T* cl, oop array, int chunk, int pow);
56 
57   inline void count_liveness(ShenandoahLiveData* live_data, oop obj);
58 
59   template <class T, bool CANCELLABLE>
60   void mark_loop_work(T* cl, ShenandoahLiveData* live_data, uint worker_id, TaskTerminator *t);
61 
62   template <bool CANCELLABLE>
63   void mark_loop_prework(uint worker_id, TaskTerminator *terminator, ReferenceProcessor *rp, bool strdedup);
64 
65 public:
mark_loop(uint worker_id,TaskTerminator * terminator,ReferenceProcessor * rp,bool cancellable,bool strdedup)66   void mark_loop(uint worker_id, TaskTerminator* terminator, ReferenceProcessor *rp,
67                  bool cancellable, bool strdedup) {
68     if (cancellable) {
69       mark_loop_prework<true>(worker_id, terminator, rp, strdedup);
70     } else {
71       mark_loop_prework<false>(worker_id, terminator, rp, strdedup);
72     }
73   }
74 
75   template<class T, UpdateRefsMode UPDATE_REFS, StringDedupMode STRING_DEDUP>
76   static inline void mark_through_ref(T* p, ShenandoahHeap* heap, ShenandoahObjToScanQueue* q, ShenandoahMarkingContext* const mark_context);
77 
78   void mark_from_roots();
79   void finish_mark_from_roots(bool full_gc);
80 
81   void mark_roots(ShenandoahPhaseTimings::Phase root_phase);
82   void update_roots(ShenandoahPhaseTimings::Phase root_phase);
83   void update_thread_roots(ShenandoahPhaseTimings::Phase root_phase);
84 
85 // ---------- Weak references
86 //
87 private:
88   void weak_refs_work(bool full_gc);
89   void weak_refs_work_doit(bool full_gc);
90 
91 public:
92   void preclean_weak_refs();
93 
94 // ---------- Helpers
95 // Used from closures, need to be public
96 //
97 public:
98   ShenandoahObjToScanQueue* get_queue(uint worker_id);
task_queues()99   ShenandoahObjToScanQueueSet* task_queues() { return _task_queues; }
100 
101 };
102 
103 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHCONCURRENTMARK_HPP
104