Wed, 27 Apr 2016 01:25:04 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | * |
aoqi@0 | 23 | */ |
aoqi@0 | 24 | |
aoqi@0 | 25 | #ifndef SHARE_VM_MEMORY_CARDTABLEMODREFBS_HPP |
aoqi@0 | 26 | #define SHARE_VM_MEMORY_CARDTABLEMODREFBS_HPP |
aoqi@0 | 27 | |
aoqi@0 | 28 | #include "memory/modRefBarrierSet.hpp" |
aoqi@0 | 29 | #include "oops/oop.hpp" |
aoqi@0 | 30 | #include "oops/oop.inline2.hpp" |
aoqi@0 | 31 | |
aoqi@0 | 32 | // This kind of "BarrierSet" allows a "CollectedHeap" to detect and |
aoqi@0 | 33 | // enumerate ref fields that have been modified (since the last |
aoqi@0 | 34 | // enumeration.) |
aoqi@0 | 35 | |
aoqi@0 | 36 | // As it currently stands, this barrier is *imprecise*: when a ref field in |
aoqi@0 | 37 | // an object "o" is modified, the card table entry for the card containing |
aoqi@0 | 38 | // the head of "o" is dirtied, not necessarily the card containing the |
aoqi@0 | 39 | // modified field itself. For object arrays, however, the barrier *is* |
aoqi@0 | 40 | // precise; only the card containing the modified element is dirtied. |
aoqi@0 | 41 | // Any MemRegionClosures used to scan dirty cards should take these |
aoqi@0 | 42 | // considerations into account. |
aoqi@0 | 43 | |
aoqi@0 | 44 | class Generation; |
aoqi@0 | 45 | class OopsInGenClosure; |
aoqi@0 | 46 | class DirtyCardToOopClosure; |
aoqi@0 | 47 | class ClearNoncleanCardWrapper; |
aoqi@0 | 48 | |
aoqi@0 | 49 | class CardTableModRefBS: public ModRefBarrierSet { |
aoqi@0 | 50 | // Some classes get to look at some private stuff. |
aoqi@0 | 51 | friend class BytecodeInterpreter; |
aoqi@0 | 52 | friend class VMStructs; |
aoqi@0 | 53 | friend class CardTableRS; |
aoqi@0 | 54 | friend class CheckForUnmarkedOops; // Needs access to raw card bytes. |
aoqi@0 | 55 | friend class SharkBuilder; |
aoqi@0 | 56 | #ifndef PRODUCT |
aoqi@0 | 57 | // For debugging. |
aoqi@0 | 58 | friend class GuaranteeNotModClosure; |
aoqi@0 | 59 | #endif |
aoqi@0 | 60 | protected: |
aoqi@0 | 61 | |
aoqi@0 | 62 | enum CardValues { |
aoqi@0 | 63 | clean_card = -1, |
aoqi@0 | 64 | // The mask contains zeros in places for all other values. |
aoqi@0 | 65 | clean_card_mask = clean_card - 31, |
aoqi@0 | 66 | |
aoqi@0 | 67 | dirty_card = 0, |
aoqi@0 | 68 | precleaned_card = 1, |
aoqi@0 | 69 | claimed_card = 2, |
aoqi@0 | 70 | deferred_card = 4, |
aoqi@0 | 71 | last_card = 8, |
aoqi@0 | 72 | CT_MR_BS_last_reserved = 16 |
aoqi@0 | 73 | }; |
aoqi@0 | 74 | |
aoqi@0 | 75 | // a word's worth (row) of clean card values |
aoqi@0 | 76 | static const intptr_t clean_card_row = (intptr_t)(-1); |
aoqi@0 | 77 | |
aoqi@0 | 78 | // dirty and precleaned are equivalent wrt younger_refs_iter. |
aoqi@0 | 79 | static bool card_is_dirty_wrt_gen_iter(jbyte cv) { |
aoqi@0 | 80 | return cv == dirty_card || cv == precleaned_card; |
aoqi@0 | 81 | } |
aoqi@0 | 82 | |
aoqi@0 | 83 | // Returns "true" iff the value "cv" will cause the card containing it |
aoqi@0 | 84 | // to be scanned in the current traversal. May be overridden by |
aoqi@0 | 85 | // subtypes. |
aoqi@0 | 86 | virtual bool card_will_be_scanned(jbyte cv) { |
aoqi@0 | 87 | return CardTableModRefBS::card_is_dirty_wrt_gen_iter(cv); |
aoqi@0 | 88 | } |
aoqi@0 | 89 | |
aoqi@0 | 90 | // Returns "true" iff the value "cv" may have represented a dirty card at |
aoqi@0 | 91 | // some point. |
aoqi@0 | 92 | virtual bool card_may_have_been_dirty(jbyte cv) { |
aoqi@0 | 93 | return card_is_dirty_wrt_gen_iter(cv); |
aoqi@0 | 94 | } |
aoqi@0 | 95 | |
aoqi@0 | 96 | // The declaration order of these const fields is important; see the |
aoqi@0 | 97 | // constructor before changing. |
aoqi@0 | 98 | const MemRegion _whole_heap; // the region covered by the card table |
aoqi@0 | 99 | const size_t _guard_index; // index of very last element in the card |
aoqi@0 | 100 | // table; it is set to a guard value |
aoqi@0 | 101 | // (last_card) and should never be modified |
aoqi@0 | 102 | const size_t _last_valid_index; // index of the last valid element |
aoqi@0 | 103 | const size_t _page_size; // page size used when mapping _byte_map |
aoqi@0 | 104 | const size_t _byte_map_size; // in bytes |
aoqi@0 | 105 | jbyte* _byte_map; // the card marking array |
aoqi@0 | 106 | |
aoqi@0 | 107 | int _cur_covered_regions; |
aoqi@0 | 108 | // The covered regions should be in address order. |
aoqi@0 | 109 | MemRegion* _covered; |
aoqi@0 | 110 | // The committed regions correspond one-to-one to the covered regions. |
aoqi@0 | 111 | // They represent the card-table memory that has been committed to service |
aoqi@0 | 112 | // the corresponding covered region. It may be that committed region for |
aoqi@0 | 113 | // one covered region corresponds to a larger region because of page-size |
aoqi@0 | 114 | // roundings. Thus, a committed region for one covered region may |
aoqi@0 | 115 | // actually extend onto the card-table space for the next covered region. |
aoqi@0 | 116 | MemRegion* _committed; |
aoqi@0 | 117 | |
aoqi@0 | 118 | // The last card is a guard card, and we commit the page for it so |
aoqi@0 | 119 | // we can use the card for verification purposes. We make sure we never |
aoqi@0 | 120 | // uncommit the MemRegion for that page. |
aoqi@0 | 121 | MemRegion _guard_region; |
aoqi@0 | 122 | |
aoqi@0 | 123 | protected: |
aoqi@0 | 124 | // Initialization utilities; covered_words is the size of the covered region |
aoqi@0 | 125 | // in, um, words. |
aoqi@0 | 126 | inline size_t cards_required(size_t covered_words); |
aoqi@0 | 127 | inline size_t compute_byte_map_size(); |
aoqi@0 | 128 | |
aoqi@0 | 129 | // Finds and return the index of the region, if any, to which the given |
aoqi@0 | 130 | // region would be contiguous. If none exists, assign a new region and |
aoqi@0 | 131 | // returns its index. Requires that no more than the maximum number of |
aoqi@0 | 132 | // covered regions defined in the constructor are ever in use. |
aoqi@0 | 133 | int find_covering_region_by_base(HeapWord* base); |
aoqi@0 | 134 | |
aoqi@0 | 135 | // Same as above, but finds the region containing the given address |
aoqi@0 | 136 | // instead of starting at a given base address. |
aoqi@0 | 137 | int find_covering_region_containing(HeapWord* addr); |
aoqi@0 | 138 | |
aoqi@0 | 139 | // Resize one of the regions covered by the remembered set. |
aoqi@0 | 140 | void resize_covered_region(MemRegion new_region); |
aoqi@0 | 141 | |
aoqi@0 | 142 | // Returns the leftmost end of a committed region corresponding to a |
aoqi@0 | 143 | // covered region before covered region "ind", or else "NULL" if "ind" is |
aoqi@0 | 144 | // the first covered region. |
aoqi@0 | 145 | HeapWord* largest_prev_committed_end(int ind) const; |
aoqi@0 | 146 | |
aoqi@0 | 147 | // Returns the part of the region mr that doesn't intersect with |
aoqi@0 | 148 | // any committed region other than self. Used to prevent uncommitting |
aoqi@0 | 149 | // regions that are also committed by other regions. Also protects |
aoqi@0 | 150 | // against uncommitting the guard region. |
aoqi@0 | 151 | MemRegion committed_unique_to_self(int self, MemRegion mr) const; |
aoqi@0 | 152 | |
aoqi@0 | 153 | // Mapping from address to card marking array entry |
aoqi@0 | 154 | jbyte* byte_for(const void* p) const { |
aoqi@0 | 155 | assert(_whole_heap.contains(p), |
aoqi@0 | 156 | err_msg("Attempt to access p = "PTR_FORMAT" out of bounds of " |
aoqi@0 | 157 | " card marking array's _whole_heap = ["PTR_FORMAT","PTR_FORMAT")", |
aoqi@0 | 158 | p2i(p), p2i(_whole_heap.start()), p2i(_whole_heap.end()))); |
aoqi@0 | 159 | jbyte* result = &byte_map_base[uintptr_t(p) >> card_shift]; |
aoqi@0 | 160 | assert(result >= _byte_map && result < _byte_map + _byte_map_size, |
aoqi@0 | 161 | "out of bounds accessor for card marking array"); |
aoqi@0 | 162 | return result; |
aoqi@0 | 163 | } |
aoqi@0 | 164 | |
aoqi@0 | 165 | // The card table byte one after the card marking array |
aoqi@0 | 166 | // entry for argument address. Typically used for higher bounds |
aoqi@0 | 167 | // for loops iterating through the card table. |
aoqi@0 | 168 | jbyte* byte_after(const void* p) const { |
aoqi@0 | 169 | return byte_for(p) + 1; |
aoqi@0 | 170 | } |
aoqi@0 | 171 | |
aoqi@0 | 172 | // Iterate over the portion of the card-table which covers the given |
aoqi@0 | 173 | // region mr in the given space and apply cl to any dirty sub-regions |
aoqi@0 | 174 | // of mr. Dirty cards are _not_ cleared by the iterator method itself, |
aoqi@0 | 175 | // but closures may arrange to do so on their own should they so wish. |
aoqi@0 | 176 | void non_clean_card_iterate_serial(MemRegion mr, MemRegionClosure* cl); |
aoqi@0 | 177 | |
aoqi@0 | 178 | // A variant of the above that will operate in a parallel mode if |
aoqi@0 | 179 | // worker threads are available, and clear the dirty cards as it |
aoqi@0 | 180 | // processes them. |
aoqi@0 | 181 | // XXX ??? MemRegionClosure above vs OopsInGenClosure below XXX |
aoqi@0 | 182 | // XXX some new_dcto_cl's take OopClosure's, plus as above there are |
aoqi@0 | 183 | // some MemRegionClosures. Clean this up everywhere. XXX |
aoqi@0 | 184 | void non_clean_card_iterate_possibly_parallel(Space* sp, MemRegion mr, |
aoqi@0 | 185 | OopsInGenClosure* cl, CardTableRS* ct); |
aoqi@0 | 186 | |
aoqi@0 | 187 | private: |
aoqi@0 | 188 | // Work method used to implement non_clean_card_iterate_possibly_parallel() |
aoqi@0 | 189 | // above in the parallel case. |
aoqi@0 | 190 | void non_clean_card_iterate_parallel_work(Space* sp, MemRegion mr, |
aoqi@0 | 191 | OopsInGenClosure* cl, CardTableRS* ct, |
aoqi@0 | 192 | int n_threads); |
aoqi@0 | 193 | |
aoqi@0 | 194 | protected: |
aoqi@0 | 195 | // Dirty the bytes corresponding to "mr" (not all of which must be |
aoqi@0 | 196 | // covered.) |
aoqi@0 | 197 | void dirty_MemRegion(MemRegion mr); |
aoqi@0 | 198 | |
aoqi@0 | 199 | // Clear (to clean_card) the bytes entirely contained within "mr" (not |
aoqi@0 | 200 | // all of which must be covered.) |
aoqi@0 | 201 | void clear_MemRegion(MemRegion mr); |
aoqi@0 | 202 | |
aoqi@0 | 203 | // *** Support for parallel card scanning. |
aoqi@0 | 204 | |
aoqi@0 | 205 | // This is an array, one element per covered region of the card table. |
aoqi@0 | 206 | // Each entry is itself an array, with one element per chunk in the |
aoqi@0 | 207 | // covered region. Each entry of these arrays is the lowest non-clean |
aoqi@0 | 208 | // card of the corresponding chunk containing part of an object from the |
aoqi@0 | 209 | // previous chunk, or else NULL. |
aoqi@0 | 210 | typedef jbyte* CardPtr; |
aoqi@0 | 211 | typedef CardPtr* CardArr; |
aoqi@0 | 212 | CardArr* _lowest_non_clean; |
aoqi@0 | 213 | size_t* _lowest_non_clean_chunk_size; |
aoqi@0 | 214 | uintptr_t* _lowest_non_clean_base_chunk_index; |
aoqi@0 | 215 | int* _last_LNC_resizing_collection; |
aoqi@0 | 216 | |
aoqi@0 | 217 | // Initializes "lowest_non_clean" to point to the array for the region |
aoqi@0 | 218 | // covering "sp", and "lowest_non_clean_base_chunk_index" to the chunk |
aoqi@0 | 219 | // index of the corresponding to the first element of that array. |
aoqi@0 | 220 | // Ensures that these arrays are of sufficient size, allocating if necessary. |
aoqi@0 | 221 | // May be called by several threads concurrently. |
aoqi@0 | 222 | void get_LNC_array_for_space(Space* sp, |
aoqi@0 | 223 | jbyte**& lowest_non_clean, |
aoqi@0 | 224 | uintptr_t& lowest_non_clean_base_chunk_index, |
aoqi@0 | 225 | size_t& lowest_non_clean_chunk_size); |
aoqi@0 | 226 | |
aoqi@0 | 227 | // Returns the number of chunks necessary to cover "mr". |
aoqi@0 | 228 | size_t chunks_to_cover(MemRegion mr) { |
aoqi@0 | 229 | return (size_t)(addr_to_chunk_index(mr.last()) - |
aoqi@0 | 230 | addr_to_chunk_index(mr.start()) + 1); |
aoqi@0 | 231 | } |
aoqi@0 | 232 | |
aoqi@0 | 233 | // Returns the index of the chunk in a stride which |
aoqi@0 | 234 | // covers the given address. |
aoqi@0 | 235 | uintptr_t addr_to_chunk_index(const void* addr) { |
aoqi@0 | 236 | uintptr_t card = (uintptr_t) byte_for(addr); |
aoqi@0 | 237 | return card / ParGCCardsPerStrideChunk; |
aoqi@0 | 238 | } |
aoqi@0 | 239 | |
aoqi@0 | 240 | // Apply cl, which must either itself apply dcto_cl or be dcto_cl, |
aoqi@0 | 241 | // to the cards in the stride (of n_strides) within the given space. |
aoqi@0 | 242 | void process_stride(Space* sp, |
aoqi@0 | 243 | MemRegion used, |
aoqi@0 | 244 | jint stride, int n_strides, |
aoqi@0 | 245 | OopsInGenClosure* cl, |
aoqi@0 | 246 | CardTableRS* ct, |
aoqi@0 | 247 | jbyte** lowest_non_clean, |
aoqi@0 | 248 | uintptr_t lowest_non_clean_base_chunk_index, |
aoqi@0 | 249 | size_t lowest_non_clean_chunk_size); |
aoqi@0 | 250 | |
aoqi@0 | 251 | // Makes sure that chunk boundaries are handled appropriately, by |
aoqi@0 | 252 | // adjusting the min_done of dcto_cl, and by using a special card-table |
aoqi@0 | 253 | // value to indicate how min_done should be set. |
aoqi@0 | 254 | void process_chunk_boundaries(Space* sp, |
aoqi@0 | 255 | DirtyCardToOopClosure* dcto_cl, |
aoqi@0 | 256 | MemRegion chunk_mr, |
aoqi@0 | 257 | MemRegion used, |
aoqi@0 | 258 | jbyte** lowest_non_clean, |
aoqi@0 | 259 | uintptr_t lowest_non_clean_base_chunk_index, |
aoqi@0 | 260 | size_t lowest_non_clean_chunk_size); |
aoqi@0 | 261 | |
aoqi@0 | 262 | public: |
aoqi@0 | 263 | // Constants |
aoqi@0 | 264 | enum SomePublicConstants { |
aoqi@0 | 265 | card_shift = 9, |
aoqi@0 | 266 | card_size = 1 << card_shift, |
aoqi@0 | 267 | card_size_in_words = card_size / sizeof(HeapWord) |
aoqi@0 | 268 | }; |
aoqi@0 | 269 | |
aoqi@0 | 270 | static int clean_card_val() { return clean_card; } |
aoqi@0 | 271 | static int clean_card_mask_val() { return clean_card_mask; } |
aoqi@0 | 272 | static int dirty_card_val() { return dirty_card; } |
aoqi@0 | 273 | static int claimed_card_val() { return claimed_card; } |
aoqi@0 | 274 | static int precleaned_card_val() { return precleaned_card; } |
aoqi@0 | 275 | static int deferred_card_val() { return deferred_card; } |
aoqi@0 | 276 | |
aoqi@0 | 277 | // For RTTI simulation. |
aoqi@0 | 278 | bool is_a(BarrierSet::Name bsn) { |
aoqi@0 | 279 | return bsn == BarrierSet::CardTableModRef || ModRefBarrierSet::is_a(bsn); |
aoqi@0 | 280 | } |
aoqi@0 | 281 | |
aoqi@0 | 282 | CardTableModRefBS(MemRegion whole_heap, int max_covered_regions); |
aoqi@0 | 283 | ~CardTableModRefBS(); |
aoqi@0 | 284 | |
aoqi@0 | 285 | // *** Barrier set functions. |
aoqi@0 | 286 | |
aoqi@0 | 287 | bool has_write_ref_pre_barrier() { return false; } |
aoqi@0 | 288 | |
aoqi@0 | 289 | // Record a reference update. Note that these versions are precise! |
aoqi@0 | 290 | // The scanning code has to handle the fact that the write barrier may be |
aoqi@0 | 291 | // either precise or imprecise. We make non-virtual inline variants of |
aoqi@0 | 292 | // these functions here for performance. |
aoqi@0 | 293 | protected: |
aoqi@0 | 294 | void write_ref_field_work(oop obj, size_t offset, oop newVal); |
aoqi@0 | 295 | virtual void write_ref_field_work(void* field, oop newVal, bool release = false); |
aoqi@0 | 296 | public: |
aoqi@0 | 297 | |
aoqi@0 | 298 | bool has_write_ref_array_opt() { return true; } |
aoqi@0 | 299 | bool has_write_region_opt() { return true; } |
aoqi@0 | 300 | |
aoqi@0 | 301 | inline void inline_write_region(MemRegion mr) { |
aoqi@0 | 302 | dirty_MemRegion(mr); |
aoqi@0 | 303 | } |
aoqi@0 | 304 | protected: |
aoqi@0 | 305 | void write_region_work(MemRegion mr) { |
aoqi@0 | 306 | inline_write_region(mr); |
aoqi@0 | 307 | } |
aoqi@0 | 308 | public: |
aoqi@0 | 309 | |
aoqi@0 | 310 | inline void inline_write_ref_array(MemRegion mr) { |
aoqi@0 | 311 | dirty_MemRegion(mr); |
aoqi@0 | 312 | } |
aoqi@0 | 313 | protected: |
aoqi@0 | 314 | void write_ref_array_work(MemRegion mr) { |
aoqi@0 | 315 | inline_write_ref_array(mr); |
aoqi@0 | 316 | } |
aoqi@0 | 317 | public: |
aoqi@0 | 318 | |
aoqi@0 | 319 | bool is_aligned(HeapWord* addr) { |
aoqi@0 | 320 | return is_card_aligned(addr); |
aoqi@0 | 321 | } |
aoqi@0 | 322 | |
aoqi@0 | 323 | // *** Card-table-barrier-specific things. |
aoqi@0 | 324 | |
aoqi@0 | 325 | template <class T> inline void inline_write_ref_field_pre(T* field, oop newVal) {} |
aoqi@0 | 326 | |
aoqi@0 | 327 | template <class T> inline void inline_write_ref_field(T* field, oop newVal, bool release) { |
aoqi@0 | 328 | jbyte* byte = byte_for((void*)field); |
aoqi@0 | 329 | if (release) { |
aoqi@0 | 330 | // Perform a releasing store if requested. |
aoqi@0 | 331 | OrderAccess::release_store((volatile jbyte*) byte, dirty_card); |
aoqi@0 | 332 | } else { |
aoqi@0 | 333 | *byte = dirty_card; |
aoqi@0 | 334 | } |
aoqi@0 | 335 | } |
aoqi@0 | 336 | |
aoqi@0 | 337 | // These are used by G1, when it uses the card table as a temporary data |
aoqi@0 | 338 | // structure for card claiming. |
aoqi@0 | 339 | bool is_card_dirty(size_t card_index) { |
aoqi@0 | 340 | return _byte_map[card_index] == dirty_card_val(); |
aoqi@0 | 341 | } |
aoqi@0 | 342 | |
aoqi@0 | 343 | void mark_card_dirty(size_t card_index) { |
aoqi@0 | 344 | _byte_map[card_index] = dirty_card_val(); |
aoqi@0 | 345 | } |
aoqi@0 | 346 | |
aoqi@0 | 347 | bool is_card_clean(size_t card_index) { |
aoqi@0 | 348 | return _byte_map[card_index] == clean_card_val(); |
aoqi@0 | 349 | } |
aoqi@0 | 350 | |
aoqi@0 | 351 | // Card marking array base (adjusted for heap low boundary) |
aoqi@0 | 352 | // This would be the 0th element of _byte_map, if the heap started at 0x0. |
aoqi@0 | 353 | // But since the heap starts at some higher address, this points to somewhere |
aoqi@0 | 354 | // before the beginning of the actual _byte_map. |
aoqi@0 | 355 | jbyte* byte_map_base; |
aoqi@0 | 356 | |
aoqi@0 | 357 | // Return true if "p" is at the start of a card. |
aoqi@0 | 358 | bool is_card_aligned(HeapWord* p) { |
aoqi@0 | 359 | jbyte* pcard = byte_for(p); |
aoqi@0 | 360 | return (addr_for(pcard) == p); |
aoqi@0 | 361 | } |
aoqi@0 | 362 | |
aoqi@0 | 363 | HeapWord* align_to_card_boundary(HeapWord* p) { |
aoqi@0 | 364 | jbyte* pcard = byte_for(p + card_size_in_words - 1); |
aoqi@0 | 365 | return addr_for(pcard); |
aoqi@0 | 366 | } |
aoqi@0 | 367 | |
aoqi@0 | 368 | // The kinds of precision a CardTableModRefBS may offer. |
aoqi@0 | 369 | enum PrecisionStyle { |
aoqi@0 | 370 | Precise, |
aoqi@0 | 371 | ObjHeadPreciseArray |
aoqi@0 | 372 | }; |
aoqi@0 | 373 | |
aoqi@0 | 374 | // Tells what style of precision this card table offers. |
aoqi@0 | 375 | PrecisionStyle precision() { |
aoqi@0 | 376 | return ObjHeadPreciseArray; // Only one supported for now. |
aoqi@0 | 377 | } |
aoqi@0 | 378 | |
aoqi@0 | 379 | // ModRefBS functions. |
aoqi@0 | 380 | virtual void invalidate(MemRegion mr, bool whole_heap = false); |
aoqi@0 | 381 | void clear(MemRegion mr); |
aoqi@0 | 382 | void dirty(MemRegion mr); |
aoqi@0 | 383 | |
aoqi@0 | 384 | // *** Card-table-RemSet-specific things. |
aoqi@0 | 385 | |
aoqi@0 | 386 | // Invoke "cl.do_MemRegion" on a set of MemRegions that collectively |
aoqi@0 | 387 | // includes all the modified cards (expressing each card as a |
aoqi@0 | 388 | // MemRegion). Thus, several modified cards may be lumped into one |
aoqi@0 | 389 | // region. The regions are non-overlapping, and are visited in |
aoqi@0 | 390 | // *decreasing* address order. (This order aids with imprecise card |
aoqi@0 | 391 | // marking, where a dirty card may cause scanning, and summarization |
aoqi@0 | 392 | // marking, of objects that extend onto subsequent cards.) |
aoqi@0 | 393 | void mod_card_iterate(MemRegionClosure* cl) { |
aoqi@0 | 394 | non_clean_card_iterate_serial(_whole_heap, cl); |
aoqi@0 | 395 | } |
aoqi@0 | 396 | |
aoqi@0 | 397 | // Like the "mod_cards_iterate" above, except only invokes the closure |
aoqi@0 | 398 | // for cards within the MemRegion "mr" (which is required to be |
aoqi@0 | 399 | // card-aligned and sized.) |
aoqi@0 | 400 | void mod_card_iterate(MemRegion mr, MemRegionClosure* cl) { |
aoqi@0 | 401 | non_clean_card_iterate_serial(mr, cl); |
aoqi@0 | 402 | } |
aoqi@0 | 403 | |
aoqi@0 | 404 | static uintx ct_max_alignment_constraint(); |
aoqi@0 | 405 | |
aoqi@0 | 406 | // Apply closure "cl" to the dirty cards containing some part of |
aoqi@0 | 407 | // MemRegion "mr". |
aoqi@0 | 408 | void dirty_card_iterate(MemRegion mr, MemRegionClosure* cl); |
aoqi@0 | 409 | |
aoqi@0 | 410 | // Return the MemRegion corresponding to the first maximal run |
aoqi@0 | 411 | // of dirty cards lying completely within MemRegion mr. |
aoqi@0 | 412 | // If reset is "true", then sets those card table entries to the given |
aoqi@0 | 413 | // value. |
aoqi@0 | 414 | MemRegion dirty_card_range_after_reset(MemRegion mr, bool reset, |
aoqi@0 | 415 | int reset_val); |
aoqi@0 | 416 | |
aoqi@0 | 417 | // Provide read-only access to the card table array. |
aoqi@0 | 418 | const jbyte* byte_for_const(const void* p) const { |
aoqi@0 | 419 | return byte_for(p); |
aoqi@0 | 420 | } |
aoqi@0 | 421 | const jbyte* byte_after_const(const void* p) const { |
aoqi@0 | 422 | return byte_after(p); |
aoqi@0 | 423 | } |
aoqi@0 | 424 | |
aoqi@0 | 425 | // Mapping from card marking array entry to address of first word |
aoqi@0 | 426 | HeapWord* addr_for(const jbyte* p) const { |
aoqi@0 | 427 | assert(p >= _byte_map && p < _byte_map + _byte_map_size, |
aoqi@0 | 428 | "out of bounds access to card marking array"); |
aoqi@0 | 429 | size_t delta = pointer_delta(p, byte_map_base, sizeof(jbyte)); |
aoqi@0 | 430 | HeapWord* result = (HeapWord*) (delta << card_shift); |
aoqi@0 | 431 | assert(_whole_heap.contains(result), |
aoqi@0 | 432 | err_msg("Returning result = "PTR_FORMAT" out of bounds of " |
aoqi@0 | 433 | " card marking array's _whole_heap = ["PTR_FORMAT","PTR_FORMAT")", |
aoqi@0 | 434 | p2i(result), p2i(_whole_heap.start()), p2i(_whole_heap.end()))); |
aoqi@0 | 435 | return result; |
aoqi@0 | 436 | } |
aoqi@0 | 437 | |
aoqi@0 | 438 | // Mapping from address to card marking array index. |
aoqi@0 | 439 | size_t index_for(void* p) { |
aoqi@0 | 440 | assert(_whole_heap.contains(p), |
aoqi@0 | 441 | err_msg("Attempt to access p = "PTR_FORMAT" out of bounds of " |
aoqi@0 | 442 | " card marking array's _whole_heap = ["PTR_FORMAT","PTR_FORMAT")", |
aoqi@0 | 443 | p2i(p), p2i(_whole_heap.start()), p2i(_whole_heap.end()))); |
aoqi@0 | 444 | return byte_for(p) - _byte_map; |
aoqi@0 | 445 | } |
aoqi@0 | 446 | |
aoqi@0 | 447 | const jbyte* byte_for_index(const size_t card_index) const { |
aoqi@0 | 448 | return _byte_map + card_index; |
aoqi@0 | 449 | } |
aoqi@0 | 450 | |
aoqi@0 | 451 | // Print a description of the memory for the barrier set |
aoqi@0 | 452 | virtual void print_on(outputStream* st) const; |
aoqi@0 | 453 | |
aoqi@0 | 454 | void verify(); |
aoqi@0 | 455 | void verify_guard(); |
aoqi@0 | 456 | |
aoqi@0 | 457 | // val_equals -> it will check that all cards covered by mr equal val |
aoqi@0 | 458 | // !val_equals -> it will check that all cards covered by mr do not equal val |
aoqi@0 | 459 | void verify_region(MemRegion mr, jbyte val, bool val_equals) PRODUCT_RETURN; |
aoqi@0 | 460 | void verify_not_dirty_region(MemRegion mr) PRODUCT_RETURN; |
aoqi@0 | 461 | void verify_dirty_region(MemRegion mr) PRODUCT_RETURN; |
aoqi@0 | 462 | |
aoqi@0 | 463 | static size_t par_chunk_heapword_alignment() { |
aoqi@0 | 464 | return ParGCCardsPerStrideChunk * card_size_in_words; |
aoqi@0 | 465 | } |
aoqi@0 | 466 | |
aoqi@0 | 467 | }; |
aoqi@0 | 468 | |
aoqi@0 | 469 | class CardTableRS; |
aoqi@0 | 470 | |
aoqi@0 | 471 | // A specialization for the CardTableRS gen rem set. |
aoqi@0 | 472 | class CardTableModRefBSForCTRS: public CardTableModRefBS { |
aoqi@0 | 473 | CardTableRS* _rs; |
aoqi@0 | 474 | protected: |
aoqi@0 | 475 | bool card_will_be_scanned(jbyte cv); |
aoqi@0 | 476 | bool card_may_have_been_dirty(jbyte cv); |
aoqi@0 | 477 | public: |
aoqi@0 | 478 | CardTableModRefBSForCTRS(MemRegion whole_heap, |
aoqi@0 | 479 | int max_covered_regions) : |
aoqi@0 | 480 | CardTableModRefBS(whole_heap, max_covered_regions) {} |
aoqi@0 | 481 | |
aoqi@0 | 482 | void set_CTRS(CardTableRS* rs) { _rs = rs; } |
aoqi@0 | 483 | }; |
aoqi@0 | 484 | |
aoqi@0 | 485 | |
aoqi@0 | 486 | #endif // SHARE_VM_MEMORY_CARDTABLEMODREFBS_HPP |