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 
33 class ShenandoahOldGeneration : public ShenandoahGeneration {
34  public:
35   ShenandoahOldGeneration(uint max_queues, size_t max_capacity, size_t soft_max_capacity);
36 
37   const char* name() const override;
38 
39   bool contains(ShenandoahHeapRegion* region) const override;
40 
41   bool contains(oop obj) const override;
42 
43   void parallel_heap_region_iterate(ShenandoahHeapRegionClosure* cl) override;
44 
45   void heap_region_iterate(ShenandoahHeapRegionClosure* cl) override;
46 
47   void set_concurrent_mark_in_progress(bool in_progress) override;
48 
49   bool prepare_regions_and_collection_set(bool concurrent) override;
50 
51   virtual ShenandoahHeuristics* initialize_heuristics(ShenandoahMode* gc_mode) override;
52 
53   // We leave the SATB barrier on for the entirety of the old generation
54   // marking phase. In some cases, this can cause a write to a perfectly
55   // reachable oop to enqueue a pointer that later becomes garbage (because
56   // it points at an object in the collection set, for example). There are
57   // also cases where the referent of a weak reference ends up in the SATB
58   // and is later collected. In these cases the oop in the SATB buffer becomes
59   // invalid and the _next_ cycle will crash during its marking phase. To
60   // avoid this problem, we "purge" the SATB buffers during the final update
61   // references phase if (and only if) an old generation mark is in progress.
62   // At this stage we can safely determine if any of the oops in the SATB
63   // buffer belong to trashed regions (before they are recycled). As it
64   // happens, flushing a SATB queue also filters out oops which have already
65   // been marked - which is the case for anything that is being evacuated
66   // from the collection set.
67   //
68   // Alternatively, we could inspect the state of the heap and the age of the
69   // object at the barrier, but we reject this approach because it is likely
70   // the performance impact would be too severe.
71   void purge_satb_buffers(bool abandon);
72  protected:
73   bool is_concurrent_mark_in_progress() override;
74 };
75 
76 
77 #endif //SHARE_VM_GC_SHENANDOAH_SHENANDOAHOLDGENERATION_HPP