1 /*
2 * Copyright 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_GC_SHENANDOAH_SHENANDOAHCARDTABLE_HPP
26 #define SHARE_GC_SHENANDOAH_SHENANDOAHCARDTABLE_HPP
27
28 #include "gc/shared/cardTable.hpp"
29 #include "memory/virtualspace.hpp"
30 #include "oops/oopsHierarchy.hpp"
31 #include "utilities/macros.hpp"
32
33 #define ShenandoahMinCardSizeInBytes 128
34
35 class ShenandoahCardTable: public CardTable {
36 friend class VMStructs;
37
38 private:
39 // We maintain two copies of the card table to facilitate concurrent remembered set scanning
40 // and concurrent clearing of stale remembered set information. During the init_mark safepoint,
41 // we copy the contents of _write_byte_map to _read_byte_map and clear _write_byte_map.
42 //
43 // Concurrent remembered set scanning reads from _read_byte_map while concurrent mutator write
44 // barriers are overwriting cards of the _write_byte_map with DIRTY codes. Concurrent remembered
45 // set scanning also overwrites cards of the _write_byte_map with DIRTY codes whenever it discovers
46 // interesting pointers.
47 //
48 // During a concurrent update-references phase, we scan the _write_byte_map concurrently to find
49 // all old-gen references that may need to be updated.
50 //
51 // In a future implementation, we may swap the values of _read_byte_map and _write_byte_map during
52 // the init-mark safepoint to avoid the need for bulk STW copying and initialization. Doing so
53 // requires a change to the implementation of mutator write barriers as the address of the card
54 // table is currently in-lined and hard-coded.
55 CardValue* _read_byte_map;
56 CardValue* _write_byte_map;
57 CardValue* _read_byte_map_base;
58 CardValue* _write_byte_map_base;
59
60 public:
61 explicit ShenandoahCardTable(MemRegion whole_heap) : CardTable(whole_heap),
62 _read_byte_map(nullptr), _write_byte_map(nullptr),
63 _read_byte_map_base(nullptr), _write_byte_map_base(nullptr) {}
64
65 void initialize();
66
67 bool is_in_young(const void* obj) const override;
68
69 CardValue* read_byte_for(const void* p);
70
71 size_t last_valid_index();
72
73 CardValue* swap_read_and_write_tables() {
74 swap(_read_byte_map, _write_byte_map);
75 swap(_read_byte_map_base, _write_byte_map_base);
76
77 _byte_map = _write_byte_map;
78 _byte_map_base = _write_byte_map_base;
79
80 return _byte_map_base;
81 }
82
83 CardValue* read_byte_map() {
84 return _read_byte_map;
85 }
86
87 CardValue* read_byte_map_base() {
88 return _read_byte_map_base;
89 }
90
91 CardValue* write_byte_map() {
92 return _write_byte_map;
93 }
94
95 CardValue* write_byte_map_base() {
96 return _write_byte_map_base;
97 }
98
99 private:
100 void initialize(const ReservedSpace& card_table);
101 };
102
103 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHCARDTABLE_HPP