1 /* 2 * Copyright (c) 2021, Amazon.com, Inc. or its affiliates. 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_VM_GC_SHENANDOAH_SHENANDOAHOLDGENERATION_HPP 26 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHOLDGENERATION_HPP 27 28 #include "gc/shenandoah/shenandoahGeneration.hpp" 29 30 class ShenandoahHeapRegion; 31 class ShenandoahHeapRegionClosure; 32 class ShenandoahOldHeuristics; 33 34 class ShenandoahOldGeneration : public ShenandoahGeneration { 35 public: 36 ShenandoahOldGeneration(uint max_queues, size_t max_capacity, size_t soft_max_capacity); 37 38 const char* name() const override; 39 40 bool contains(ShenandoahHeapRegion* region) const override; 41 42 bool contains(oop obj) const override; 43 44 void parallel_heap_region_iterate(ShenandoahHeapRegionClosure* cl) override; 45 46 void heap_region_iterate(ShenandoahHeapRegionClosure* cl) override; 47 48 void set_concurrent_mark_in_progress(bool in_progress) override; 49 50 virtual void cancel_marking() override; 51 52 virtual void prepare_gc() override; 53 54 void prepare_regions_and_collection_set(bool concurrent) override; 55 56 virtual ShenandoahHeuristics* initialize_heuristics(ShenandoahMode* gc_mode) override; 57 58 // We leave the SATB barrier on for the entirety of the old generation 59 // marking phase. In some cases, this can cause a write to a perfectly 60 // reachable oop to enqueue a pointer that later becomes garbage (because 61 // it points at an object in the collection set, for example). There are 62 // also cases where the referent of a weak reference ends up in the SATB 63 // and is later collected. In these cases the oop in the SATB buffer becomes 64 // invalid and the _next_ cycle will crash during its marking phase. To 65 // avoid this problem, we "purge" the SATB buffers during the final update 66 // references phase if (and only if) an old generation mark is in progress. 67 // At this stage we can safely determine if any of the oops in the SATB 68 // buffer belong to trashed regions (before they are recycled). As it 69 // happens, flushing a SATB queue also filters out oops which have already 70 // been marked - which is the case for anything that is being evacuated 71 // from the collection set. 72 // 73 // Alternatively, we could inspect the state of the heap and the age of the 74 // object at the barrier, but we reject this approach because it is likely 75 // the performance impact would be too severe. 76 void transfer_pointers_from_satb(); 77 78 bool is_concurrent_mark_in_progress() override; 79 80 virtual void record_success_concurrent(bool abbreviated) override; 81 82 enum State { 83 IDLE, FILLING, BOOTSTRAPPING, MARKING, WAITING 84 }; 85 86 static const char* state_name(State state); 87 88 void transition_to(State new_state); 89 90 #ifdef ASSERT 91 bool validate_transition(State new_state); 92 #endif 93 94 State state() const { 95 return _state; 96 } 97 98 private: 99 bool entry_coalesce_and_fill(); 100 bool coalesce_and_fill(); 101 102 ShenandoahHeapRegion** _coalesce_and_fill_region_array; 103 ShenandoahOldHeuristics* _old_heuristics; 104 State _state; 105 }; 106 107 108 #endif //SHARE_VM_GC_SHENANDOAH_SHENANDOAHOLDGENERATION_HPP