3610N/A * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A // Parallel or sequential, we must always set the prev to equal the 0N/A // last one written. 0N/A // Find a parallel value to be used next. 0N/A // In an sequential traversal we will always write youngergen, so that 0N/A // the inline barrier is correct. 2384N/A // In the parallel case, we may have to do this several times. 2384N/A "We shouldn't be looking at clean cards, and this should " 2384N/A "be the only place they get cleaned.");
2384N/A "The CAS above should only fail if another thread did " 2384N/A // Parallelism shouldn't matter in this case. Only the thread 2384N/A // assigned to scan the card should change this value. 2384N/A "Should be the only possibility.");
2384N/A // In this case, the card was clean before, and become 2384N/A // cur_youngergen only because of processing of a promoted object. 2384N/A // We don't have to look at the card. 2384N/A "We shouldn't be looking at clean cards, and this should " 2384N/A "be the only place they get cleaned.");
2384N/A "This should be possible in the sequential case.");
2941N/A // Cannot yet substitute active_workers for n_par_threads 2941N/A // in the case where parallelism is being turned off by 2941N/A // setting n_par_threads to 0. 2384N/A // mr.end() may not necessarily be card aligned. 2384N/A // Continue the dirty range by opening the 2384N/A // dirty window one card to the left. 2384N/A // We hit a "clean" card; process any non-empty 2384N/A // "dirty" range accumulated so far. 3610N/A // fast forward through potential continuous whole-word range of clean cards beginning at a word-boundary 2384N/A // Reset the dirty window, while continuing to look 2384N/A // for the next dirty card that will start a 2384N/A // Note that "cur_entry" leads "start_of_non_clean" in 2384N/A // its leftward excursion after this point 2384N/A // in the loop and, when we hit the left end of "mr", 2384N/A // will point off of the left end of the card-table 2384N/A // If the first card of "mr" was dirty, we will have 2384N/A // been left with a dirty window, co-initial with "mr", 0N/A// clean (by dirty->clean before) ==> cur_younger_gen 0N/A// dirty ==> cur_youngergen_and_prev_nonclean_card 0N/A// precleaned ==> cur_youngergen_and_prev_nonclean_card 0N/A// prev-younger-gen ==> cur_youngergen_and_prev_nonclean_card 0N/A// cur-younger-gen ==> cur_younger_gen 0N/A// cur_youngergen_and_prev_nonclean_card ==> no change. 0N/A // We put this first because it's probably the most common case. 0N/A // No threat of contention with cleaning threads. 0N/A // Mark it as both cur and prev youngergen; card cleaning thread will 0N/A // eventually remove the previous stuff. 0N/A // Did the CAS succeed? 0N/A // Otherwise, retry, to see the new value. 0N/A "should be only possibilities.");
2390N/A // Convert the assertion check to a warning if we are running 2390N/A // CMS+ParNew until related bug is fixed. 2390N/A // In the case of CMS+ParNew, issue a warning 2390N/A warning(
"CMS+ParNew: Flickering used_region_at_save_marks()!!");
0N/A // Generations younger than gen have been evacuated. We can clear 0N/A // card table entries for gen (we know that it has no pointers 0N/A // to younger gens) and for those below. The card tables for 0N/A // the youngest gen need never be cleared, and those for perm gen 0N/A // will be cleared based on the parameter clear_perm. 0N/A // There's a bit of subtlety in the clear() and invalidate() 0N/A // methods that we exploit here and in invalidate_or_clear() 0N/A // below to avoid missing cards at the fringes. If clear() or 0N/A // invalidate() are changed in the future, this code should 0N/A // be revisited. 20040107.ysr 0N/A // Clear perm gen cards if asked to do so. 0N/A // For each generation gen (and younger and/or perm) 0N/A // invalidate the cards for the currently occupied part 0N/A // of that generation and clear the cards for the 0N/A // unoccupied part of the generation (if any, making use 0N/A // of that generation's prev_used_region to determine that 0N/A // region). No need to do anything for the youngest 0N/A // generation. Also see note#20040107.ysr above. 0N/A // Clear perm gen cards if asked to do so. 0N/A // Skip the youngest generation. 0N/A // Normally, we're interested in pointers to younger generations. 0N/A // We don't need to do young-gen spaces. 0N/A // If the first object is a regular object, and it has a 0N/A // young-to-old field, that would mark the previous card. 0N/A "else boundary would be boundary_block");
0N/A // Now traverse objects until end. 0N/A // We'd normally expect that cur_youngergen_and_prev_nonclean_card 0N/A // is a transient value, that cannot be in the card table 0N/A // except during GC, and thus assert that: 0N/A // guarantee(*cur_entry != cur_youngergen_and_prev_nonclean_card, 0N/A // "Illegal CT value"); 0N/A // That however, need not hold, as will become clear in the 0N/A // We'd normally expect that if we are in the parallel case, 0N/A // we can't have left a prev value (which would be different 0N/A // from the current value) in the card table, and so we'd like to 0N/A // guarantee(cur_youngergen_card_val() == youngergen_card 0N/A // || !is_prev_youngergen_card_val(*cur_entry), 0N/A // "Illegal CT value"); 0N/A // That, however, may not hold occasionally, because of 0N/A // CMS or MSC in the old gen. To wit, consider the 0N/A // following two simple illustrative scenarios: 0N/A // (a) CMS: Consider the case where a large object L 0N/A // spanning several cards is allocated in the old 0N/A // gen, and has a young gen reference stored in it, dirtying 0N/A // some interior cards. A young collection scans the card, 0N/A // finds a young ref and installs a youngergenP_n value. 0N/A // L then goes dead. Now a CMS collection starts, 0N/A // finds L dead and sweeps it up. Assume that L is 0N/A // abutting _unallocated_blk, so _unallocated_blk is 0N/A // adjusted down to (below) L. Assume further that 0N/A // no young collection intervenes during this CMS cycle. 0N/A // The next young gen cycle will not get to look at this 0N/A // youngergenP_n card since it lies in the unoccupied 0N/A // part of the space. 0N/A // Some young collections later the blocks on this 0N/A // card can be re-allocated either due to direct allocation 0N/A // or due to absorbing promotions. At this time, the 0N/A // before-gc verification will fail the above assert. 0N/A // (b) MSC: In this case, an object L with a young reference 0N/A // is on a card that (therefore) holds a youngergen_n value. 0N/A // Suppose also that L lies towards the end of the used 0N/A // the used space before GC. An MSC collection 0N/A // occurs that compacts to such an extent that this 0N/A // card is no longer in the occupied part of the space. 0N/A // Since current code in MSC does not always clear cards 0N/A // in the unused part of old gen, this stale youngergen_n 0N/A // value is left behind and can later be covered by 0N/A // an object when promotion or direct allocation 0N/A // re-allocates that part of the heap. 0N/A // Fortunately, the presence of such stale card values is 0N/A // "only" a minor annoyance in that subsequent young collections 0N/A // might needlessly scan such cards, but would still never corrupt 0N/A // the heap as a result. However, it's likely not to be a significant 0N/A // performance inhibitor in practice. For instance, 0N/A // some recent measurements with unoccupied cards eagerly cleared 0N/A // out to maintain this invariant, showed next to no 0N/A // change in young collection times; of course one can construct 0N/A // degenerate examples where the cost can be significant.) 0N/A // Note, in particular, that if the "stale" card is modified 0N/A // after re-allocation, it would be dirty, not "stale". Thus, 0N/A // we can never have a younger ref in such a card and it is 0N/A // safe not to scan that card in any collection. [As we see 0N/A // below, we do some unnecessary scanning 0N/A // in some cases in the current parallel scanning algorithm.] 0N/A // The main point below is that the parallel card scanning code 0N/A // deals correctly with these stale card values. There are two main 0N/A // cases to consider where we have a stale "younger gen" value and a 0N/A // "derivative" case to consider, where we have a stale 0N/A // "cur_younger_gen_and_prev_non_clean" value, as will become 0N/A // apparent in the case analysis below. 0N/A // o Case 1. If the stale value corresponds to a younger_gen_n 0N/A // value other than the cur_younger_gen value then the code 0N/A // treats this as being tantamount to a prev_younger_gen 0N/A // card. This means that the card may be unnecessarily scanned. 0N/A // There are two sub-cases to consider: 0N/A // o Case 1a. Let us say that the card is in the occupied part 0N/A // of the generation at the time the collection begins. In 0N/A // that case the card will be either cleared when it is scanned 0N/A // for young pointers, or will be set to cur_younger_gen as a 0N/A // result of promotion. (We have elided the normal case where 0N/A // the scanning thread and the promoting thread interleave 0N/A // possibly resulting in a transient 0N/A // cur_younger_gen_and_prev_non_clean value before settling 0N/A // to cur_younger_gen. [End Case 1a.] 0N/A // o Case 1b. Consider now the case when the card is in the unoccupied 0N/A // part of the space which becomes occupied because of promotions 0N/A // into it during the current young GC. In this case the card 0N/A // will never be scanned for young references. The current 0N/A // code will set the card value to either 0N/A // cur_younger_gen_and_prev_non_clean or leave 0N/A // it with its stale value -- because the promotions didn't 0N/A // result in any younger refs on that card. Of these two 0N/A // cases, the latter will be covered in Case 1a during 0N/A // a subsequent scan. To deal with the former case, we need 0N/A // to further consider how we deal with a stale value of 0N/A // cur_younger_gen_and_prev_non_clean in our case analysis 0N/A // below. This we do in Case 3 below. [End Case 1b] 0N/A // o Case 2. If the stale value corresponds to cur_younger_gen being 0N/A // a value not necessarily written by a current promotion, the 0N/A // card will not be scanned by the younger refs scanning code. 0N/A // (This is OK since as we argued above such cards cannot contain 0N/A // any younger refs.) The result is that this value will be 0N/A // treated as a prev_younger_gen value in a subsequent collection, 0N/A // which is addressed in Case 1 above. [End Case 2] 0N/A // o Case 3. We here consider the "derivative" case from Case 1b. above 0N/A // because of which we may find a stale 0N/A // cur_younger_gen_and_prev_non_clean card value in the table. 0N/A // Once again, as in Case 1, we consider two subcases, depending 0N/A // on whether the card lies in the occupied or unoccupied part 0N/A // of the space at the start of the young collection. 0N/A // o Case 3a. Let us say the card is in the occupied part of 0N/A // the old gen at the start of the young collection. In that 0N/A // case, the card will be scanned by the younger refs scanning 0N/A // code which will set it to cur_younger_gen. In a subsequent 0N/A // scan, the card will be considered again and get its final 0N/A // correct value. [End Case 3a] 0N/A // o Case 3b. Now consider the case where the card is in the 0N/A // unoccupied part of the old gen, and is occupied as a result 0N/A // of promotions during thus young gc. In that case, 0N/A // the card will not be scanned for younger refs. The presence 0N/A // of newly promoted objects on the card will then result in 0N/A // its keeping the value cur_younger_gen_and_prev_non_clean 0N/A // value, which we have dealt with in Case 3 here. [End Case 3b] 0N/A // (Please refer to the code in the helper class 0N/A // ClearNonCleanCardWrapper and in CardTableModRefBS for details.) 0N/A // The informal arguments above can be tightened into a formal 0N/A // correctness proof and it behooves us to write up such a proof, 0N/A // or to use model checking to prove that there are no lingering 0N/A // Clearly because of Case 3b one cannot bound the time for 0N/A // which a card will retain what we have called a "stale" value. 0N/A // However, one can obtain a Loose upper bound on the redundant 0N/A // work as a result of such stale values. Note first that any 0N/A // time a stale card lies in the occupied part of the space at 0N/A // the start of the collection, it is scanned by younger refs 0N/A // code and we can define a rank function on card values that 0N/A // declines when this is so. Note also that when a card does not 0N/A // lie in the occupied part of the space at the beginning of a 0N/A // young collection, its rank can either decline or stay unchanged. 0N/A // In this case, no extra work is done in terms of redundant 0N/A // younger refs scanning of that card. 0N/A // Then, the case analysis above reveals that, in the worst case, 0N/A // any such stale card will be scanned unnecessarily at most twice. 0N/A // It is nonethelss advisable to try and get rid of some of this 0N/A // redundant work in a subsequent (low priority) re-design of 0N/A // the card-scanning code, if only to simplify the underlying 0N/A // At present, we only know how to verify the card table RS for 0N/A // generational heaps. 0N/A // We will do the perm-gen portion of the card table, too. 0N/A // If the old gen collections also collect perm, then we are only 0N/A // interested in perm-to-young pointers, not perm-to-old pointers. 6N/A // The region mr may not start on a card boundary so 6N/A // the first card may reflect a write to the space 6N/A // just prior to mr. 0N/A "Unexpected dirty card found");