use of org.mmtk.policy.Space in project JikesRVM by JikesRVM.
the class Allocator method allocSlowInline.
/**
* <b>Inline</b> slow path allocation. This method attempts allocSlowOnce
* several times, and allows collection to occur, and ensures that execution
* safely resumes by taking care of potential thread/mutator context affinity
* changes. All allocators should use this as the trampoline for slow
* path allocation.
*
* @param bytes The size of the allocation request
* @param alignment The required alignment
* @param offset The alignment offset
* @return The start address of the region, or zero if allocation fails
*/
@Inline
public final Address allocSlowInline(int bytes, int alignment, int offset) {
Allocator current = this;
Space space = current.getSpace();
// Information about the previous collection.
boolean emergencyCollection = false;
while (true) {
// Try to allocate using the slow path
Address result = current.allocSlowOnce(bytes, alignment, offset);
// Collector allocation always succeeds (or fails inside allocSlow).
if (!VM.activePlan.isMutator()) {
if (VM.VERIFY_ASSERTIONS)
VM.assertions._assert(!result.isZero());
return result;
}
if (!result.isZero()) {
// Report allocation success to assist OutOfMemory handling.
if (!allocationSuccess) {
oomLock.acquire();
allocationSuccess = true;
oomLock.release();
}
return result;
}
if (emergencyCollection) {
// Check if we are in an OutOfMemory situation
oomLock.acquire();
boolean failWithOOM = !allocationSuccess;
// This seems odd, but we must allow each OOM to run its course (and maybe give us back memory)
allocationSuccess = true;
oomLock.release();
if (failWithOOM) {
// Nobody has successfully allocated since an emergency collection: OutOfMemory
VM.collection.outOfMemory();
VM.assertions.fail("Not Reached");
return Address.zero();
}
}
/* This is in case a GC occurs, and our mutator context is stale.
* In some VMs the scheduler can change the affinity between the
* current thread and the mutator context. This is possible for
* VMs that dynamically multiplex Java threads onto multiple mutator
* contexts, */
current = VM.activePlan.mutator().getAllocatorFromSpace(space);
/*
* Record whether last collection was an Emergency collection.
* If so, we make one more attempt to allocate before we signal
* an OOM.
*/
emergencyCollection = Plan.isEmergencyCollection();
}
}
use of org.mmtk.policy.Space in project JikesRVM by JikesRVM.
the class Map64 method createFreeList.
@Override
@Interruptible
public GenericFreeList createFreeList(FreeListPageResource pr, int units, int grain) {
Space space = pr.getSpace();
Address start = space.getStart();
Extent extent = space.getExtent();
int index = spaceIndex(start);
units = (int) (units * NON_MAP_FRACTION);
Extent listExtent = Conversions.pagesToBytes(RawMemoryFreeList.sizeInPages(units, 1));
if (VMLayoutConstants.VERBOSE_BUILD) {
Log.write("Allocating free list for space ");
Log.write(space.getName());
Log.write(", start = ", start);
Log.write(", extent = ", extent);
Log.write(", units = ", units);
Log.write(" listPages = ", RawMemoryFreeList.sizeInPages(units, 1));
Log.writeln(", listExtent = ", listExtent);
}
RawMemoryFreeList list = new RawMemoryFreeList(start, start.plus(listExtent), units, grain);
flPageResources[index] = pr;
flMap[index] = list;
/* Adjust the base address and highwater to account for the allocated chunks for the map */
Address base = Conversions.chunkAlign(start.plus(listExtent), false);
highWater.set(index, base);
baseAddress.set(index, base);
return list;
}
Aggregations