/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "classfile/systemDictionary.hpp"
#include "classfile/vmSymbols.hpp"
#include "gc_implementation/shared/liveRange.hpp"
#include "gc_implementation/shared/markSweep.hpp"
#include "gc_implementation/shared/spaceDecorator.hpp"
#include "memory/blockOffsetTable.inline.hpp"
#include "memory/defNewGeneration.hpp"
#include "memory/genCollectedHeap.hpp"
#include "memory/space.inline.hpp"
#include "memory/universe.inline.hpp"
#include "oops/oop.inline.hpp"
#include "oops/oop.inline2.hpp"
#include "runtime/safepoint.hpp"
#include "utilities/globalDefinitions.hpp"
void SpaceMemRegionOopsIterClosure::do_oop(oop* p) { SpaceMemRegionOopsIterClosure::do_oop_work(p); }
void SpaceMemRegionOopsIterClosure::do_oop(narrowOop* p) { SpaceMemRegionOopsIterClosure::do_oop_work(p); }
// An arrayOop is starting on the dirty card - since we do exact
// store checks for objArrays we are done.
} else {
// Otherwise, it is possible that the object starting on the dirty
// card spans the entire card, and that the store happened on a
// later card. Figure out where the object ends.
// Use the block_size() method of the space over which
// the iteration is being done. That space (e.g. CMS) may have
// specific requirements on object sizes which will
// be reflected in the block_size() method.
}
}
} else {
}
} else {
}
return top;
}
// 1. Blocks may or may not be objects.
// 2. Even when a block_is_obj(), it may not entirely
// occupy the block if the block quantum is larger than
// the object size.
// We can and should try to optimize by calling the non-MemRegion
// version of oop_iterate() for all but the extremal objects
// (for which we need to call the MemRegion version of
// oop_iterate()) To be done post-beta XXX
// As in the case of contiguous space above, we'd like to
// just use the value returned by oop_iterate to increment the
// current pointer; unfortunately, that won't work in CMS because
// we'd need an interface change (it seems) to have the space
// "adjust the object size" (for instance pad it up to its
// block alignment or minimum block size restrictions. XXX
}
}
}
// We get called with "mr" representing the dirty region
// that we want to process. Because of imprecise marking,
// we may need to extend the incoming "mr" to the right,
// and scan more. However, because we may already have
// scanned some of that extended region, we may need to
// trim its right-end back some so we do not scan what
// we (or another worker thread) may already have scanned
// or planning to scan.
// Some collectors need to do special things whenever their dirty
// cards are processed. For instance, CMS must remember mutator updates
// (i.e. dirty cards) so as to re-scan mutated objects.
// Such work can be piggy-backed here on dirty card scanning, so as to make
// it slightly more efficient than doing a complete non-detructive pre-scan
// of the card table.
}
"Only ones we deal with for now.");
top <= _last_bottom,
"Not decreasing");
// Given what we think is the top of the memory region and
// the start of the object at the top, get the actual
// value of the top.
// If the previous call did some part of this region, don't redo.
}
// Top may have been reset, and in fact may be below bottom,
// e.g. the dirty card region is entirely in a now free object
// -- something that could happen with a concurrent sweeper.
"overlap!");
// Walk the region if it is not empty; otherwise there is nothing to do.
if (!extended_mr.is_empty()) {
}
// An idempotent closure might be applied in any order, so we don't
// record a _min_done for it.
if (!_cl->idempotent()) {
} else {
"Don't update _min_done for idempotent cl");
}
}
}
// An arrayOop is starting on the dirty card - since we do exact
// store checks for objArrays we are done.
} else {
// Otherwise, it is possible that the object starting on the dirty
// card spans the entire card, and that the store happened on a
// later card. Figure out where the object ends.
"Block size and object size mismatch");
}
}
} else {
}
return top;
}
// Note that this assumption won't hold if we have a concurrent
// collector in this space, which may have freed up objects after
// they were dirtied and before the stop-the-world GC that is
// examining cards here.
// We have a boundary outside of which we don't want to look
// at objects, so create a filtering closure around the
// oop closure before walking the region.
} else {
// No boundary, simply walk the heap with the oop closure.
}
}
// We must replicate this so that the static type of "FilteringClosure"
// (see above) is apparent at the oop_iterate calls.
ClosureType* cl) { \
/* Bottom lies entirely below top, so we can call the */ \
/* non-memRegion version of oop_iterate below. */ \
} \
/* Last object. */ \
} \
}
// (There are only two of these, rather than N, because the split is due
// only to the introduction of the FilteringClosure, a local part of the
// impl of this abstraction.)
}
bool clear_space,
bool mangle_space) {
"invalid space boundaries");
}
if (ZapUnusedHeapArea && mangle_space) {
}
}
_mangler = new GenSpaceMangler(this);
}
delete _mangler;
}
bool clear_space,
bool mangle_space)
{
}
}
bool ContiguousSpace::is_in(const void* p) const {
}
return p >= _top;
}
}
}
// Space should not advertize an increase in size
// until after the underlying offest table has been enlarged.
}
#ifndef PRODUCT
mangler()->set_top_for_allocations(v);
}
void ContiguousSpace::set_top_for_allocations() {
}
}
}
// Mangled only the unused space that has not previously
// been mangled and that has not been allocated since being
// mangled.
mangler()->mangle_unused_area();
}
}
// Although this method uses SpaceMangler::mangle_region() which
// is not specific to a space, the when the ContiguousSpace version
// is called, it is always with regard to a space and this
// bounds checking is appropriate.
}
#endif // NOT_PRODUCT
bool clear_space,
bool mangle_space) {
}
_compaction_top = bottom();
}
// q is alive
// First check if we should switch compaction space
while (size > compaction_max_size) {
// switch to next compaction space
}
}
// store the forwarding pointer into the mark word
if ((HeapWord*)q != compact_top) {
} else {
// if the object isn't moving we can just set the mark to the default
// mark and handle it specially later on.
q->init_mark();
}
compact_top += size;
// we need to update the offset table so that the beginnings of objects can be
// found during scavenge. Note that we are updating the offset table based on
// where the object will be once the compaction phase finishes.
return compact_top;
}
if (allowed_deadspace_words >= deadlength) {
// Recall that we required "q == compaction_top".
return true;
} else {
return false;
}
}
#define block_is_always_obj(q) true
#define adjust_obj_size(s) s
}
// Faster object search.
}
// adjust all the interior pointers to point at the new locations of objects
// Used by MarkSweep::mark_sweep_phase3()
// First check to see if there is any work to be done.
if (used() == 0) {
return; // Nothing to do.
}
// Otherwise...
while (q < t) {
if (oop(q)->is_gc_marked()) {
// q is alive
// point all the oops to the new location
debug_only(prev_q = q);
q += size;
} else {
// q is not a live object. But we're not in a compactible space,
// So we don't have live ranges.
debug_only(prev_q = q);
q += block_size(q);
}
}
assert(q == t, "just checking");
}
// Check first is there is any work to do.
if (used() == 0) {
return; // Nothing to do.
}
}
}
}
}
}
}
while (p < t) {
prev_p = p;
}
"top should be start of unallocated block, if it exists");
}
}
}
guarantee(false, "NYI");
return bottom();
}
guarantee(false, "NYI");
return bottom();
}
// We use MemRegion(bottom(), end()) rather than used_region() below
// because the two are not necessarily equal for some kinds of
// spaces, in particular, certain kinds of free list spaces.
// We could use the more complicated but more precise:
// MemRegion(used_region().start(), round_to(used_region().end(), CardSize))
// but the slight imprecision seems acceptable in the assertion check.
"Should be within used space");
return;
}
// This assert will not work when we go from cms space to perm
// space, and use same closure. Easy fix deferred for later. XXX YSR
// assert(prev == NULL || contains(prev), "Should be within space");
bool last_was_obj_array = false;
// The previous invocation may have pushed "prev" beyond the
// last allocated block yet there may be still be blocks
// in this region due to a particular coalescing policy.
// Relax the assertion so that the case where the unallocated
// block is maintained and "prev" is beyond the unallocated
// block does not cause the assertion to fire.
} else {
}
while (blk_start_addr < region_end_addr) {
if (block_is_obj(blk_start_addr)) {
} else {
last_was_obj_array = false;
}
blk_start_addr += size;
}
if (!last_was_obj_array) {
"Should be within (closed) used space");
}
}
return true;
}
return;
}
// See comment above (in more general method above) in case you
// happen to use this method.
bool last_was_obj_array = false;
} else {
}
while (obj_start_addr < region_end_addr) {
obj_start_addr += size;
}
if (!last_was_obj_array) {
"Should be within (closed) used space");
}
}
#ifndef SERIALGC
\
while (obj_addr < t) { \
} \
}
#endif // SERIALGC
if (is_empty()) return;
// Could call objects iterate, but this is easier.
while (obj_addr < t) {
}
}
if (is_empty()) {
return;
}
return;
}
return;
}
// Handle first object specially.
while (obj_addr < t) {
// If "obj_addr" is not greater than top, then the
// entire object "obj" is within the region.
if (obj_addr <= t) {
} else {
// "obj" extends beyond end of region
break;
}
};
}
if (is_empty()) return;
}
// For a continguous space object_iterate() and safe_object_iterate()
// are the same.
}
while (p < top()) {
}
}
if (size == 0) {
return p; // failed at p
} else {
p += size;
}
}
return NULL; // all done
}
\
void ContiguousSpace:: \
HeapWord* t; \
HeapWord* p = saved_mark_word(); \
\
do { \
t = top(); \
while (p < t) { \
p += m->oop_iterate(blk); \
} \
} while (t < top()); \
\
set_saved_mark_word(p); \
}
// Very general, slow implementation.
if (p >= top()) {
return top();
} else {
while (cur <= p) {
}
return last;
}
}
assert(p <= current_top,
p, current_top));
if (p < current_top) {
} else {
}
}
// This version requires locking.
// In G1 there are places where a GC worker can allocates into a
// region using this serial allocation code without being prone to a
// race with other GC workers (we ensure that no other GC worker can
// access the same region at the same time). So the assert below is
// too strong in the case of G1.
"not locked");
return obj;
} else {
return NULL;
}
}
// This version is lock-free.
do {
// result can be one of two:
// the old top value: the exchange succeeded
// otherwise: the new value of the top is returned.
return obj;
}
} else {
return NULL;
}
} while (true);
}
// Requires locking.
}
// Lock-free.
}
// allocate temporary type array decreasing free size with factor 'factor'
// if space is full, return
if (size == 0) return;
if (factor > 0) {
}
// allocate uninitialized int array
t->set_length((int)length);
} else {
"size for smallest fake object doesn't match");
obj->set_klass_gap(0);
}
}
set_soft_end(end());
}
// Requires locking.
}
// Lock-free.
}
{
do {
// The invariant is top() should be read before end() because
// top() can't be greater than end(), so if an update of _soft_end
// occurs between 'end_val = end();' and 'top_val = top();' top()
// also can grow up to the new end() and the condition
// 'top_val > end_val' is true. To ensure the loading order
// OrderAccess::loadload() is required after top() read.
OrderAccess::loadload();
// result can be one of two:
// the old top value: the exchange succeeded
// otherwise: the new value of the top is returned.
return obj;
}
} else {
return NULL;
}
} while (true);
}
return _offsets.initialize_threshold();
}
}
{
_offsets.set_contig_space(this);
}
#define OBJ_SAMPLE_INTERVAL 0
int objs = 0;
int blocks = 0;
if (VerifyObjectStartArray) {
}
while (p < top()) {
// For a sampling of objects in the space, find it using the
// block offset table.
if (blocks == BLOCK_SAMPLE_INTERVAL) {
"check offset computation");
blocks = 0;
} else {
blocks++;
}
if (objs == OBJ_SAMPLE_INTERVAL) {
objs = 0;
} else {
objs++;
}
prev_p = p;
p += size;
}
}
}
return MarkSweepDeadRatio;
}
return PermMarkSweepDeadRatio;
}