use of org.mmtk.utility.ForwardingWord in project JikesRVM by JikesRVM.
the class CopySpace method traceObject.
/**
* Trace an object under a copying collection policy.<p>
*
* We use a tri-state algorithm to deal with races to forward
* the object. The tracer must wait if the object is concurrently
* being forwarded by another thread.<p>
*
* If the object is already forwarded, the copy is returned.
* Otherwise, the object is forwarded and the copy is returned.
*
* @param trace The trace being conducted.
* @param object The object to be forwarded.
* @param allocator The allocator to use when copying.
* @return The forwarded object.
*/
@Inline
public ObjectReference traceObject(TransitiveClosure trace, ObjectReference object, int allocator) {
/* If the object in question is already in to-space, then do nothing */
if (!fromSpace)
return object;
/* Try to forward the object */
Word forwardingWord = ForwardingWord.attemptToForward(object);
if (ForwardingWord.stateIsForwardedOrBeingForwarded(forwardingWord)) {
/* We must wait (spin) if the object is not yet fully forwarded */
while (ForwardingWord.stateIsBeingForwarded(forwardingWord)) forwardingWord = VM.objectModel.readAvailableBitsWord(object);
/* Now extract the object reference from the forwarding word and return it */
return ForwardingWord.extractForwardingPointer(forwardingWord);
} else {
/* We are the designated copier, so forward it and enqueue it */
ObjectReference newObject = VM.objectModel.copy(object, allocator);
ForwardingWord.setForwardingPointer(object, newObject);
// Scan it later
trace.processNode(newObject);
if (VM.VERIFY_ASSERTIONS && Options.verbose.getValue() >= 9) {
Log.write("C[");
Log.write(object);
Log.write("/");
Log.write(getName());
Log.write("] -> ");
Log.write(newObject);
Log.write("/");
Log.write(Space.getSpaceForObject(newObject).getName());
Log.writeln("]");
}
return newObject;
}
}
Aggregations