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* read_byte_map() {
74     return _read_byte_map;
75   }
76 
77   CardValue* write_byte_map() {
78     return _write_byte_map;
79   }
80 
81   CardValue* write_byte_map_base() {
82     return _write_byte_map_base;
83   }
84 
85 private:
86   void initialize(const ReservedSpace& card_table);
87 };
88 
89 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHCARDTABLE_HPP