1 /*
2 * Copyright (c) 2016, 2020, Red Hat, Inc. 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 *
26 #define SHARE_GC_SHENANDOAH_SHENANDOAHCOLLECTIONSET_HPP
27
28 #include "memory/allocation.hpp"
29 #include "memory/virtualspace.hpp"
30 #include "gc/shenandoah/shenandoahHeap.hpp"
31 #include "gc/shenandoah/shenandoahHeapRegion.hpp"
32 #include "gc/shenandoah/shenandoahPadding.hpp"
33
34 class ShenandoahCollectionSet : public CHeapObj<mtGC> {
35 friend class ShenandoahHeap;
36 private:
37 size_t const _map_size;
38 size_t const _region_size_bytes_shift;
39 ReservedSpace _map_space;
40 char* const _cset_map;
41 // Bias cset map's base address for fast test if an oop is in cset
42 char* const _biased_cset_map;
43
44 ShenandoahHeap* const _heap;
45
46 size_t _garbage;
47 size_t _used;
48 size_t _region_count;
49
50 shenandoah_padding(0);
51 volatile size_t _current_index;
52 shenandoah_padding(1);
53
54 public:
55 ShenandoahCollectionSet(ShenandoahHeap* heap, ReservedSpace space, char* heap_base);
56
57 // Add region to collection set
58 void add_region(ShenandoahHeapRegion* r);
59
60 // MT version
61 ShenandoahHeapRegion* claim_next();
62
63 // Single-thread version
64 ShenandoahHeapRegion* next();
65
66 size_t count() const { return _region_count; }
67 bool is_empty() const { return _region_count == 0; }
68
69 void clear_current_index() {
70 _current_index = 0;
71 }
72
73 inline bool is_in(ShenandoahHeapRegion* r) const;
74 inline bool is_in(size_t region_idx) const;
75 inline bool is_in(oop obj) const;
76 inline bool is_in_loc(void* loc) const;
77
78 void print_on(outputStream* out) const;
79
80 size_t used() const { return _used; }
81 size_t garbage() const { return _garbage; }
82 void clear();
83
84 private:
85 char* map_address() const {
86 return _cset_map;
87 }
88 char* biased_map_address() const {
89 return _biased_cset_map;
90 }
91 };
92
93 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHCOLLECTIONSET_HPP
|
1 /*
2 * Copyright (c) 2016, 2020, 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 *
27 #define SHARE_GC_SHENANDOAH_SHENANDOAHCOLLECTIONSET_HPP
28
29 #include "memory/allocation.hpp"
30 #include "memory/virtualspace.hpp"
31 #include "gc/shenandoah/shenandoahHeap.hpp"
32 #include "gc/shenandoah/shenandoahHeapRegion.hpp"
33 #include "gc/shenandoah/shenandoahPadding.hpp"
34
35 class ShenandoahCollectionSet : public CHeapObj<mtGC> {
36 friend class ShenandoahHeap;
37 private:
38 size_t const _map_size;
39 size_t const _region_size_bytes_shift;
40 ReservedSpace _map_space;
41 char* const _cset_map;
42 // Bias cset map's base address for fast test if an oop is in cset
43 char* const _biased_cset_map;
44
45 ShenandoahHeap* const _heap;
46
47 bool _has_old_regions;
48 size_t _garbage;
49 size_t _used;
50 size_t _live;
51 size_t _region_count;
52 size_t _immediate_trash;
53
54 size_t _young_bytes_to_evacuate;
55 size_t _young_bytes_to_promote;
56 size_t _old_bytes_to_evacuate;
57
58 size_t _young_region_count;
59 size_t _old_region_count;
60
61 // How many bytes of old garbage are present in a mixed collection set?
62 size_t _old_garbage;
63
64 // Points to array identifying which tenure-age regions have been preselected
65 // for inclusion in collection set. This field is only valid during brief
66 // spans of time while collection set is being constructed.
67 bool* _preselected_regions;
68
69 // When a region having memory available to be allocated is added to the collection set, the region's available memory
70 // should be subtracted from what's available.
71 size_t _young_available_bytes_collected;
72 size_t _old_available_bytes_collected;
73
74 shenandoah_padding(0);
75 volatile size_t _current_index;
76 shenandoah_padding(1);
77
78 public:
79 ShenandoahCollectionSet(ShenandoahHeap* heap, ReservedSpace space, char* heap_base);
80
81 // Add region to collection set
82 void add_region(ShenandoahHeapRegion* r);
83
84 // MT version
85 ShenandoahHeapRegion* claim_next();
86
87 // Single-thread version
88 ShenandoahHeapRegion* next();
89
90 size_t count() const { return _region_count; }
91 bool is_empty() const { return _region_count == 0; }
92
93 void clear_current_index() {
94 _current_index = 0;
95 }
96
97 inline bool is_in(ShenandoahHeapRegion* r) const;
98 inline bool is_in(size_t region_idx) const;
99 inline bool is_in(oop obj) const;
100 inline bool is_in_loc(void* loc) const;
101
102 void print_on(outputStream* out) const;
103
104 inline size_t get_immediate_trash();
105 inline void set_immediate_trash(size_t immediate_trash);
106
107 // This represents total amount of work to be performed by evacuation, including evacuations to young, to old,
108 // and promotions from young to old. This equals get_young_bytes_reserved_for_evacuation() plus
109 // get_old_bytes_reserved_for_evacuation().
110 // TODO: Seems unused.
111 inline size_t get_bytes_reserved_for_evacuation();
112
113 // It is not known how many of these bytes will be promoted.
114 inline size_t get_young_bytes_reserved_for_evacuation();
115 inline size_t get_old_bytes_reserved_for_evacuation();
116
117 inline size_t get_young_bytes_to_be_promoted();
118
119 size_t get_young_available_bytes_collected() { return _young_available_bytes_collected; }
120
121 size_t get_old_available_bytes_collected() { return _old_available_bytes_collected; }
122
123 inline size_t get_old_region_count();
124 inline size_t get_young_region_count();
125
126 inline size_t get_old_garbage();
127
128 void establish_preselected(bool *preselected) { _preselected_regions = preselected; }
129 void abandon_preselected() { _preselected_regions = nullptr; }
130 bool is_preselected(size_t region_idx) { return (_preselected_regions != nullptr) && _preselected_regions[region_idx]; }
131
132 bool has_old_regions() const { return _has_old_regions; }
133 size_t used() const { return _used; }
134 size_t live() const { return _live; }
135 size_t garbage() const { return _garbage; }
136
137 void clear();
138
139 private:
140 char* map_address() const {
141 return _cset_map;
142 }
143 char* biased_map_address() const {
144 return _biased_cset_map;
145 }
146 };
147
148 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHCOLLECTIONSET_HPP
|