0N/A/*
3679N/A * Copyright (c) 1997, 2012, 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 "classfile/systemDictionary.hpp"
1879N/A#include "classfile/vmSymbols.hpp"
1879N/A#include "gc_implementation/shared/liveRange.hpp"
1879N/A#include "gc_implementation/shared/markSweep.hpp"
1879N/A#include "gc_implementation/shared/spaceDecorator.hpp"
1879N/A#include "memory/blockOffsetTable.inline.hpp"
1879N/A#include "memory/defNewGeneration.hpp"
1879N/A#include "memory/genCollectedHeap.hpp"
1879N/A#include "memory/space.hpp"
1879N/A#include "memory/space.inline.hpp"
1879N/A#include "memory/universe.inline.hpp"
1879N/A#include "oops/oop.inline.hpp"
1879N/A#include "oops/oop.inline2.hpp"
1879N/A#include "runtime/java.hpp"
1879N/A#include "runtime/safepoint.hpp"
1879N/A#include "utilities/copy.hpp"
1879N/A#include "utilities/globalDefinitions.hpp"
0N/A
113N/Avoid SpaceMemRegionOopsIterClosure::do_oop(oop* p) { SpaceMemRegionOopsIterClosure::do_oop_work(p); }
113N/Avoid SpaceMemRegionOopsIterClosure::do_oop(narrowOop* p) { SpaceMemRegionOopsIterClosure::do_oop_work(p); }
113N/A
0N/AHeapWord* DirtyCardToOopClosure::get_actual_top(HeapWord* top,
0N/A HeapWord* top_obj) {
0N/A if (top_obj != NULL) {
0N/A if (_sp->block_is_obj(top_obj)) {
0N/A if (_precision == CardTableModRefBS::ObjHeadPreciseArray) {
0N/A if (oop(top_obj)->is_objArray() || oop(top_obj)->is_typeArray()) {
0N/A // An arrayOop is starting on the dirty card - since we do exact
0N/A // store checks for objArrays we are done.
0N/A } else {
0N/A // Otherwise, it is possible that the object starting on the dirty
0N/A // card spans the entire card, and that the store happened on a
0N/A // later card. Figure out where the object ends.
0N/A // Use the block_size() method of the space over which
0N/A // the iteration is being done. That space (e.g. CMS) may have
0N/A // specific requirements on object sizes which will
0N/A // be reflected in the block_size() method.
0N/A top = top_obj + oop(top_obj)->size();
0N/A }
0N/A }
0N/A } else {
0N/A top = top_obj;
0N/A }
0N/A } else {
0N/A assert(top == _sp->end(), "only case where top_obj == NULL");
0N/A }
0N/A return top;
0N/A}
0N/A
0N/Avoid DirtyCardToOopClosure::walk_mem_region(MemRegion mr,
0N/A HeapWord* bottom,
0N/A HeapWord* top) {
0N/A // 1. Blocks may or may not be objects.
0N/A // 2. Even when a block_is_obj(), it may not entirely
0N/A // occupy the block if the block quantum is larger than
0N/A // the object size.
0N/A // We can and should try to optimize by calling the non-MemRegion
0N/A // version of oop_iterate() for all but the extremal objects
0N/A // (for which we need to call the MemRegion version of
0N/A // oop_iterate()) To be done post-beta XXX
0N/A for (; bottom < top; bottom += _sp->block_size(bottom)) {
0N/A // As in the case of contiguous space above, we'd like to
0N/A // just use the value returned by oop_iterate to increment the
0N/A // current pointer; unfortunately, that won't work in CMS because
0N/A // we'd need an interface change (it seems) to have the space
0N/A // "adjust the object size" (for instance pad it up to its
0N/A // block alignment or minimum block size restrictions. XXX
0N/A if (_sp->block_is_obj(bottom) &&
0N/A !_sp->obj_allocated_since_save_marks(oop(bottom))) {
0N/A oop(bottom)->oop_iterate(_cl, mr);
0N/A }
0N/A }
0N/A}
0N/A
2454N/A// We get called with "mr" representing the dirty region
2454N/A// that we want to process. Because of imprecise marking,
2454N/A// we may need to extend the incoming "mr" to the right,
2454N/A// and scan more. However, because we may already have
2454N/A// scanned some of that extended region, we may need to
2454N/A// trim its right-end back some so we do not scan what
2454N/A// we (or another worker thread) may already have scanned
2454N/A// or planning to scan.
0N/Avoid DirtyCardToOopClosure::do_MemRegion(MemRegion mr) {
0N/A
0N/A // Some collectors need to do special things whenever their dirty
0N/A // cards are processed. For instance, CMS must remember mutator updates
0N/A // (i.e. dirty cards) so as to re-scan mutated objects.
0N/A // Such work can be piggy-backed here on dirty card scanning, so as to make
0N/A // it slightly more efficient than doing a complete non-detructive pre-scan
0N/A // of the card table.
0N/A MemRegionClosure* pCl = _sp->preconsumptionDirtyCardClosure();
0N/A if (pCl != NULL) {
0N/A pCl->do_MemRegion(mr);
0N/A }
0N/A
0N/A HeapWord* bottom = mr.start();
0N/A HeapWord* last = mr.last();
0N/A HeapWord* top = mr.end();
0N/A HeapWord* bottom_obj;
0N/A HeapWord* top_obj;
0N/A
0N/A assert(_precision == CardTableModRefBS::ObjHeadPreciseArray ||
0N/A _precision == CardTableModRefBS::Precise,
0N/A "Only ones we deal with for now.");
0N/A
0N/A assert(_precision != CardTableModRefBS::ObjHeadPreciseArray ||
342N/A _cl->idempotent() || _last_bottom == NULL ||
0N/A top <= _last_bottom,
0N/A "Not decreasing");
0N/A NOT_PRODUCT(_last_bottom = mr.start());
0N/A
0N/A bottom_obj = _sp->block_start(bottom);
0N/A top_obj = _sp->block_start(last);
0N/A
0N/A assert(bottom_obj <= bottom, "just checking");
0N/A assert(top_obj <= top, "just checking");
0N/A
0N/A // Given what we think is the top of the memory region and
0N/A // the start of the object at the top, get the actual
0N/A // value of the top.
0N/A top = get_actual_top(top, top_obj);
0N/A
0N/A // If the previous call did some part of this region, don't redo.
0N/A if (_precision == CardTableModRefBS::ObjHeadPreciseArray &&
0N/A _min_done != NULL &&
0N/A _min_done < top) {
0N/A top = _min_done;
0N/A }
0N/A
0N/A // Top may have been reset, and in fact may be below bottom,
0N/A // e.g. the dirty card region is entirely in a now free object
0N/A // -- something that could happen with a concurrent sweeper.
0N/A bottom = MIN2(bottom, top);
2454N/A MemRegion extended_mr = MemRegion(bottom, top);
0N/A assert(bottom <= top &&
0N/A (_precision != CardTableModRefBS::ObjHeadPreciseArray ||
0N/A _min_done == NULL ||
0N/A top <= _min_done),
0N/A "overlap!");
0N/A
0N/A // Walk the region if it is not empty; otherwise there is nothing to do.
2454N/A if (!extended_mr.is_empty()) {
2454N/A walk_mem_region(extended_mr, bottom_obj, top);
0N/A }
0N/A
342N/A // An idempotent closure might be applied in any order, so we don't
342N/A // record a _min_done for it.
342N/A if (!_cl->idempotent()) {
342N/A _min_done = bottom;
342N/A } else {
342N/A assert(_min_done == _last_explicit_min_done,
342N/A "Don't update _min_done for idempotent cl");
342N/A }
0N/A}
0N/A
0N/ADirtyCardToOopClosure* Space::new_dcto_cl(OopClosure* cl,
0N/A CardTableModRefBS::PrecisionStyle precision,
0N/A HeapWord* boundary) {
0N/A return new DirtyCardToOopClosure(this, cl, precision, boundary);
0N/A}
0N/A
0N/AHeapWord* ContiguousSpaceDCTOC::get_actual_top(HeapWord* top,
0N/A HeapWord* top_obj) {
0N/A if (top_obj != NULL && top_obj < (_sp->toContiguousSpace())->top()) {
0N/A if (_precision == CardTableModRefBS::ObjHeadPreciseArray) {
0N/A if (oop(top_obj)->is_objArray() || oop(top_obj)->is_typeArray()) {
0N/A // An arrayOop is starting on the dirty card - since we do exact
0N/A // store checks for objArrays we are done.
0N/A } else {
0N/A // Otherwise, it is possible that the object starting on the dirty
0N/A // card spans the entire card, and that the store happened on a
0N/A // later card. Figure out where the object ends.
0N/A assert(_sp->block_size(top_obj) == (size_t) oop(top_obj)->size(),
0N/A "Block size and object size mismatch");
0N/A top = top_obj + oop(top_obj)->size();
0N/A }
0N/A }
0N/A } else {
0N/A top = (_sp->toContiguousSpace())->top();
0N/A }
0N/A return top;
0N/A}
0N/A
0N/Avoid Filtering_DCTOC::walk_mem_region(MemRegion mr,
0N/A HeapWord* bottom,
0N/A HeapWord* top) {
0N/A // Note that this assumption won't hold if we have a concurrent
0N/A // collector in this space, which may have freed up objects after
0N/A // they were dirtied and before the stop-the-world GC that is
0N/A // examining cards here.
0N/A assert(bottom < top, "ought to be at least one obj on a dirty card.");
0N/A
0N/A if (_boundary != NULL) {
0N/A // We have a boundary outside of which we don't want to look
0N/A // at objects, so create a filtering closure around the
0N/A // oop closure before walking the region.
0N/A FilteringClosure filter(_boundary, _cl);
0N/A walk_mem_region_with_cl(mr, bottom, top, &filter);
0N/A } else {
0N/A // No boundary, simply walk the heap with the oop closure.
0N/A walk_mem_region_with_cl(mr, bottom, top, _cl);
0N/A }
0N/A
0N/A}
0N/A
0N/A// We must replicate this so that the static type of "FilteringClosure"
0N/A// (see above) is apparent at the oop_iterate calls.
0N/A#define ContiguousSpaceDCTOC__walk_mem_region_with_cl_DEFN(ClosureType) \
0N/Avoid ContiguousSpaceDCTOC::walk_mem_region_with_cl(MemRegion mr, \
0N/A HeapWord* bottom, \
0N/A HeapWord* top, \
0N/A ClosureType* cl) { \
0N/A bottom += oop(bottom)->oop_iterate(cl, mr); \
0N/A if (bottom < top) { \
0N/A HeapWord* next_obj = bottom + oop(bottom)->size(); \
0N/A while (next_obj < top) { \
0N/A /* Bottom lies entirely below top, so we can call the */ \
0N/A /* non-memRegion version of oop_iterate below. */ \
0N/A oop(bottom)->oop_iterate(cl); \
0N/A bottom = next_obj; \
0N/A next_obj = bottom + oop(bottom)->size(); \
0N/A } \
0N/A /* Last object. */ \
0N/A oop(bottom)->oop_iterate(cl, mr); \
0N/A } \
0N/A}
0N/A
0N/A// (There are only two of these, rather than N, because the split is due
0N/A// only to the introduction of the FilteringClosure, a local part of the
0N/A// impl of this abstraction.)
0N/AContiguousSpaceDCTOC__walk_mem_region_with_cl_DEFN(OopClosure)
0N/AContiguousSpaceDCTOC__walk_mem_region_with_cl_DEFN(FilteringClosure)
0N/A
0N/ADirtyCardToOopClosure*
0N/AContiguousSpace::new_dcto_cl(OopClosure* cl,
0N/A CardTableModRefBS::PrecisionStyle precision,
0N/A HeapWord* boundary) {
0N/A return new ContiguousSpaceDCTOC(this, cl, precision, boundary);
0N/A}
0N/A
263N/Avoid Space::initialize(MemRegion mr,
263N/A bool clear_space,
263N/A bool mangle_space) {
0N/A HeapWord* bottom = mr.start();
0N/A HeapWord* end = mr.end();
0N/A assert(Universe::on_page_boundary(bottom) && Universe::on_page_boundary(end),
0N/A "invalid space boundaries");
0N/A set_bottom(bottom);
0N/A set_end(end);
263N/A if (clear_space) clear(mangle_space);
263N/A}
263N/A
263N/Avoid Space::clear(bool mangle_space) {
263N/A if (ZapUnusedHeapArea && mangle_space) {
263N/A mangle_unused_area();
263N/A }
0N/A}
0N/A
356N/AContiguousSpace::ContiguousSpace(): CompactibleSpace(), _top(NULL),
356N/A _concurrent_iteration_safe_limit(NULL) {
263N/A _mangler = new GenSpaceMangler(this);
0N/A}
0N/A
263N/AContiguousSpace::~ContiguousSpace() {
263N/A delete _mangler;
263N/A}
263N/A
263N/Avoid ContiguousSpace::initialize(MemRegion mr,
263N/A bool clear_space,
263N/A bool mangle_space)
0N/A{
263N/A CompactibleSpace::initialize(mr, clear_space, mangle_space);
347N/A set_concurrent_iteration_safe_limit(top());
0N/A}
0N/A
263N/Avoid ContiguousSpace::clear(bool mangle_space) {
0N/A set_top(bottom());
0N/A set_saved_mark();
356N/A CompactibleSpace::clear(mangle_space);
0N/A}
0N/A
0N/Abool ContiguousSpace::is_in(const void* p) const {
0N/A return _bottom <= p && p < _top;
0N/A}
0N/A
0N/Abool ContiguousSpace::is_free_block(const HeapWord* p) const {
0N/A return p >= _top;
0N/A}
0N/A
263N/Avoid OffsetTableContigSpace::clear(bool mangle_space) {
263N/A ContiguousSpace::clear(mangle_space);
0N/A _offsets.initialize_threshold();
0N/A}
0N/A
0N/Avoid OffsetTableContigSpace::set_bottom(HeapWord* new_bottom) {
0N/A Space::set_bottom(new_bottom);
0N/A _offsets.set_bottom(new_bottom);
0N/A}
0N/A
0N/Avoid OffsetTableContigSpace::set_end(HeapWord* new_end) {
0N/A // Space should not advertize an increase in size
0N/A // until after the underlying offest table has been enlarged.
0N/A _offsets.resize(pointer_delta(new_end, bottom()));
0N/A Space::set_end(new_end);
0N/A}
0N/A
263N/A#ifndef PRODUCT
263N/A
263N/Avoid ContiguousSpace::set_top_for_allocations(HeapWord* v) {
263N/A mangler()->set_top_for_allocations(v);
263N/A}
263N/Avoid ContiguousSpace::set_top_for_allocations() {
263N/A mangler()->set_top_for_allocations(top());
263N/A}
263N/Avoid ContiguousSpace::check_mangled_unused_area(HeapWord* limit) {
263N/A mangler()->check_mangled_unused_area(limit);
263N/A}
263N/A
263N/Avoid ContiguousSpace::check_mangled_unused_area_complete() {
263N/A mangler()->check_mangled_unused_area_complete();
0N/A}
0N/A
263N/A// Mangled only the unused space that has not previously
263N/A// been mangled and that has not been allocated since being
263N/A// mangled.
263N/Avoid ContiguousSpace::mangle_unused_area() {
263N/A mangler()->mangle_unused_area();
263N/A}
263N/Avoid ContiguousSpace::mangle_unused_area_complete() {
263N/A mangler()->mangle_unused_area_complete();
0N/A}
263N/Avoid ContiguousSpace::mangle_region(MemRegion mr) {
263N/A // Although this method uses SpaceMangler::mangle_region() which
263N/A // is not specific to a space, the when the ContiguousSpace version
263N/A // is called, it is always with regard to a space and this
263N/A // bounds checking is appropriate.
263N/A MemRegion space_mr(bottom(), end());
263N/A assert(space_mr.contains(mr), "Mangling outside space");
263N/A SpaceMangler::mangle_region(mr);
263N/A}
263N/A#endif // NOT_PRODUCT
0N/A
263N/Avoid CompactibleSpace::initialize(MemRegion mr,
263N/A bool clear_space,
263N/A bool mangle_space) {
263N/A Space::initialize(mr, clear_space, mangle_space);
356N/A set_compaction_top(bottom());
356N/A _next_compaction_space = NULL;
356N/A}
356N/A
356N/Avoid CompactibleSpace::clear(bool mangle_space) {
356N/A Space::clear(mangle_space);
0N/A _compaction_top = bottom();
0N/A}
0N/A
0N/AHeapWord* CompactibleSpace::forward(oop q, size_t size,
0N/A CompactPoint* cp, HeapWord* compact_top) {
0N/A // q is alive
0N/A // First check if we should switch compaction space
0N/A assert(this == cp->space, "'this' should be current compaction space.");
0N/A size_t compaction_max_size = pointer_delta(end(), compact_top);
0N/A while (size > compaction_max_size) {
0N/A // switch to next compaction space
0N/A cp->space->set_compaction_top(compact_top);
0N/A cp->space = cp->space->next_compaction_space();
0N/A if (cp->space == NULL) {
0N/A cp->gen = GenCollectedHeap::heap()->prev_gen(cp->gen);
0N/A assert(cp->gen != NULL, "compaction must succeed");
0N/A cp->space = cp->gen->first_compaction_space();
0N/A assert(cp->space != NULL, "generation must have a first compaction space");
0N/A }
0N/A compact_top = cp->space->bottom();
0N/A cp->space->set_compaction_top(compact_top);
0N/A cp->threshold = cp->space->initialize_threshold();
0N/A compaction_max_size = pointer_delta(cp->space->end(), compact_top);
0N/A }
0N/A
0N/A // store the forwarding pointer into the mark word
0N/A if ((HeapWord*)q != compact_top) {
0N/A q->forward_to(oop(compact_top));
0N/A assert(q->is_gc_marked(), "encoding the pointer should preserve the mark");
0N/A } else {
0N/A // if the object isn't moving we can just set the mark to the default
0N/A // mark and handle it specially later on.
0N/A q->init_mark();
0N/A assert(q->forwardee() == NULL, "should be forwarded to NULL");
0N/A }
0N/A
113N/A VALIDATE_MARK_SWEEP_ONLY(MarkSweep::register_live_oop(q, size));
0N/A compact_top += size;
0N/A
0N/A // we need to update the offset table so that the beginnings of objects can be
0N/A // found during scavenge. Note that we are updating the offset table based on
0N/A // where the object will be once the compaction phase finishes.
0N/A if (compact_top > cp->threshold)
0N/A cp->threshold =
0N/A cp->space->cross_threshold(compact_top - size, compact_top);
0N/A return compact_top;
0N/A}
0N/A
0N/A
0N/Abool CompactibleSpace::insert_deadspace(size_t& allowed_deadspace_words,
0N/A HeapWord* q, size_t deadlength) {
0N/A if (allowed_deadspace_words >= deadlength) {
0N/A allowed_deadspace_words -= deadlength;
481N/A CollectedHeap::fill_with_object(q, deadlength);
481N/A oop(q)->set_mark(oop(q)->mark()->set_marked());
481N/A assert((int) deadlength == oop(q)->size(), "bad filler object size");
0N/A // Recall that we required "q == compaction_top".
0N/A return true;
0N/A } else {
0N/A allowed_deadspace_words = 0;
0N/A return false;
0N/A }
0N/A}
0N/A
0N/A#define block_is_always_obj(q) true
0N/A#define obj_size(q) oop(q)->size()
0N/A#define adjust_obj_size(s) s
0N/A
0N/Avoid CompactibleSpace::prepare_for_compaction(CompactPoint* cp) {
0N/A SCAN_AND_FORWARD(cp, end, block_is_obj, block_size);
0N/A}
0N/A
0N/A// Faster object search.
0N/Avoid ContiguousSpace::prepare_for_compaction(CompactPoint* cp) {
0N/A SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
0N/A}
0N/A
0N/Avoid Space::adjust_pointers() {
0N/A // adjust all the interior pointers to point at the new locations of objects
0N/A // Used by MarkSweep::mark_sweep_phase3()
0N/A
0N/A // First check to see if there is any work to be done.
0N/A if (used() == 0) {
0N/A return; // Nothing to do.
0N/A }
0N/A
0N/A // Otherwise...
0N/A HeapWord* q = bottom();
0N/A HeapWord* t = end();
0N/A
0N/A debug_only(HeapWord* prev_q = NULL);
0N/A while (q < t) {
0N/A if (oop(q)->is_gc_marked()) {
0N/A // q is alive
0N/A
113N/A VALIDATE_MARK_SWEEP_ONLY(MarkSweep::track_interior_pointers(oop(q)));
0N/A // point all the oops to the new location
0N/A size_t size = oop(q)->adjust_pointers();
113N/A VALIDATE_MARK_SWEEP_ONLY(MarkSweep::check_interior_pointers());
0N/A
0N/A debug_only(prev_q = q);
113N/A VALIDATE_MARK_SWEEP_ONLY(MarkSweep::validate_live_oop(oop(q), size));
0N/A
0N/A q += size;
0N/A } else {
0N/A // q is not a live object. But we're not in a compactible space,
0N/A // So we don't have live ranges.
0N/A debug_only(prev_q = q);
0N/A q += block_size(q);
0N/A assert(q > prev_q, "we should be moving forward through memory");
0N/A }
0N/A }
0N/A assert(q == t, "just checking");
0N/A}
0N/A
0N/Avoid CompactibleSpace::adjust_pointers() {
0N/A // Check first is there is any work to do.
0N/A if (used() == 0) {
0N/A return; // Nothing to do.
0N/A }
0N/A
0N/A SCAN_AND_ADJUST_POINTERS(adjust_obj_size);
0N/A}
0N/A
0N/Avoid CompactibleSpace::compact() {
0N/A SCAN_AND_COMPACT(obj_size);
0N/A}
0N/A
0N/Avoid Space::print_short() const { print_short_on(tty); }
0N/A
0N/Avoid Space::print_short_on(outputStream* st) const {
0N/A st->print(" space " SIZE_FORMAT "K, %3d%% used", capacity() / K,
0N/A (int) ((double) used() * 100 / capacity()));
0N/A}
0N/A
0N/Avoid Space::print() const { print_on(tty); }
0N/A
0N/Avoid Space::print_on(outputStream* st) const {
0N/A print_short_on(st);
0N/A st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ")",
0N/A bottom(), end());
0N/A}
0N/A
0N/Avoid ContiguousSpace::print_on(outputStream* st) const {
0N/A print_short_on(st);
0N/A st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")",
0N/A bottom(), top(), end());
0N/A}
0N/A
0N/Avoid OffsetTableContigSpace::print_on(outputStream* st) const {
0N/A print_short_on(st);
0N/A st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", "
0N/A INTPTR_FORMAT ", " INTPTR_FORMAT ")",
0N/A bottom(), top(), _offsets.threshold(), end());
0N/A}
0N/A
3679N/Avoid ContiguousSpace::verify() const {
0N/A HeapWord* p = bottom();
0N/A HeapWord* t = top();
0N/A HeapWord* prev_p = NULL;
0N/A while (p < t) {
0N/A oop(p)->verify();
0N/A prev_p = p;
0N/A p += oop(p)->size();
0N/A }
0N/A guarantee(p == top(), "end of last object must match end of space");
0N/A if (top() != end()) {
342N/A guarantee(top() == block_start_const(end()-1) &&
342N/A top() == block_start_const(top()),
0N/A "top should be start of unallocated block, if it exists");
0N/A }
0N/A}
0N/A
0N/Avoid Space::oop_iterate(OopClosure* blk) {
0N/A ObjectToOopClosure blk2(blk);
0N/A object_iterate(&blk2);
0N/A}
0N/A
0N/AHeapWord* Space::object_iterate_careful(ObjectClosureCareful* cl) {
0N/A guarantee(false, "NYI");
0N/A return bottom();
0N/A}
0N/A
0N/AHeapWord* Space::object_iterate_careful_m(MemRegion mr,
0N/A ObjectClosureCareful* cl) {
0N/A guarantee(false, "NYI");
0N/A return bottom();
0N/A}
0N/A
0N/A
0N/Avoid Space::object_iterate_mem(MemRegion mr, UpwardsObjectClosure* cl) {
0N/A assert(!mr.is_empty(), "Should be non-empty");
0N/A // We use MemRegion(bottom(), end()) rather than used_region() below
0N/A // because the two are not necessarily equal for some kinds of
0N/A // spaces, in particular, certain kinds of free list spaces.
0N/A // We could use the more complicated but more precise:
0N/A // MemRegion(used_region().start(), round_to(used_region().end(), CardSize))
0N/A // but the slight imprecision seems acceptable in the assertion check.
0N/A assert(MemRegion(bottom(), end()).contains(mr),
0N/A "Should be within used space");
0N/A HeapWord* prev = cl->previous(); // max address from last time
0N/A if (prev >= mr.end()) { // nothing to do
0N/A return;
0N/A }
0N/A // This assert will not work when we go from cms space to perm
0N/A // space, and use same closure. Easy fix deferred for later. XXX YSR
0N/A // assert(prev == NULL || contains(prev), "Should be within space");
0N/A
0N/A bool last_was_obj_array = false;
0N/A HeapWord *blk_start_addr, *region_start_addr;
0N/A if (prev > mr.start()) {
0N/A region_start_addr = prev;
0N/A blk_start_addr = prev;
518N/A // The previous invocation may have pushed "prev" beyond the
518N/A // last allocated block yet there may be still be blocks
518N/A // in this region due to a particular coalescing policy.
518N/A // Relax the assertion so that the case where the unallocated
518N/A // block is maintained and "prev" is beyond the unallocated
518N/A // block does not cause the assertion to fire.
518N/A assert((BlockOffsetArrayUseUnallocatedBlock &&
518N/A (!is_in(prev))) ||
518N/A (blk_start_addr == block_start(region_start_addr)), "invariant");
0N/A } else {
0N/A region_start_addr = mr.start();
0N/A blk_start_addr = block_start(region_start_addr);
0N/A }
0N/A HeapWord* region_end_addr = mr.end();
0N/A MemRegion derived_mr(region_start_addr, region_end_addr);
0N/A while (blk_start_addr < region_end_addr) {
0N/A const size_t size = block_size(blk_start_addr);
0N/A if (block_is_obj(blk_start_addr)) {
0N/A last_was_obj_array = cl->do_object_bm(oop(blk_start_addr), derived_mr);
0N/A } else {
0N/A last_was_obj_array = false;
0N/A }
0N/A blk_start_addr += size;
0N/A }
0N/A if (!last_was_obj_array) {
0N/A assert((bottom() <= blk_start_addr) && (blk_start_addr <= end()),
0N/A "Should be within (closed) used space");
0N/A assert(blk_start_addr > prev, "Invariant");
0N/A cl->set_previous(blk_start_addr); // min address for next time
0N/A }
0N/A}
0N/A
0N/Abool Space::obj_is_alive(const HeapWord* p) const {
0N/A assert (block_is_obj(p), "The address should point to an object");
0N/A return true;
0N/A}
0N/A
0N/Avoid ContiguousSpace::object_iterate_mem(MemRegion mr, UpwardsObjectClosure* cl) {
0N/A assert(!mr.is_empty(), "Should be non-empty");
0N/A assert(used_region().contains(mr), "Should be within used space");
0N/A HeapWord* prev = cl->previous(); // max address from last time
0N/A if (prev >= mr.end()) { // nothing to do
0N/A return;
0N/A }
0N/A // See comment above (in more general method above) in case you
0N/A // happen to use this method.
0N/A assert(prev == NULL || is_in_reserved(prev), "Should be within space");
0N/A
0N/A bool last_was_obj_array = false;
0N/A HeapWord *obj_start_addr, *region_start_addr;
0N/A if (prev > mr.start()) {
0N/A region_start_addr = prev;
0N/A obj_start_addr = prev;
0N/A assert(obj_start_addr == block_start(region_start_addr), "invariant");
0N/A } else {
0N/A region_start_addr = mr.start();
0N/A obj_start_addr = block_start(region_start_addr);
0N/A }
0N/A HeapWord* region_end_addr = mr.end();
0N/A MemRegion derived_mr(region_start_addr, region_end_addr);
0N/A while (obj_start_addr < region_end_addr) {
0N/A oop obj = oop(obj_start_addr);
0N/A const size_t size = obj->size();
0N/A last_was_obj_array = cl->do_object_bm(obj, derived_mr);
0N/A obj_start_addr += size;
0N/A }
0N/A if (!last_was_obj_array) {
0N/A assert((bottom() <= obj_start_addr) && (obj_start_addr <= end()),
0N/A "Should be within (closed) used space");
0N/A assert(obj_start_addr > prev, "Invariant");
0N/A cl->set_previous(obj_start_addr); // min address for next time
0N/A }
0N/A}
0N/A
0N/A#ifndef SERIALGC
0N/A#define ContigSpace_PAR_OOP_ITERATE_DEFN(OopClosureType, nv_suffix) \
0N/A \
0N/A void ContiguousSpace::par_oop_iterate(MemRegion mr, OopClosureType* blk) {\
0N/A HeapWord* obj_addr = mr.start(); \
0N/A HeapWord* t = mr.end(); \
0N/A while (obj_addr < t) { \
0N/A assert(oop(obj_addr)->is_oop(), "Should be an oop"); \
0N/A obj_addr += oop(obj_addr)->oop_iterate(blk); \
0N/A } \
0N/A }
0N/A
0N/A ALL_PAR_OOP_ITERATE_CLOSURES(ContigSpace_PAR_OOP_ITERATE_DEFN)
0N/A
0N/A#undef ContigSpace_PAR_OOP_ITERATE_DEFN
0N/A#endif // SERIALGC
0N/A
0N/Avoid ContiguousSpace::oop_iterate(OopClosure* blk) {
0N/A if (is_empty()) return;
0N/A HeapWord* obj_addr = bottom();
0N/A HeapWord* t = top();
0N/A // Could call objects iterate, but this is easier.
0N/A while (obj_addr < t) {
0N/A obj_addr += oop(obj_addr)->oop_iterate(blk);
0N/A }
0N/A}
0N/A
0N/Avoid ContiguousSpace::oop_iterate(MemRegion mr, OopClosure* blk) {
0N/A if (is_empty()) {
0N/A return;
0N/A }
0N/A MemRegion cur = MemRegion(bottom(), top());
0N/A mr = mr.intersection(cur);
0N/A if (mr.is_empty()) {
0N/A return;
0N/A }
0N/A if (mr.equals(cur)) {
0N/A oop_iterate(blk);
0N/A return;
0N/A }
0N/A assert(mr.end() <= top(), "just took an intersection above");
0N/A HeapWord* obj_addr = block_start(mr.start());
0N/A HeapWord* t = mr.end();
0N/A
0N/A // Handle first object specially.
0N/A oop obj = oop(obj_addr);
0N/A SpaceMemRegionOopsIterClosure smr_blk(blk, mr);
0N/A obj_addr += obj->oop_iterate(&smr_blk);
0N/A while (obj_addr < t) {
0N/A oop obj = oop(obj_addr);
0N/A assert(obj->is_oop(), "expected an oop");
0N/A obj_addr += obj->size();
0N/A // If "obj_addr" is not greater than top, then the
0N/A // entire object "obj" is within the region.
0N/A if (obj_addr <= t) {
0N/A obj->oop_iterate(blk);
0N/A } else {
0N/A // "obj" extends beyond end of region
0N/A obj->oop_iterate(&smr_blk);
0N/A break;
0N/A }
0N/A };
0N/A}
0N/A
0N/Avoid ContiguousSpace::object_iterate(ObjectClosure* blk) {
0N/A if (is_empty()) return;
0N/A WaterMark bm = bottom_mark();
0N/A object_iterate_from(bm, blk);
0N/A}
0N/A
517N/A// For a continguous space object_iterate() and safe_object_iterate()
517N/A// are the same.
517N/Avoid ContiguousSpace::safe_object_iterate(ObjectClosure* blk) {
517N/A object_iterate(blk);
517N/A}
517N/A
0N/Avoid ContiguousSpace::object_iterate_from(WaterMark mark, ObjectClosure* blk) {
0N/A assert(mark.space() == this, "Mark does not match space");
0N/A HeapWord* p = mark.point();
0N/A while (p < top()) {
0N/A blk->do_object(oop(p));
0N/A p += oop(p)->size();
0N/A }
0N/A}
0N/A
0N/AHeapWord*
0N/AContiguousSpace::object_iterate_careful(ObjectClosureCareful* blk) {
0N/A HeapWord * limit = concurrent_iteration_safe_limit();
0N/A assert(limit <= top(), "sanity check");
0N/A for (HeapWord* p = bottom(); p < limit;) {
0N/A size_t size = blk->do_object_careful(oop(p));
0N/A if (size == 0) {
0N/A return p; // failed at p
0N/A } else {
0N/A p += size;
0N/A }
0N/A }
0N/A return NULL; // all done
0N/A}
0N/A
0N/A#define ContigSpace_OOP_SINCE_SAVE_MARKS_DEFN(OopClosureType, nv_suffix) \
0N/A \
0N/Avoid ContiguousSpace:: \
0N/Aoop_since_save_marks_iterate##nv_suffix(OopClosureType* blk) { \
0N/A HeapWord* t; \
0N/A HeapWord* p = saved_mark_word(); \
0N/A assert(p != NULL, "expected saved mark"); \
0N/A \
0N/A const intx interval = PrefetchScanIntervalInBytes; \
0N/A do { \
0N/A t = top(); \
0N/A while (p < t) { \
0N/A Prefetch::write(p, interval); \
0N/A debug_only(HeapWord* prev = p); \
0N/A oop m = oop(p); \
0N/A p += m->oop_iterate(blk); \
0N/A } \
0N/A } while (t < top()); \
0N/A \
0N/A set_saved_mark_word(p); \
0N/A}
0N/A
0N/AALL_SINCE_SAVE_MARKS_CLOSURES(ContigSpace_OOP_SINCE_SAVE_MARKS_DEFN)
0N/A
0N/A#undef ContigSpace_OOP_SINCE_SAVE_MARKS_DEFN
0N/A
0N/A// Very general, slow implementation.
342N/AHeapWord* ContiguousSpace::block_start_const(const void* p) const {
4080N/A assert(MemRegion(bottom(), end()).contains(p),
4080N/A err_msg("p (" PTR_FORMAT ") not in space [" PTR_FORMAT ", " PTR_FORMAT ")",
4080N/A p, bottom(), end()));
0N/A if (p >= top()) {
0N/A return top();
0N/A } else {
0N/A HeapWord* last = bottom();
0N/A HeapWord* cur = last;
0N/A while (cur <= p) {
0N/A last = cur;
0N/A cur += oop(cur)->size();
0N/A }
4080N/A assert(oop(last)->is_oop(),
4080N/A err_msg(PTR_FORMAT " should be an object start", last));
0N/A return last;
0N/A }
0N/A}
0N/A
0N/Asize_t ContiguousSpace::block_size(const HeapWord* p) const {
4080N/A assert(MemRegion(bottom(), end()).contains(p),
4080N/A err_msg("p (" PTR_FORMAT ") not in space [" PTR_FORMAT ", " PTR_FORMAT ")",
4080N/A p, bottom(), end()));
0N/A HeapWord* current_top = top();
4080N/A assert(p <= current_top,
4080N/A err_msg("p > current top - p: " PTR_FORMAT ", current top: " PTR_FORMAT,
4080N/A p, current_top));
4080N/A assert(p == current_top || oop(p)->is_oop(),
4080N/A err_msg("p (" PTR_FORMAT ") is not a block start - "
4080N/A "current_top: " PTR_FORMAT ", is_oop: %s",
4080N/A p, current_top, BOOL_TO_STR(oop(p)->is_oop())));
4080N/A if (p < current_top) {
0N/A return oop(p)->size();
4080N/A } else {
0N/A assert(p == current_top, "just checking");
0N/A return pointer_delta(end(), (HeapWord*) p);
0N/A }
0N/A}
0N/A
0N/A// This version requires locking.
0N/Ainline HeapWord* ContiguousSpace::allocate_impl(size_t size,
0N/A HeapWord* const end_value) {
2280N/A // In G1 there are places where a GC worker can allocates into a
2280N/A // region using this serial allocation code without being prone to a
2280N/A // race with other GC workers (we ensure that no other GC worker can
2280N/A // access the same region at the same time). So the assert below is
2280N/A // too strong in the case of G1.
0N/A assert(Heap_lock->owned_by_self() ||
0N/A (SafepointSynchronize::is_at_safepoint() &&
2280N/A (Thread::current()->is_VM_thread() || UseG1GC)),
0N/A "not locked");
0N/A HeapWord* obj = top();
0N/A if (pointer_delta(end_value, obj) >= size) {
0N/A HeapWord* new_top = obj + size;
0N/A set_top(new_top);
0N/A assert(is_aligned(obj) && is_aligned(new_top), "checking alignment");
0N/A return obj;
0N/A } else {
0N/A return NULL;
0N/A }
0N/A}
0N/A
0N/A// This version is lock-free.
0N/Ainline HeapWord* ContiguousSpace::par_allocate_impl(size_t size,
0N/A HeapWord* const end_value) {
0N/A do {
0N/A HeapWord* obj = top();
0N/A if (pointer_delta(end_value, obj) >= size) {
0N/A HeapWord* new_top = obj + size;
0N/A HeapWord* result = (HeapWord*)Atomic::cmpxchg_ptr(new_top, top_addr(), obj);
0N/A // result can be one of two:
0N/A // the old top value: the exchange succeeded
0N/A // otherwise: the new value of the top is returned.
0N/A if (result == obj) {
0N/A assert(is_aligned(obj) && is_aligned(new_top), "checking alignment");
0N/A return obj;
0N/A }
0N/A } else {
0N/A return NULL;
0N/A }
0N/A } while (true);
0N/A}
0N/A
0N/A// Requires locking.
0N/AHeapWord* ContiguousSpace::allocate(size_t size) {
0N/A return allocate_impl(size, end());
0N/A}
0N/A
0N/A// Lock-free.
0N/AHeapWord* ContiguousSpace::par_allocate(size_t size) {
0N/A return par_allocate_impl(size, end());
0N/A}
0N/A
0N/Avoid ContiguousSpace::allocate_temporary_filler(int factor) {
0N/A // allocate temporary type array decreasing free size with factor 'factor'
0N/A assert(factor >= 0, "just checking");
0N/A size_t size = pointer_delta(end(), top());
0N/A
0N/A // if space is full, return
0N/A if (size == 0) return;
0N/A
0N/A if (factor > 0) {
0N/A size -= size/factor;
0N/A }
0N/A size = align_object_size(size);
0N/A
1491N/A const size_t array_header_size = typeArrayOopDesc::header_size(T_INT);
1491N/A if (size >= (size_t)align_object_size(array_header_size)) {
1491N/A size_t length = (size - array_header_size) * (HeapWordSize / sizeof(jint));
0N/A // allocate uninitialized int array
0N/A typeArrayOop t = (typeArrayOop) allocate(size);
0N/A assert(t != NULL, "allocation should succeed");
0N/A t->set_mark(markOopDesc::prototype());
0N/A t->set_klass(Universe::intArrayKlassObj());
0N/A t->set_length((int)length);
0N/A } else {
1491N/A assert(size == CollectedHeap::min_fill_size(),
0N/A "size for smallest fake object doesn't match");
0N/A instanceOop obj = (instanceOop) allocate(size);
0N/A obj->set_mark(markOopDesc::prototype());
167N/A obj->set_klass_gap(0);
1142N/A obj->set_klass(SystemDictionary::Object_klass());
0N/A }
0N/A}
0N/A
263N/Avoid EdenSpace::clear(bool mangle_space) {
263N/A ContiguousSpace::clear(mangle_space);
0N/A set_soft_end(end());
0N/A}
0N/A
0N/A// Requires locking.
0N/AHeapWord* EdenSpace::allocate(size_t size) {
0N/A return allocate_impl(size, soft_end());
0N/A}
0N/A
0N/A// Lock-free.
0N/AHeapWord* EdenSpace::par_allocate(size_t size) {
0N/A return par_allocate_impl(size, soft_end());
0N/A}
0N/A
0N/AHeapWord* ConcEdenSpace::par_allocate(size_t size)
0N/A{
0N/A do {
0N/A // The invariant is top() should be read before end() because
0N/A // top() can't be greater than end(), so if an update of _soft_end
0N/A // occurs between 'end_val = end();' and 'top_val = top();' top()
0N/A // also can grow up to the new end() and the condition
0N/A // 'top_val > end_val' is true. To ensure the loading order
0N/A // OrderAccess::loadload() is required after top() read.
0N/A HeapWord* obj = top();
0N/A OrderAccess::loadload();
0N/A if (pointer_delta(*soft_end_addr(), obj) >= size) {
0N/A HeapWord* new_top = obj + size;
0N/A HeapWord* result = (HeapWord*)Atomic::cmpxchg_ptr(new_top, top_addr(), obj);
0N/A // result can be one of two:
0N/A // the old top value: the exchange succeeded
0N/A // otherwise: the new value of the top is returned.
0N/A if (result == obj) {
0N/A assert(is_aligned(obj) && is_aligned(new_top), "checking alignment");
0N/A return obj;
0N/A }
0N/A } else {
0N/A return NULL;
0N/A }
0N/A } while (true);
0N/A}
0N/A
0N/A
0N/AHeapWord* OffsetTableContigSpace::initialize_threshold() {
0N/A return _offsets.initialize_threshold();
0N/A}
0N/A
0N/AHeapWord* OffsetTableContigSpace::cross_threshold(HeapWord* start, HeapWord* end) {
0N/A _offsets.alloc_block(start, end);
0N/A return _offsets.threshold();
0N/A}
0N/A
0N/AOffsetTableContigSpace::OffsetTableContigSpace(BlockOffsetSharedArray* sharedOffsetArray,
0N/A MemRegion mr) :
0N/A _offsets(sharedOffsetArray, mr),
0N/A _par_alloc_lock(Mutex::leaf, "OffsetTableContigSpace par alloc lock", true)
0N/A{
0N/A _offsets.set_contig_space(this);
263N/A initialize(mr, SpaceDecorator::Clear, SpaceDecorator::Mangle);
0N/A}
0N/A
0N/A#define OBJ_SAMPLE_INTERVAL 0
0N/A#define BLOCK_SAMPLE_INTERVAL 100
0N/A
3679N/Avoid OffsetTableContigSpace::verify() const {
0N/A HeapWord* p = bottom();
0N/A HeapWord* prev_p = NULL;
0N/A int objs = 0;
0N/A int blocks = 0;
0N/A
0N/A if (VerifyObjectStartArray) {
0N/A _offsets.verify();
0N/A }
0N/A
0N/A while (p < top()) {
0N/A size_t size = oop(p)->size();
0N/A // For a sampling of objects in the space, find it using the
0N/A // block offset table.
0N/A if (blocks == BLOCK_SAMPLE_INTERVAL) {
342N/A guarantee(p == block_start_const(p + (size/2)),
342N/A "check offset computation");
0N/A blocks = 0;
0N/A } else {
0N/A blocks++;
0N/A }
0N/A
0N/A if (objs == OBJ_SAMPLE_INTERVAL) {
0N/A oop(p)->verify();
0N/A objs = 0;
0N/A } else {
0N/A objs++;
0N/A }
0N/A prev_p = p;
0N/A p += size;
0N/A }
0N/A guarantee(p == top(), "end of last object must match end of space");
0N/A}
0N/A
0N/Avoid OffsetTableContigSpace::serialize_block_offset_array_offsets(
0N/A SerializeOopClosure* soc) {
0N/A _offsets.serialize(soc);
0N/A}
0N/A
0N/A
438N/Asize_t TenuredSpace::allowed_dead_ratio() const {
0N/A return MarkSweepDeadRatio;
0N/A}
0N/A
0N/A
438N/Asize_t ContigPermSpace::allowed_dead_ratio() const {
0N/A return PermMarkSweepDeadRatio;
0N/A}