1 /* 2 * Copyright (c) 2018, 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_SHENANDOAHTRAVERSALGC_HPP 25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHTRAVERSALGC_HPP 26 27 #include "memory/allocation.hpp" 28 #include "gc/shenandoah/shenandoahHeapRegionSet.hpp" 29 #include "gc/shenandoah/shenandoahTaskqueue.hpp" 30 #include "gc/shenandoah/shenandoahArrayCopyTaskQueue.hpp" 31 32 class Thread; 33 class ShenandoahHeap; 34 class ShenandoahStrDedupQueue; 35 36 class ShenandoahTraversalGC : public CHeapObj<mtGC> { 37 private: 38 ShenandoahHeap* const _heap; 39 ShenandoahObjToScanQueueSet* const _task_queues; 40 41 // Used for buffering per-region liveness data. 42 // Needed since ShenandoahHeapRegion uses atomics to update liveness. 43 // 44 // The array has max-workers elements, each of which is an array of 45 // jushort * max_regions. The choice of jushort is not accidental: 46 // there is a tradeoff between static/dynamic footprint that translates 47 // into cache pressure (which is already high during marking), and 48 // too many atomic updates. size_t/jint is too large, jbyte is too small. 49 jushort** _liveness_local; 50 51 ShenandoahHeapRegionSet _traversal_set; 52 ShenandoahHeapRegionSet _root_regions; 53 54 ShenandoahHeapRegionSetIterator _root_regions_iterator; 55 56 ShenandoahConnectionMatrix* const _matrix; 57 58 ShenandoahArrayCopyTaskQueue _arraycopy_task_queue; 59 60 public: 61 ShenandoahTraversalGC(ShenandoahHeap* heap, size_t num_regions); 62 ~ShenandoahTraversalGC(); 63 64 ShenandoahHeapRegionSet* traversal_set() { return &_traversal_set; } 65 ShenandoahHeapRegionSet* root_regions() { return &_root_regions;} 66 67 void reset(); 68 void prepare(); 69 void init_traversal_collection(); 70 void concurrent_traversal_collection(); 71 void final_traversal_collection(); 72 73 template <class T, bool STRING_DEDUP, bool DEGEN, bool UPDATE_MATRIX> 74 inline void process_oop(T* p, Thread* thread, ShenandoahObjToScanQueue* queue, ShenandoahMarkingContext* const mark_context, oop base_obj); 75 76 bool check_and_handle_cancelled_gc(ParallelTaskTerminator* terminator); 77 78 ShenandoahObjToScanQueueSet* task_queues(); 79 80 jushort* get_liveness(uint worker_id); 81 void flush_liveness(uint worker_id); 82 83 void main_loop(uint worker_id, ParallelTaskTerminator* terminator); 84 85 void push_arraycopy(HeapWord* start, size_t count); 86 87 private: 88 89 void prepare_regions(); 90 91 template <class T> 92 void main_loop_work(T* cl, jushort* live_data, uint worker_id, ParallelTaskTerminator* terminator); 93 94 void preclean_weak_refs(); 95 void weak_refs_work(); 96 void weak_refs_work_doit(); 97 98 void fixup_roots(); 99 100 template <class T> 101 bool process_arraycopy_task(T* cl); 102 }; 103 104 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHTRAVERSALGC_HPP