space.cpp revision 167
4632N/A * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. 4632N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4632N/A * This code is free software; you can redistribute it and/or modify it 4632N/A * under the terms of the GNU General Public License version 2 only, as 4632N/A * published by the Free Software Foundation. 4632N/A * This code is distributed in the hope that it will be useful, but WITHOUT 4632N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4632N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4632N/A * version 2 for more details (a copy is included in the LICENSE file that 4632N/A * You should have received a copy of the GNU General Public License version 4632N/A * 2 along with this work; if not, write to the Free Software Foundation, 4632N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4632N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 4632N/A * CA 95054 USA or visit www.sun.com if you need additional information or 4632N/A#
include "incls/_precompiled.incl" 4632N/A // An arrayOop is starting on the dirty card - since we do exact 4632N/A // store checks for objArrays we are done. 5331N/A // Otherwise, it is possible that the object starting on the dirty 4632N/A // card spans the entire card, and that the store happened on a 4632N/A // later card. Figure out where the object ends. 4632N/A // Use the block_size() method of the space over which 4632N/A // the iteration is being done. That space (e.g. CMS) may have 4632N/A // specific requirements on object sizes which will 4632N/A // be reflected in the block_size() method. 4632N/A // 1. Blocks may or may not be objects. 4632N/A // 2. Even when a block_is_obj(), it may not entirely 4632N/A // occupy the block if the block quantum is larger than 4632N/A // We can and should try to optimize by calling the non-MemRegion 4632N/A // version of oop_iterate() for all but the extremal objects 4632N/A // (for which we need to call the MemRegion version of 4632N/A // oop_iterate()) To be done post-beta XXX 4632N/A // As in the case of contiguous space above, we'd like to 4632N/A // just use the value returned by oop_iterate to increment the 4632N/A // current pointer; unfortunately, that won't work in CMS because 4632N/A // we'd need an interface change (it seems) to have the space 4632N/A // "adjust the object size" (for instance pad it up to its 4632N/A // block alignment or minimum block size restrictions. XXX 4632N/A // Some collectors need to do special things whenever their dirty 4632N/A // cards are processed. For instance, CMS must remember mutator updates 4632N/A // (i.e. dirty cards) so as to re-scan mutated objects. 4632N/A // Such work can be piggy-backed here on dirty card scanning, so as to make 4632N/A // it slightly more efficient than doing a complete non-detructive pre-scan 4632N/A "Only ones we deal with for now.");
4632N/A // Given what we think is the top of the memory region and 4632N/A // the start of the object at the top, get the actual 4632N/A // If the previous call did some part of this region, don't redo. 4632N/A // Top may have been reset, and in fact may be below bottom, 4632N/A // e.g. the dirty card region is entirely in a now free object 4632N/A // -- something that could happen with a concurrent sweeper. 4632N/A // Walk the region if it is not empty; otherwise there is nothing to do. 4632N/A // An arrayOop is starting on the dirty card - since we do exact 4632N/A // store checks for objArrays we are done. 4632N/A // Otherwise, it is possible that the object starting on the dirty 4632N/A // card spans the entire card, and that the store happened on a 4632N/A // later card. Figure out where the object ends. 4632N/A "Block size and object size mismatch");
4632N/A // Note that this assumption won't hold if we have a concurrent 4632N/A // collector in this space, which may have freed up objects after 4632N/A // they were dirtied and before the stop-the-world GC that is 4632N/A // We have a boundary outside of which we don't want to look 4632N/A // at objects, so create a filtering closure around the 4632N/A // oop closure before walking the region. 4632N/A // No boundary, simply walk the heap with the oop closure. 4632N/A// We must replicate this so that the static type of "FilteringClosure" 4632N/A// (see above) is apparent at the oop_iterate calls. 4632N/A /* Bottom lies entirely below top, so we can call the */ \
4632N/A /* non-memRegion version of oop_iterate below. */ \
4632N/A// (There are only two of these, rather than N, because the split is due 4632N/A// only to the introduction of the FilteringClosure, a local part of the 4632N/A// impl of this abstraction.) 4632N/A "invalid space boundaries");
4632N/A // Space should not advertize an increase in size 4632N/A // until after the underlying offest table has been enlarged. 4632N/A // to-space is used for storing marks during mark-sweep 4632N/A // First check if we should switch compaction space 4632N/A // switch to next compaction space 4632N/A // store the forwarding pointer into the mark word 4632N/A // if the object isn't moving we can just set the mark to the default 4632N/A // mark and handle it specially later on. 4632N/A // we need to update the offset table so that the beginnings of objects can be 4632N/A // found during scavenge. Note that we are updating the offset table based on 4632N/A // where the object will be once the compaction phase finishes. 4632N/A "size for smallest fake dead object doesn't match");
4632N/A "make sure size for fake dead object match");
4632N/A // Recall that we required "q == compaction_top". // 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. return;
// Nothing to do. // point all the oops to the new location // q is not a live object. But we're not in a compactible space, // So we don't have live ranges. assert(q >
prev_q,
"we should be moving forward through memory");
assert(q == t,
"just checking");
// Check first is there is any work to do. return;
// Nothing to do. guarantee(p ==
top(),
"end of last object must match end of space");
"top should be start of unallocated block, if it exists");
// 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");
// 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"); "Should be within (closed) used space");
// See comment above (in more general method above) in case you // happen to use this method. "Should be within (closed) used space");
// Could call objects iterate, but this is easier. // Handle first object specially. // If "obj_addr" is not greater than top, then the // entire object "obj" is within the region. // "obj" extends beyond end of region // Very general, slow implementation. // This version requires locking. // This version is lock-free. // result can be one of two: // the old top value: the exchange succeeded // otherwise: the new value of the top is returned. // allocate temporary type array decreasing free size with factor 'factor' // if space is full, return // allocate uninitialized int array "size for smallest fake object doesn't match");
// 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. // result can be one of two: // the old top value: the exchange succeeded // otherwise: the new value of the top is returned. // For a sampling of objects in the space, find it using the guarantee(p ==
top(),
"end of last object must match end of space");