1 /*
 2  * Copyright (c) 2020, 2021, Amazon.com, Inc. and/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_SHENANDOAHCARDTABLE_HPP
26 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHCARDTABLE_HPP
27 
28 #include "gc/g1/g1RegionToSpaceMapper.hpp"
29 #include "gc/shared/cardTable.hpp"
30 #include "oops/oopsHierarchy.hpp"
31 #include "utilities/macros.hpp"
32 
33 class ShenandoahCardTable: public CardTable {
34   friend class VMStructs;
35 
36 protected:
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   ShenandoahCardTable(MemRegion whole_heap) : CardTable(whole_heap) { }
60 
61   virtual void initialize();
62 
63   virtual bool is_in_young(oop obj) const;
64 
65   bool is_dirty(MemRegion mr);
66 
67   void clear();
68 
69   void clear_read_table();
70 
71   // Exchange the roles of the read and write card tables.
72   void swap_card_tables();
73 
74   CardValue* read_byte_map() {
75     return _read_byte_map;
76   }
77 
78   CardValue* write_byte_map() {
79     return _write_byte_map;
80   }
81 
82   CardValue* read_byte_map_base() {
83     return _read_byte_map_base;
84   }
85 
86   CardValue* write_byte_map_base() {
87     return _write_byte_map_base;
88   }
89 };
90 
91 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHCARDTABLE_HPP