1 /*
  2  * Copyright (c) 2021, 2022, Red Hat, Inc. All rights reserved.
  3  * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
  4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5  *
  6  * This code is free software; you can redistribute it and/or modify it
  7  * under the terms of the GNU General Public License version 2 only, as
  8  * published by the Free Software Foundation.
  9  *
 10  * This code is distributed in the hope that it will be useful, but WITHOUT
 11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 13  * version 2 for more details (a copy is included in the LICENSE file that
 14  * accompanied this code).
 15  *
 16  * You should have received a copy of the GNU General Public License version
 17  * 2 along with this work; if not, write to the Free Software Foundation,
 18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19  *
 20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21  * or visit www.oracle.com if you need additional information or have any
 22  * questions.
 23  *
 24  */
 25 
 26 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHMARK_HPP
 27 #define SHARE_GC_SHENANDOAH_SHENANDOAHMARK_HPP
 28 
 29 #include "gc/shared/ageTable.hpp"
 30 #include "gc/shared/stringdedup/stringDedup.hpp"
 31 #include "gc/shared/taskTerminator.hpp"
 32 #include "gc/shenandoah/shenandoahOopClosures.hpp"
 33 #include "gc/shenandoah/shenandoahTaskqueue.hpp"
 34 
 35 // Base class for mark
 36 // Mark class does not maintain states. Instead, mark states are
 37 // maintained by task queues, mark bitmap and SATB buffers (concurrent mark)
 38 class ShenandoahMark: public StackObj {
 39 protected:
 40   ShenandoahGeneration* const _generation;
 41   ShenandoahObjToScanQueueSet* const _task_queues;
 42   ShenandoahObjToScanQueueSet* const _old_gen_task_queues;
 43 
 44 protected:
 45   ShenandoahMark(ShenandoahGeneration* generation);
 46 
 47 public:
 48   template<class T, ShenandoahGenerationType GENERATION>
 49   static inline void mark_through_ref(T* p, ShenandoahObjToScanQueue* q, ShenandoahObjToScanQueue* old_q, ShenandoahMarkingContext* const mark_context, bool weak);
 50 
 51   // Loom support
 52   void start_mark();
 53   void end_mark();
 54 
 55   // Helpers
 56   inline ShenandoahObjToScanQueueSet* task_queues() const;
 57   ShenandoahObjToScanQueueSet* old_task_queues() {
 58     return _old_gen_task_queues;
 59   }
 60 
 61   inline ShenandoahObjToScanQueue* get_queue(uint index) const;
 62   inline ShenandoahObjToScanQueue* get_old_queue(uint index) const;
 63 
 64   inline ShenandoahGeneration* generation() { return _generation; };
 65 
 66 private:
 67 // ---------- Marking loop and tasks
 68 
 69   template <class T, ShenandoahGenerationType GENERATION, StringDedupMode STRING_DEDUP>
 70   inline void do_task(ShenandoahObjToScanQueue* q, T* cl, ShenandoahLiveData* live_data, StringDedup::Requests* const req, ShenandoahMarkTask* task, uint worker_id);
 71 
 72   template <class T>
 73   inline void do_chunked_array_start(ShenandoahObjToScanQueue* q, T* cl, oop array, bool weak);
 74 
 75   template <class T>
 76   inline void do_chunked_array(ShenandoahObjToScanQueue* q, T* cl, oop array, int chunk, int pow, bool weak);
 77 
 78   template <ShenandoahGenerationType GENERATION>
 79   inline void count_liveness(ShenandoahLiveData* live_data, oop obj, uint worker_id);
 80 
 81   template <class T, ShenandoahGenerationType GENERATION, bool CANCELLABLE, StringDedupMode STRING_DEDUP>
 82   void mark_loop_work(T* cl, ShenandoahLiveData* live_data, uint worker_id, TaskTerminator *t, StringDedup::Requests* const req);
 83 
 84   template <ShenandoahGenerationType GENERATION, bool CANCELLABLE, StringDedupMode STRING_DEDUP>
 85   void mark_loop_prework(uint worker_id, TaskTerminator *terminator, ShenandoahReferenceProcessor *rp, StringDedup::Requests* const req, bool update_refs);
 86 
 87   template <ShenandoahGenerationType GENERATION>
 88   static bool in_generation(ShenandoahHeap* const heap, oop obj);
 89 
 90   static void mark_ref(ShenandoahObjToScanQueue* q,
 91                        ShenandoahMarkingContext* const mark_context,
 92                        bool weak, oop obj);
 93 
 94   template <StringDedupMode STRING_DEDUP>
 95   inline void dedup_string(oop obj, StringDedup::Requests* const req);
 96 protected:
 97   template<bool CANCELLABLE, StringDedupMode STRING_DEDUP>
 98   void mark_loop(ShenandoahGenerationType generation, uint worker_id, TaskTerminator* terminator, ShenandoahReferenceProcessor *rp,
 99                  StringDedup::Requests* const req);
100 
101   void mark_loop(ShenandoahGenerationType generation, uint worker_id, TaskTerminator* terminator, ShenandoahReferenceProcessor *rp,
102                  bool cancellable, StringDedupMode dedup_mode, StringDedup::Requests* const req);
103 };
104 
105 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHMARK_HPP