1 /* 2 * Copyright (c) 2001, 2015, Oracle 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_SHARED_GENREMSET_HPP 26 #define SHARE_VM_GC_SHARED_GENREMSET_HPP 27 28 #include "oops/oop.hpp" 29 30 // A GenRemSet provides ways of iterating over pointers across generations. 31 // (This is especially useful for older-to-younger.) 32 33 class Generation; 34 class BarrierSet; 35 class OopsInGenClosure; 36 class CardTableRS; 37 38 // Helper to remember modified oops in all klasses. 39 class KlassRemSet { 40 bool _accumulate_modified_oops; 41 public: 42 KlassRemSet() : _accumulate_modified_oops(false) {} 43 void set_accumulate_modified_oops(bool value) { _accumulate_modified_oops = value; } 44 bool accumulate_modified_oops() { return _accumulate_modified_oops; } 45 bool mod_union_is_clear(); 46 void clear_mod_union(); 47 }; 48 49 class GenRemSet: public CHeapObj<mtGC> { 50 friend class Generation; 51 52 BarrierSet* _bs; 53 KlassRemSet _klass_rem_set; 54 55 public: 56 GenRemSet(BarrierSet * bs) : _bs(bs) {} 57 GenRemSet() : _bs(NULL) {} 58 59 // These are for dynamic downcasts. Unfortunately that it names the 60 // possible subtypes (but not that they are subtypes!) Return NULL if 61 // the cast is invalid. 62 virtual CardTableRS* as_CardTableRS() { return NULL; } 63 64 // Return the barrier set associated with "this." 65 BarrierSet* bs() { return _bs; } 66 67 // Set the barrier set. 68 void set_bs(BarrierSet* bs) { _bs = bs; } 69 70 KlassRemSet* klass_rem_set() { return &_klass_rem_set; } 71 72 // Do any (sequential) processing necessary to prepare for (possibly 73 // "parallel", if that arg is true) calls to younger_refs_iterate. 74 virtual void prepare_for_younger_refs_iterate(bool parallel) = 0; 75 76 // Apply the "do_oop" method of "blk" to (exactly) all oop locations 77 // 1) that are in objects allocated in "g" at the time of the last call 78 // to "save_Marks", and 79 // 2) that point to objects in younger generations. 80 virtual void younger_refs_iterate(Generation* g, OopsInGenClosure* blk, uint n_threads) = 0; 81 82 virtual void younger_refs_in_space_iterate(Space* sp, 83 OopsInGenClosure* cl, 84 uint n_threads) = 0; 85 86 // This method is used to notify the remembered set that "new_val" has 87 // been written into "field" by the garbage collector. 88 void write_ref_field_gc(void* field, oop new_val); 89 protected: 90 virtual void write_ref_field_gc_work(void* field, oop new_val) = 0; 91 public: 92 93 // A version of the above suitable for use by parallel collectors. 94 virtual void write_ref_field_gc_par(void* field, oop new_val) = 0; 95 96 // Resize one of the regions covered by the remembered set. 97 virtual void resize_covered_region(MemRegion new_region) = 0; 98 99 // If the rem set imposes any alignment restrictions on boundaries 100 // within the heap, this function tells whether they are met. 101 virtual bool is_aligned(HeapWord* addr) = 0; 102 103 // Returns any alignment constraint that the remembered set imposes upon the 104 // heap. 105 static uintx max_alignment_constraint(); 106 107 virtual void verify() = 0; 108 109 // If appropriate, print some information about the remset on "tty". 110 virtual void print() {} 111 112 // Informs the RS that the given memregion contains no references to 113 // younger generations. 114 virtual void clear(MemRegion mr) = 0; 115 116 // Informs the RS that there are no references to generations 117 // younger than gen from generations gen and older. 118 // The parameter clear_perm indicates if the perm_gen's 119 // remembered set should also be processed/cleared. 120 virtual void clear_into_younger(Generation* old_gen) = 0; 121 122 // Informs the RS that refs in the given "mr" may have changed 123 // arbitrarily, and therefore may contain old-to-young pointers. 124 // If "whole heap" is true, then this invalidation is part of an 125 // invalidation of the whole heap, which an implementation might 126 // handle differently than that of a sub-part of the heap. 127 virtual void invalidate(MemRegion mr, bool whole_heap = false) = 0; 128 129 // Informs the RS that refs in this generation 130 // may have changed arbitrarily, and therefore may contain 131 // old-to-young pointers in arbitrary locations. 132 virtual void invalidate_or_clear(Generation* old_gen) = 0; 133 }; 134 135 #endif // SHARE_VM_GC_SHARED_GENREMSET_HPP