use of org.vmmagic.unboxed.Address in project JikesRVM by JikesRVM.
the class DynamicLibrary method load.
/**
* Load a dynamic library
* @param libName the name of the library to load.
* @return 0 on failure, 1 on success
*/
public static synchronized int load(String libName) {
DynamicLibrary dl = dynamicLibraries.get(libName);
if (dl != null) {
// success: already loaded
return 1;
} else {
// Convert file name from unicode to filesystem character set.
// (Assume file name is ASCII, for now).
//
byte[] asciiName = StringUtilities.stringToBytesNullTerminated(libName);
// make sure we have enough stack to load the library.
// This operation has been known to require more than 20K of stack.
RVMThread myThread = RVMThread.getCurrentThread();
Offset remaining = Magic.getFramePointer().diff(myThread.stackLimit);
int stackNeededInBytes = StackFrameLayout.getStackSizeDLOpen() - remaining.toInt();
if (stackNeededInBytes > 0) {
if (myThread.hasNativeStackFrame()) {
throw new java.lang.StackOverflowError("Not enough space to open shared library");
} else {
RVMThread.resizeCurrentStack(myThread.getStackLength() + stackNeededInBytes, null);
}
}
Address libHandler = SysCall.sysCall.sysDlopen(asciiName);
if (!libHandler.isZero()) {
dynamicLibraries.put(libName, new DynamicLibrary(libName, libHandler));
return 1;
} else {
// fail; file does not exist
return 0;
}
}
}
use of org.vmmagic.unboxed.Address in project JikesRVM by JikesRVM.
the class SharedDeque method checkDequeLength.
/**
* Check the number of buffers in the work queue (for debugging
* purposes).
*
* @param length The number of buffers believed to be in the queue.
* @return True if the length of the queue matches length.
*/
private boolean checkDequeLength(int length) {
Address top = head;
int l = 0;
while (!top.isZero() && l <= length) {
top = getNext(top);
l++;
}
return l == length;
}
use of org.vmmagic.unboxed.Address in project JikesRVM by JikesRVM.
the class SharedDeque method spinWait.
/**
* Spinwait for GC work to arrive
*
* @param fromTail Check the head or the tail ?
*/
private void spinWait(boolean fromTail) {
long startNano = 0;
long lastElapsedNano = 0;
while (true) {
long startCycles = VM.statistics.cycles();
// a few hundred milliseconds more or less.
long endCycles = startCycles + ((long) 1e9);
long nowCycles;
do {
VM.memory.combinedLoadBarriers();
Address rtn = ((fromTail) ? tail : head);
if (!rtn.isZero() || complete())
return;
nowCycles = VM.statistics.cycles();
} while (startCycles < nowCycles && nowCycles < endCycles);
/* check against both ends to guard against CPU migration */
/*
* According to the cycle counter, we've been spinning for a while.
* Time to check nanoTime and see if we should print a warning and/or fail.
* We lock the deque while doing this to avoid interleaved messages from multiple threads.
*/
lock();
if (startNano == 0) {
startNano = VM.statistics.nanoTime();
} else {
long nowNano = VM.statistics.nanoTime();
long elapsedNano = nowNano - startNano;
if (elapsedNano - lastElapsedNano > WARN_PERIOD) {
Log.write("GC Warning: SharedDeque(");
Log.write(name);
Log.write(") wait has reached ");
Log.write(VM.statistics.nanosToSecs(elapsedNano));
Log.write(", ", numConsumersWaiting);
Log.write("/", numConsumers);
Log.writeln(" threads waiting");
lastElapsedNano = elapsedNano;
}
if (elapsedNano > TIMEOUT_PERIOD) {
// To allow other GC threads to die in turn
unlock();
VM.assertions.fail("GC Error: SharedDeque Timeout");
}
}
unlock();
}
}
use of org.vmmagic.unboxed.Address in project JikesRVM by JikesRVM.
the class BumpPointer method gcspyGatherData.
/**
* Gather data for GCspy. <p>
* This method calls the drivers linear scanner to scan through
* the objects allocated by this bump pointer.
*
* @param driver The GCspy driver for this space.
* @param scanSpace The space to scan
*/
public void gcspyGatherData(LinearSpaceDriver driver, Space scanSpace) {
// TODO can scanSpace ever be different to this.space?
if (VM.VERIFY_ASSERTIONS)
VM.assertions._assert(scanSpace == space, "scanSpace != space");
// driver.setRange(scanSpace.getStart(), cursor);
Address start = scanSpace.getStart();
driver.setRange(start, limit);
if (false) {
Log.write("\nBumpPointer.gcspyGatherData set Range ", scanSpace.getStart());
Log.write(" to ", limit);
Log.writeln("BumpPointergcspyGatherData scan from ", initialRegion);
}
linearScan(driver.getScanner());
}
use of org.vmmagic.unboxed.Address in project JikesRVM by JikesRVM.
the class BumpPointer method allocSlow.
/**
* Internal allocation slow path. This is called whenever the bump
* pointer reaches the internal limit. The code is forced out of
* line. If required we perform an external slow path take, which
* we inline into this method since this is already out of line.
*
* @param start The start address for the pending allocation
* @param end The end address for the pending allocation
* @param align The requested alignment
* @param offset The offset from the alignment
* @return The address of the first byte of the allocated region
*/
@NoInline
private Address allocSlow(Address start, Address end, int align, int offset) {
Address rtn = null;
Address card = null;
if (SUPPORT_CARD_SCANNING)
// round up
card = getCard(start.plus(CARD_MASK));
if (end.GT(limit)) {
/* external slow path */
rtn = allocSlowInline(end.diff(start).toInt(), align, offset);
if (SUPPORT_CARD_SCANNING && card.NE(getCard(rtn.plus(CARD_MASK))))
// round down
card = getCard(rtn);
} else {
/* internal slow path */
while (internalLimit.LE(end)) internalLimit = internalLimit.plus(STEP_SIZE);
if (internalLimit.GT(limit))
internalLimit = limit;
fillAlignmentGap(cursor, start);
cursor = end;
rtn = start;
}
if (SUPPORT_CARD_SCANNING && !rtn.isZero())
createCardAnchor(card, rtn, end.diff(start).toInt());
return rtn;
}
Aggregations