0N/A/*
4552N/A * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
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 *
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 *
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.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "gc_implementation/parallelScavenge/cardTableExtension.hpp"
1879N/A#include "gc_implementation/parallelScavenge/gcTaskManager.hpp"
1879N/A#include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
1879N/A#include "gc_implementation/parallelScavenge/psTasks.hpp"
1879N/A#include "gc_implementation/parallelScavenge/psYoungGen.hpp"
1879N/A#include "oops/oop.inline.hpp"
1879N/A#include "oops/oop.psgc.inline.hpp"
0N/A
0N/A// Checks an individual oop for missing precise marks. Mark
0N/A// may be either dirty or newgen.
0N/Aclass CheckForUnmarkedOops : public OopClosure {
113N/A private:
113N/A PSYoungGen* _young_gen;
0N/A CardTableExtension* _card_table;
113N/A HeapWord* _unmarked_addr;
113N/A jbyte* _unmarked_card;
0N/A
113N/A protected:
113N/A template <class T> void do_oop_work(T* p) {
3680N/A oop obj = oopDesc::load_decode_heap_oop(p);
113N/A if (_young_gen->is_in_reserved(obj) &&
0N/A !_card_table->addr_is_marked_imprecise(p)) {
0N/A // Don't overwrite the first missing card mark
0N/A if (_unmarked_addr == NULL) {
0N/A _unmarked_addr = (HeapWord*)p;
0N/A _unmarked_card = _card_table->byte_for(p);
0N/A }
0N/A }
0N/A }
0N/A
113N/A public:
113N/A CheckForUnmarkedOops(PSYoungGen* young_gen, CardTableExtension* card_table) :
113N/A _young_gen(young_gen), _card_table(card_table), _unmarked_addr(NULL) { }
113N/A
113N/A virtual void do_oop(oop* p) { CheckForUnmarkedOops::do_oop_work(p); }
113N/A virtual void do_oop(narrowOop* p) { CheckForUnmarkedOops::do_oop_work(p); }
113N/A
0N/A bool has_unmarked_oop() {
0N/A return _unmarked_addr != NULL;
0N/A }
0N/A};
0N/A
0N/A// Checks all objects for the existance of some type of mark,
0N/A// precise or imprecise, dirty or newgen.
0N/Aclass CheckForUnmarkedObjects : public ObjectClosure {
113N/A private:
113N/A PSYoungGen* _young_gen;
0N/A CardTableExtension* _card_table;
0N/A
0N/A public:
0N/A CheckForUnmarkedObjects() {
0N/A ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
0N/A assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
0N/A
0N/A _young_gen = heap->young_gen();
0N/A _card_table = (CardTableExtension*)heap->barrier_set();
0N/A // No point in asserting barrier set type here. Need to make CardTableExtension
0N/A // a unique barrier set type.
0N/A }
0N/A
0N/A // Card marks are not precise. The current system can leave us with
605N/A // a mismash of precise marks and beginning of object marks. This means
0N/A // we test for missing precise marks first. If any are found, we don't
0N/A // fail unless the object head is also unmarked.
0N/A virtual void do_object(oop obj) {
113N/A CheckForUnmarkedOops object_check(_young_gen, _card_table);
0N/A obj->oop_iterate(&object_check);
0N/A if (object_check.has_unmarked_oop()) {
0N/A assert(_card_table->addr_is_marked_imprecise(obj), "Found unmarked young_gen object");
0N/A }
0N/A }
0N/A};
0N/A
0N/A// Checks for precise marking of oops as newgen.
0N/Aclass CheckForPreciseMarks : public OopClosure {
113N/A private:
113N/A PSYoungGen* _young_gen;
0N/A CardTableExtension* _card_table;
0N/A
113N/A protected:
113N/A template <class T> void do_oop_work(T* p) {
113N/A oop obj = oopDesc::load_decode_heap_oop_not_null(p);
113N/A if (_young_gen->is_in_reserved(obj)) {
113N/A assert(_card_table->addr_is_marked_precise(p), "Found unmarked precise oop");
113N/A _card_table->set_card_newgen(p);
113N/A }
113N/A }
113N/A
0N/A public:
0N/A CheckForPreciseMarks( PSYoungGen* young_gen, CardTableExtension* card_table ) :
0N/A _young_gen(young_gen), _card_table(card_table) { }
0N/A
113N/A virtual void do_oop(oop* p) { CheckForPreciseMarks::do_oop_work(p); }
113N/A virtual void do_oop(narrowOop* p) { CheckForPreciseMarks::do_oop_work(p); }
0N/A};
0N/A
0N/A// We get passed the space_top value to prevent us from traversing into
0N/A// the old_gen promotion labs, which cannot be safely parsed.
0N/Avoid CardTableExtension::scavenge_contents(ObjectStartArray* start_array,
0N/A MutableSpace* sp,
0N/A HeapWord* space_top,
0N/A PSPromotionManager* pm)
0N/A{
0N/A assert(start_array != NULL && sp != NULL && pm != NULL, "Sanity");
0N/A assert(start_array->covered_region().contains(sp->used_region()),
0N/A "ObjectStartArray does not cover space");
0N/A
0N/A if (sp->not_empty()) {
0N/A oop* sp_top = (oop*)space_top;
0N/A oop* prev_top = NULL;
0N/A jbyte* current_card = byte_for(sp->bottom());
0N/A jbyte* end_card = byte_for(sp_top - 1); // sp_top is exclusive
0N/A // scan card marking array
0N/A while (current_card <= end_card) {
0N/A jbyte value = *current_card;
0N/A // skip clean cards
0N/A if (card_is_clean(value)) {
0N/A current_card++;
0N/A } else {
0N/A // we found a non-clean card
0N/A jbyte* first_nonclean_card = current_card++;
0N/A oop* bottom = (oop*)addr_for(first_nonclean_card);
0N/A // find object starting on card
0N/A oop* bottom_obj = (oop*)start_array->object_start((HeapWord*)bottom);
0N/A // bottom_obj = (oop*)start_array->object_start((HeapWord*)bottom);
0N/A assert(bottom_obj <= bottom, "just checking");
0N/A // make sure we don't scan oops we already looked at
0N/A if (bottom < prev_top) bottom = prev_top;
0N/A // figure out when to stop scanning
0N/A jbyte* first_clean_card;
0N/A oop* top;
0N/A bool restart_scanning;
0N/A do {
0N/A restart_scanning = false;
0N/A // find a clean card
0N/A while (current_card <= end_card) {
0N/A value = *current_card;
0N/A if (card_is_clean(value)) break;
0N/A current_card++;
0N/A }
0N/A // check if we reached the end, if so we are done
0N/A if (current_card >= end_card) {
0N/A first_clean_card = end_card + 1;
0N/A current_card++;
0N/A top = sp_top;
0N/A } else {
0N/A // we have a clean card, find object starting on that card
0N/A first_clean_card = current_card++;
0N/A top = (oop*)addr_for(first_clean_card);
0N/A oop* top_obj = (oop*)start_array->object_start((HeapWord*)top);
0N/A // top_obj = (oop*)start_array->object_start((HeapWord*)top);
0N/A assert(top_obj <= top, "just checking");
0N/A if (oop(top_obj)->is_objArray() || oop(top_obj)->is_typeArray()) {
0N/A // an arrayOop is starting on the clean card - since we do exact store
0N/A // checks for objArrays we are done
0N/A } else {
0N/A // otherwise, it is possible that the object starting on the clean card
0N/A // spans the entire card, and that the store happened on a later card.
0N/A // figure out where the object ends
0N/A top = top_obj + oop(top_obj)->size();
0N/A jbyte* top_card = CardTableModRefBS::byte_for(top - 1); // top is exclusive
0N/A if (top_card > first_clean_card) {
0N/A // object ends a different card
0N/A current_card = top_card + 1;
0N/A if (card_is_clean(*top_card)) {
0N/A // the ending card is clean, we are done
0N/A first_clean_card = top_card;
0N/A } else {
0N/A // the ending card is not clean, continue scanning at start of do-while
0N/A restart_scanning = true;
0N/A }
0N/A } else {
0N/A // object ends on the clean card, we are done.
0N/A assert(first_clean_card == top_card, "just checking");
0N/A }
0N/A }
0N/A }
0N/A } while (restart_scanning);
0N/A // we know which cards to scan, now clear them
0N/A while (first_nonclean_card < first_clean_card) {
0N/A *first_nonclean_card++ = clean_card;
0N/A }
0N/A // scan oops in objects
1626N/A do {
1626N/A oop(bottom_obj)->push_contents(pm);
1626N/A bottom_obj += oop(bottom_obj)->size();
1626N/A assert(bottom_obj <= sp_top, "just checking");
1626N/A } while (bottom_obj < top);
1626N/A pm->drain_stacks_cond_depth();
0N/A // remember top oop* scanned
0N/A prev_top = top;
0N/A }
0N/A }
0N/A }
0N/A}
0N/A
0N/Avoid CardTableExtension::scavenge_contents_parallel(ObjectStartArray* start_array,
0N/A MutableSpace* sp,
0N/A HeapWord* space_top,
0N/A PSPromotionManager* pm,
2941N/A uint stripe_number,
2941N/A uint stripe_total) {
0N/A int ssize = 128; // Naked constant! Work unit = 64k.
0N/A int dirty_card_count = 0;
0N/A
0N/A oop* sp_top = (oop*)space_top;
0N/A jbyte* start_card = byte_for(sp->bottom());
0N/A jbyte* end_card = byte_for(sp_top - 1) + 1;
0N/A oop* last_scanned = NULL; // Prevent scanning objects more than once
2941N/A // The width of the stripe ssize*stripe_total must be
2941N/A // consistent with the number of stripes so that the complete slice
2941N/A // is covered.
2941N/A size_t slice_width = ssize * stripe_total;
2941N/A for (jbyte* slice = start_card; slice < end_card; slice += slice_width) {
0N/A jbyte* worker_start_card = slice + stripe_number * ssize;
0N/A if (worker_start_card >= end_card)
0N/A return; // We're done.
0N/A
0N/A jbyte* worker_end_card = worker_start_card + ssize;
0N/A if (worker_end_card > end_card)
0N/A worker_end_card = end_card;
0N/A
0N/A // We do not want to scan objects more than once. In order to accomplish
0N/A // this, we assert that any object with an object head inside our 'slice'
0N/A // belongs to us. We may need to extend the range of scanned cards if the
0N/A // last object continues into the next 'slice'.
0N/A //
0N/A // Note! ending cards are exclusive!
0N/A HeapWord* slice_start = addr_for(worker_start_card);
0N/A HeapWord* slice_end = MIN2((HeapWord*) sp_top, addr_for(worker_end_card));
0N/A
0N/A // If there are not objects starting within the chunk, skip it.
0N/A if (!start_array->object_starts_in_range(slice_start, slice_end)) {
0N/A continue;
0N/A }
605N/A // Update our beginning addr
0N/A HeapWord* first_object = start_array->object_start(slice_start);
0N/A debug_only(oop* first_object_within_slice = (oop*) first_object;)
0N/A if (first_object < slice_start) {
0N/A last_scanned = (oop*)(first_object + oop(first_object)->size());
0N/A debug_only(first_object_within_slice = last_scanned;)
0N/A worker_start_card = byte_for(last_scanned);
0N/A }
0N/A
0N/A // Update the ending addr
0N/A if (slice_end < (HeapWord*)sp_top) {
0N/A // The subtraction is important! An object may start precisely at slice_end.
0N/A HeapWord* last_object = start_array->object_start(slice_end - 1);
0N/A slice_end = last_object + oop(last_object)->size();
0N/A // worker_end_card is exclusive, so bump it one past the end of last_object's
0N/A // covered span.
0N/A worker_end_card = byte_for(slice_end) + 1;
0N/A
0N/A if (worker_end_card > end_card)
0N/A worker_end_card = end_card;
0N/A }
0N/A
0N/A assert(slice_end <= (HeapWord*)sp_top, "Last object in slice crosses space boundary");
0N/A assert(is_valid_card_address(worker_start_card), "Invalid worker start card");
0N/A assert(is_valid_card_address(worker_end_card), "Invalid worker end card");
0N/A // Note that worker_start_card >= worker_end_card is legal, and happens when
0N/A // an object spans an entire slice.
0N/A assert(worker_start_card <= end_card, "worker start card beyond end card");
0N/A assert(worker_end_card <= end_card, "worker end card beyond end card");
0N/A
0N/A jbyte* current_card = worker_start_card;
0N/A while (current_card < worker_end_card) {
0N/A // Find an unclean card.
0N/A while (current_card < worker_end_card && card_is_clean(*current_card)) {
0N/A current_card++;
0N/A }
0N/A jbyte* first_unclean_card = current_card;
0N/A
0N/A // Find the end of a run of contiguous unclean cards
0N/A while (current_card < worker_end_card && !card_is_clean(*current_card)) {
0N/A while (current_card < worker_end_card && !card_is_clean(*current_card)) {
0N/A current_card++;
0N/A }
0N/A
0N/A if (current_card < worker_end_card) {
0N/A // Some objects may be large enough to span several cards. If such
0N/A // an object has more than one dirty card, separated by a clean card,
0N/A // we will attempt to scan it twice. The test against "last_scanned"
0N/A // prevents the redundant object scan, but it does not prevent newly
0N/A // marked cards from being cleaned.
0N/A HeapWord* last_object_in_dirty_region = start_array->object_start(addr_for(current_card)-1);
0N/A size_t size_of_last_object = oop(last_object_in_dirty_region)->size();
0N/A HeapWord* end_of_last_object = last_object_in_dirty_region + size_of_last_object;
0N/A jbyte* ending_card_of_last_object = byte_for(end_of_last_object);
0N/A assert(ending_card_of_last_object <= worker_end_card, "ending_card_of_last_object is greater than worker_end_card");
0N/A if (ending_card_of_last_object > current_card) {
0N/A // This means the object spans the next complete card.
0N/A // We need to bump the current_card to ending_card_of_last_object
0N/A current_card = ending_card_of_last_object;
0N/A }
0N/A }
0N/A }
0N/A jbyte* following_clean_card = current_card;
0N/A
0N/A if (first_unclean_card < worker_end_card) {
0N/A oop* p = (oop*) start_array->object_start(addr_for(first_unclean_card));
0N/A assert((HeapWord*)p <= addr_for(first_unclean_card), "checking");
0N/A // "p" should always be >= "last_scanned" because newly GC dirtied
0N/A // cards are no longer scanned again (see comment at end
0N/A // of loop on the increment of "current_card"). Test that
0N/A // hypothesis before removing this code.
0N/A // If this code is removed, deal with the first time through
0N/A // the loop when the last_scanned is the object starting in
0N/A // the previous slice.
0N/A assert((p >= last_scanned) ||
0N/A (last_scanned == first_object_within_slice),
0N/A "Should no longer be possible");
0N/A if (p < last_scanned) {
0N/A // Avoid scanning more than once; this can happen because
0N/A // newgen cards set by GC may a different set than the
0N/A // originally dirty set
0N/A p = last_scanned;
0N/A }
0N/A oop* to = (oop*)addr_for(following_clean_card);
0N/A
0N/A // Test slice_end first!
0N/A if ((HeapWord*)to > slice_end) {
0N/A to = (oop*)slice_end;
0N/A } else if (to > sp_top) {
0N/A to = sp_top;
0N/A }
0N/A
0N/A // we know which cards to scan, now clear them
0N/A if (first_unclean_card <= worker_start_card+1)
0N/A first_unclean_card = worker_start_card+1;
0N/A if (following_clean_card >= worker_end_card-1)
0N/A following_clean_card = worker_end_card-1;
0N/A
0N/A while (first_unclean_card < following_clean_card) {
0N/A *first_unclean_card++ = clean_card;
0N/A }
0N/A
0N/A const int interval = PrefetchScanIntervalInBytes;
0N/A // scan all objects in the range
0N/A if (interval != 0) {
1626N/A while (p < to) {
1626N/A Prefetch::write(p, interval);
1626N/A oop m = oop(p);
1626N/A assert(m->is_oop_or_null(), "check for header");
1626N/A m->push_contents(pm);
1626N/A p += m->size();
0N/A }
1626N/A pm->drain_stacks_cond_depth();
0N/A } else {
1626N/A while (p < to) {
1626N/A oop m = oop(p);
1626N/A assert(m->is_oop_or_null(), "check for header");
1626N/A m->push_contents(pm);
1626N/A p += m->size();
0N/A }
1626N/A pm->drain_stacks_cond_depth();
0N/A }
0N/A last_scanned = p;
0N/A }
0N/A // "current_card" is still the "following_clean_card" or
0N/A // the current_card is >= the worker_end_card so the
0N/A // loop will not execute again.
0N/A assert((current_card == following_clean_card) ||
0N/A (current_card >= worker_end_card),
0N/A "current_card should only be incremented if it still equals "
0N/A "following_clean_card");
0N/A // Increment current_card so that it is not processed again.
0N/A // It may now be dirty because a old-to-young pointer was
0N/A // found on it an updated. If it is now dirty, it cannot be
0N/A // be safely cleaned in the next iteration.
0N/A current_card++;
0N/A }
0N/A }
0N/A}
0N/A
0N/A// This should be called before a scavenge.
0N/Avoid CardTableExtension::verify_all_young_refs_imprecise() {
0N/A CheckForUnmarkedObjects check;
0N/A
0N/A ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
0N/A assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
0N/A
0N/A PSOldGen* old_gen = heap->old_gen();
0N/A PSPermGen* perm_gen = heap->perm_gen();
0N/A
0N/A old_gen->object_iterate(&check);
0N/A perm_gen->object_iterate(&check);
0N/A}
0N/A
0N/A// This should be called immediately after a scavenge, before mutators resume.
0N/Avoid CardTableExtension::verify_all_young_refs_precise() {
0N/A ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
0N/A assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
0N/A
0N/A PSOldGen* old_gen = heap->old_gen();
0N/A PSPermGen* perm_gen = heap->perm_gen();
0N/A
0N/A CheckForPreciseMarks check(heap->young_gen(), (CardTableExtension*)heap->barrier_set());
0N/A
0N/A old_gen->oop_iterate(&check);
0N/A perm_gen->oop_iterate(&check);
0N/A
0N/A verify_all_young_refs_precise_helper(old_gen->object_space()->used_region());
0N/A verify_all_young_refs_precise_helper(perm_gen->object_space()->used_region());
0N/A}
0N/A
0N/Avoid CardTableExtension::verify_all_young_refs_precise_helper(MemRegion mr) {
0N/A CardTableExtension* card_table = (CardTableExtension*)Universe::heap()->barrier_set();
0N/A // FIX ME ASSERT HERE
0N/A
0N/A jbyte* bot = card_table->byte_for(mr.start());
0N/A jbyte* top = card_table->byte_for(mr.end());
0N/A while(bot <= top) {
0N/A assert(*bot == clean_card || *bot == verify_card, "Found unwanted or unknown card mark");
0N/A if (*bot == verify_card)
0N/A *bot = youngergen_card;
0N/A bot++;
0N/A }
0N/A}
0N/A
0N/Abool CardTableExtension::addr_is_marked_imprecise(void *addr) {
0N/A jbyte* p = byte_for(addr);
0N/A jbyte val = *p;
0N/A
0N/A if (card_is_dirty(val))
0N/A return true;
0N/A
0N/A if (card_is_newgen(val))
0N/A return true;
0N/A
0N/A if (card_is_clean(val))
0N/A return false;
0N/A
0N/A assert(false, "Found unhandled card mark type");
0N/A
0N/A return false;
0N/A}
0N/A
0N/A// Also includes verify_card
0N/Abool CardTableExtension::addr_is_marked_precise(void *addr) {
0N/A jbyte* p = byte_for(addr);
0N/A jbyte val = *p;
0N/A
0N/A if (card_is_newgen(val))
0N/A return true;
0N/A
0N/A if (card_is_verify(val))
0N/A return true;
0N/A
0N/A if (card_is_clean(val))
0N/A return false;
0N/A
0N/A if (card_is_dirty(val))
0N/A return false;
0N/A
0N/A assert(false, "Found unhandled card mark type");
0N/A
0N/A return false;
0N/A}
0N/A
0N/A// Assumes that only the base or the end changes. This allows indentification
0N/A// of the region that is being resized. The
0N/A// CardTableModRefBS::resize_covered_region() is used for the normal case
0N/A// where the covered regions are growing or shrinking at the high end.
0N/A// The method resize_covered_region_by_end() is analogous to
0N/A// CardTableModRefBS::resize_covered_region() but
0N/A// for regions that grow or shrink at the low end.
0N/Avoid CardTableExtension::resize_covered_region(MemRegion new_region) {
0N/A
0N/A for (int i = 0; i < _cur_covered_regions; i++) {
0N/A if (_covered[i].start() == new_region.start()) {
0N/A // Found a covered region with the same start as the
0N/A // new region. The region is growing or shrinking
0N/A // from the start of the region.
0N/A resize_covered_region_by_start(new_region);
0N/A return;
0N/A }
0N/A if (_covered[i].start() > new_region.start()) {
0N/A break;
0N/A }
0N/A }
0N/A
0N/A int changed_region = -1;
0N/A for (int j = 0; j < _cur_covered_regions; j++) {
0N/A if (_covered[j].end() == new_region.end()) {
0N/A changed_region = j;
0N/A // This is a case where the covered region is growing or shrinking
0N/A // at the start of the region.
0N/A assert(changed_region != -1, "Don't expect to add a covered region");
0N/A assert(_covered[changed_region].byte_size() != new_region.byte_size(),
0N/A "The sizes should be different here");
0N/A resize_covered_region_by_end(changed_region, new_region);
0N/A return;
0N/A }
0N/A }
0N/A // This should only be a new covered region (where no existing
0N/A // covered region matches at the start or the end).
0N/A assert(_cur_covered_regions < _max_covered_regions,
0N/A "An existing region should have been found");
0N/A resize_covered_region_by_start(new_region);
0N/A}
0N/A
0N/Avoid CardTableExtension::resize_covered_region_by_start(MemRegion new_region) {
0N/A CardTableModRefBS::resize_covered_region(new_region);
0N/A debug_only(verify_guard();)
0N/A}
0N/A
0N/Avoid CardTableExtension::resize_covered_region_by_end(int changed_region,
0N/A MemRegion new_region) {
0N/A assert(SafepointSynchronize::is_at_safepoint(),
0N/A "Only expect an expansion at the low end at a GC");
0N/A debug_only(verify_guard();)
0N/A#ifdef ASSERT
0N/A for (int k = 0; k < _cur_covered_regions; k++) {
0N/A if (_covered[k].end() == new_region.end()) {
0N/A assert(changed_region == k, "Changed region is incorrect");
0N/A break;
0N/A }
0N/A }
0N/A#endif
0N/A
0N/A // Commit new or uncommit old pages, if necessary.
1532N/A if (resize_commit_uncommit(changed_region, new_region)) {
1532N/A // Set the new start of the committed region
1532N/A resize_update_committed_table(changed_region, new_region);
1532N/A }
0N/A
0N/A // Update card table entries
0N/A resize_update_card_table_entries(changed_region, new_region);
0N/A
0N/A // Update the covered region
0N/A resize_update_covered_table(changed_region, new_region);
0N/A
0N/A if (TraceCardTableModRefBS) {
0N/A int ind = changed_region;
0N/A gclog_or_tty->print_cr("CardTableModRefBS::resize_covered_region: ");
0N/A gclog_or_tty->print_cr(" "
0N/A " _covered[%d].start(): " INTPTR_FORMAT
0N/A " _covered[%d].last(): " INTPTR_FORMAT,
0N/A ind, _covered[ind].start(),
0N/A ind, _covered[ind].last());
0N/A gclog_or_tty->print_cr(" "
0N/A " _committed[%d].start(): " INTPTR_FORMAT
0N/A " _committed[%d].last(): " INTPTR_FORMAT,
0N/A ind, _committed[ind].start(),
0N/A ind, _committed[ind].last());
0N/A gclog_or_tty->print_cr(" "
0N/A " byte_for(start): " INTPTR_FORMAT
0N/A " byte_for(last): " INTPTR_FORMAT,
0N/A byte_for(_covered[ind].start()),
0N/A byte_for(_covered[ind].last()));
0N/A gclog_or_tty->print_cr(" "
0N/A " addr_for(start): " INTPTR_FORMAT
0N/A " addr_for(last): " INTPTR_FORMAT,
0N/A addr_for((jbyte*) _committed[ind].start()),
0N/A addr_for((jbyte*) _committed[ind].last()));
0N/A }
0N/A debug_only(verify_guard();)
0N/A}
0N/A
1532N/Abool CardTableExtension::resize_commit_uncommit(int changed_region,
0N/A MemRegion new_region) {
1532N/A bool result = false;
0N/A // Commit new or uncommit old pages, if necessary.
0N/A MemRegion cur_committed = _committed[changed_region];
0N/A assert(_covered[changed_region].end() == new_region.end(),
0N/A "The ends of the regions are expected to match");
0N/A // Extend the start of this _committed region to
0N/A // to cover the start of any previous _committed region.
0N/A // This forms overlapping regions, but never interior regions.
0N/A HeapWord* min_prev_start = lowest_prev_committed_start(changed_region);
0N/A if (min_prev_start < cur_committed.start()) {
0N/A // Only really need to set start of "cur_committed" to
0N/A // the new start (min_prev_start) but assertion checking code
0N/A // below use cur_committed.end() so make it correct.
0N/A MemRegion new_committed =
0N/A MemRegion(min_prev_start, cur_committed.end());
0N/A cur_committed = new_committed;
0N/A }
0N/A#ifdef ASSERT
0N/A ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
0N/A assert(cur_committed.start() ==
0N/A (HeapWord*) align_size_up((uintptr_t) cur_committed.start(),
0N/A os::vm_page_size()),
0N/A "Starts should have proper alignment");
0N/A#endif
0N/A
0N/A jbyte* new_start = byte_for(new_region.start());
0N/A // Round down because this is for the start address
0N/A HeapWord* new_start_aligned =
0N/A (HeapWord*)align_size_down((uintptr_t)new_start, os::vm_page_size());
0N/A // The guard page is always committed and should not be committed over.
0N/A // This method is used in cases where the generation is growing toward
0N/A // lower addresses but the guard region is still at the end of the
0N/A // card table. That still makes sense when looking for writes
0N/A // off the end of the card table.
0N/A if (new_start_aligned < cur_committed.start()) {
0N/A // Expand the committed region
0N/A //
0N/A // Case A
0N/A // |+ guard +|
0N/A // |+ cur committed +++++++++|
0N/A // |+ new committed +++++++++++++++++|
0N/A //
0N/A // Case B
0N/A // |+ guard +|
0N/A // |+ cur committed +|
0N/A // |+ new committed +++++++|
0N/A //
0N/A // These are not expected because the calculation of the
0N/A // cur committed region and the new committed region
0N/A // share the same end for the covered region.
0N/A // Case C
0N/A // |+ guard +|
0N/A // |+ cur committed +|
0N/A // |+ new committed +++++++++++++++++|
0N/A // Case D
0N/A // |+ guard +|
0N/A // |+ cur committed +++++++++++|
0N/A // |+ new committed +++++++|
0N/A
0N/A HeapWord* new_end_for_commit =
0N/A MIN2(cur_committed.end(), _guard_region.start());
263N/A if(new_start_aligned < new_end_for_commit) {
263N/A MemRegion new_committed =
263N/A MemRegion(new_start_aligned, new_end_for_commit);
4552N/A os::commit_memory_or_exit((char*)new_committed.start(),
4552N/A new_committed.byte_size(), !ExecMem,
4552N/A "card table expansion");
0N/A }
1532N/A result = true;
0N/A } else if (new_start_aligned > cur_committed.start()) {
0N/A // Shrink the committed region
1532N/A#if 0 // uncommitting space is currently unsafe because of the interactions
1532N/A // of growing and shrinking regions. One region A can uncommit space
1532N/A // that it owns but which is being used by another region B (maybe).
1532N/A // Region B has not committed the space because it was already
1532N/A // committed by region A.
0N/A MemRegion uncommit_region = committed_unique_to_self(changed_region,
0N/A MemRegion(cur_committed.start(), new_start_aligned));
0N/A if (!uncommit_region.is_empty()) {
0N/A if (!os::uncommit_memory((char*)uncommit_region.start(),
0N/A uncommit_region.byte_size())) {
1532N/A // If the uncommit fails, ignore it. Let the
1532N/A // committed table resizing go even though the committed
1532N/A // table will over state the committed space.
0N/A }
0N/A }
1532N/A#else
1532N/A assert(!result, "Should be false with current workaround");
1532N/A#endif
0N/A }
0N/A assert(_committed[changed_region].end() == cur_committed.end(),
0N/A "end should not change");
1532N/A return result;
0N/A}
0N/A
0N/Avoid CardTableExtension::resize_update_committed_table(int changed_region,
0N/A MemRegion new_region) {
0N/A
0N/A jbyte* new_start = byte_for(new_region.start());
0N/A // Set the new start of the committed region
0N/A HeapWord* new_start_aligned =
0N/A (HeapWord*)align_size_down((uintptr_t)new_start,
0N/A os::vm_page_size());
0N/A MemRegion new_committed = MemRegion(new_start_aligned,
0N/A _committed[changed_region].end());
0N/A _committed[changed_region] = new_committed;
0N/A _committed[changed_region].set_start(new_start_aligned);
0N/A}
0N/A
0N/Avoid CardTableExtension::resize_update_card_table_entries(int changed_region,
0N/A MemRegion new_region) {
0N/A debug_only(verify_guard();)
0N/A MemRegion original_covered = _covered[changed_region];
0N/A // Initialize the card entries. Only consider the
0N/A // region covered by the card table (_whole_heap)
0N/A jbyte* entry;
0N/A if (new_region.start() < _whole_heap.start()) {
0N/A entry = byte_for(_whole_heap.start());
0N/A } else {
0N/A entry = byte_for(new_region.start());
0N/A }
0N/A jbyte* end = byte_for(original_covered.start());
0N/A // If _whole_heap starts at the original covered regions start,
0N/A // this loop will not execute.
0N/A while (entry < end) { *entry++ = clean_card; }
0N/A}
0N/A
0N/Avoid CardTableExtension::resize_update_covered_table(int changed_region,
0N/A MemRegion new_region) {
0N/A // Update the covered region
0N/A _covered[changed_region].set_start(new_region.start());
0N/A _covered[changed_region].set_word_size(new_region.word_size());
0N/A
0N/A // reorder regions. There should only be at most 1 out
0N/A // of order.
0N/A for (int i = _cur_covered_regions-1 ; i > 0; i--) {
0N/A if (_covered[i].start() < _covered[i-1].start()) {
0N/A MemRegion covered_mr = _covered[i-1];
0N/A _covered[i-1] = _covered[i];
0N/A _covered[i] = covered_mr;
0N/A MemRegion committed_mr = _committed[i-1];
0N/A _committed[i-1] = _committed[i];
0N/A _committed[i] = committed_mr;
0N/A break;
0N/A }
0N/A }
0N/A#ifdef ASSERT
0N/A for (int m = 0; m < _cur_covered_regions-1; m++) {
0N/A assert(_covered[m].start() <= _covered[m+1].start(),
0N/A "Covered regions out of order");
0N/A assert(_committed[m].start() <= _committed[m+1].start(),
0N/A "Committed regions out of order");
0N/A }
0N/A#endif
0N/A}
0N/A
0N/A// Returns the start of any committed region that is lower than
0N/A// the target committed region (index ind) and that intersects the
0N/A// target region. If none, return start of target region.
0N/A//
0N/A// -------------
0N/A// | |
0N/A// -------------
0N/A// ------------
0N/A// | target |
0N/A// ------------
0N/A// -------------
0N/A// | |
0N/A// -------------
0N/A// ^ returns this
0N/A//
0N/A// -------------
0N/A// | |
0N/A// -------------
0N/A// ------------
0N/A// | target |
0N/A// ------------
0N/A// -------------
0N/A// | |
0N/A// -------------
0N/A// ^ returns this
0N/A
0N/AHeapWord* CardTableExtension::lowest_prev_committed_start(int ind) const {
0N/A assert(_cur_covered_regions >= 0, "Expecting at least on region");
0N/A HeapWord* min_start = _committed[ind].start();
0N/A for (int j = 0; j < ind; j++) {
0N/A HeapWord* this_start = _committed[j].start();
0N/A if ((this_start < min_start) &&
0N/A !(_committed[j].intersection(_committed[ind])).is_empty()) {
0N/A min_start = this_start;
0N/A }
0N/A }
0N/A return min_start;
0N/A}