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