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   virtual void cancel_marking() override;
50 
51   void prepare_regions_and_collection_set(bool concurrent) override;
52 
53   virtual ShenandoahHeuristics* initialize_heuristics(ShenandoahMode* gc_mode) override;
54 
55   // We leave the SATB barrier on for the entirety of the old generation
56   // marking phase. In some cases, this can cause a write to a perfectly
57   // reachable oop to enqueue a pointer that later becomes garbage (because
58   // it points at an object in the collection set, for example). There are
59   // also cases where the referent of a weak reference ends up in the SATB
60   // and is later collected. In these cases the oop in the SATB buffer becomes
61   // invalid and the _next_ cycle will crash during its marking phase. To
62   // avoid this problem, we "purge" the SATB buffers during the final update
63   // references phase if (and only if) an old generation mark is in progress.
64   // At this stage we can safely determine if any of the oops in the SATB
65   // buffer belong to trashed regions (before they are recycled). As it
66   // happens, flushing a SATB queue also filters out oops which have already
67   // been marked - which is the case for anything that is being evacuated
68   // from the collection set.
69   //
70   // Alternatively, we could inspect the state of the heap and the age of the
71   // object at the barrier, but we reject this approach because it is likely
72   // the performance impact would be too severe.
73   void transfer_pointers_from_satb();
74 
75   bool is_concurrent_mark_in_progress() override;
76 };
77 
78 
79 #endif //SHARE_VM_GC_SHENANDOAH_SHENANDOAHOLDGENERATION_HPP