1 /* 2 * Copyright (c) 2014, 2021, 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_SHENANDOAHFULLGC_HPP 27 #define SHARE_GC_SHENANDOAH_SHENANDOAHFULLGC_HPP 28 29 #include "gc/shared/gcTimer.hpp" 30 #include "gc/shenandoah/shenandoahGC.hpp" 31 #include "gc/shenandoah/shenandoahHeapRegionSet.hpp" 32 33 /** 34 * This implements Full GC (e.g. when invoking System.gc()) using a mark-compact algorithm. 35 * 36 * Current implementation is parallel sliding Lisp-2-style algorithm, based on 37 * "Parallel Garbage Collection for Shared Memory Multiprocessors", by Christine Flood et al. 38 * http://people.csail.mit.edu/shanir/publications/dfsz2001.pdf 39 * 40 * It is implemented in four phases: 41 * 42 * 1. Mark all live objects of the heap by traversing objects starting at GC roots. 43 * 2. Calculate the new location of each live object. This is done by sequentially scanning 44 * the heap, keeping track of a next-location-pointer, which is then written to each 45 * object's fwdptr field. 46 * 3. Update all references. This is implemented by another scan of the heap, and updates 47 * all references in live objects by what's stored in the target object's fwdptr. 48 * 4. Compact the heap by copying all live objects to their new location. 49 * 50 * Parallelization is handled by assigning each GC worker the slice of the heap (the set of regions) 51 * where it does sliding compaction, without interfering with other threads. 52 */ 53 54 class PreservedMarksSet; 55 class VM_ShenandoahFullGC; 56 class ShenandoahDegenGC; 57 58 class ShenandoahFullGC : public ShenandoahGC { 59 friend class ShenandoahPrepareForCompactionObjectClosure; 60 friend class VM_ShenandoahFullGC; 61 friend class ShenandoahDegenGC; 62 63 private: 64 GCTimer* _gc_timer; 65 66 PreservedMarksSet* _preserved_marks; 67 68 public: 69 ShenandoahFullGC(); 70 ~ShenandoahFullGC(); 71 bool collect(GCCause::Cause cause); 72 73 private: 74 // GC entries 75 void vmop_entry_full(GCCause::Cause cause); 76 void entry_full(GCCause::Cause cause); 77 void op_full(GCCause::Cause cause); 78 79 void do_it(GCCause::Cause gc_cause); 80 81 void phase1_mark_heap(); 82 void phase2_calculate_target_addresses(ShenandoahHeapRegionSet** worker_slices); 83 void phase3_update_references(); 84 void phase4_compact_objects(ShenandoahHeapRegionSet** worker_slices); 85 void phase5_epilog(); 86 87 void distribute_slices(ShenandoahHeapRegionSet** worker_slices); 88 void calculate_target_humongous_objects(); 89 void compact_humongous_objects(); 90 }; 91 92 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHFULLGC_HPP