use of com.oracle.svm.core.heap.NoAllocationVerifier in project graal by oracle.
the class PosixJavaLangSubstitutions method doForkAndExec.
@SuppressWarnings("try")
static int doForkAndExec(CCharPointer file, CCharPointer dir, CCharPointerPointer argv, CCharPointerPointer envp, int[] stdioFds, int failFd) {
final int buflen = SizeOf.get(dirent.class) + Limits.PATH_MAX() + 1;
final boolean haveProcFs = Platform.includedIn(Platform.LINUX.class);
try (// only this thread will exist in the child and garbage collection is not possible.
PinnedObject bufferPin = PinnedObject.create(new byte[buflen]);
CCharPointerHolder procFdsPath = haveProcFs ? CTypeConversion.toCString("/proc/self/fd/") : null;
CCharPointerHolder searchPaths = CTypeConversion.toCString(System.getenv("PATH"));
CCharPointerHolder searchPathSeparator = CTypeConversion.toCString(":");
NoAllocationVerifier v = NoAllocationVerifier.factory("fragile state after fork()")) {
CCharPointer procFdsPathPtr = (procFdsPath != null) ? procFdsPath.get() : WordFactory.nullPointer();
return uninterruptibleForkAndExec(file, dir, argv, envp, stdioFds, failFd, bufferPin.addressOfArrayElement(0), buflen, procFdsPathPtr, searchPaths.get(), searchPathSeparator.get());
}
}
use of com.oracle.svm.core.heap.NoAllocationVerifier in project graal by oracle.
the class InstalledCodeBuilder method installOperation.
@SuppressWarnings("try")
private void installOperation() {
AMD64InstructionPatcher patcher = new AMD64InstructionPatcher(compilation);
patchData(patcher);
int updatedCodeSize = patchCalls(patcher);
assert updatedCodeSize <= constantsOffset;
// Store the compiled code
for (int index = 0; index < updatedCodeSize; index++) {
code.writeByte(index, compiledBytes[index]);
}
/* Primitive constants are written directly to the code memory. */
ByteBuffer constantsBuffer = SubstrateUtil.wrapAsByteBuffer(code.add(constantsOffset), compilation.getDataSection().getSectionSize());
/*
* Object constants are stored in an Object[] array first, because we have to be careful
* that they are always exposed as roots to the GC.
*/
ObjectConstantsHolder objectConstants = new ObjectConstantsHolder(compilation);
compilation.getDataSection().buildDataSection(constantsBuffer, (position, constant) -> {
objectConstants.add(position, KnownIntrinsics.convertUnknownValue(SubstrateObjectConstant.asObject(constant), Object.class));
});
// Open the PinnedAllocator for the meta-information.
metaInfoAllocator.open();
try {
runtimeMethodInfo = metaInfoAllocator.newInstance(RuntimeMethodInfo.class);
constantsWalker = metaInfoAllocator.newInstance(ConstantsWalker.class);
ReferenceMapEncoder encoder = new ReferenceMapEncoder();
encoder.add(objectConstants.referenceMap);
constantsWalker.referenceMapEncoding = encoder.encodeAll(metaInfoAllocator);
constantsWalker.referenceMapIndex = encoder.lookupEncoding(objectConstants.referenceMap);
constantsWalker.constantsAddr = code.add(constantsOffset);
constantsWalker.constantsSize = compilation.getDataSection().getSectionSize();
Heap.getHeap().getGC().registerObjectReferenceWalker(constantsWalker);
/*
* We now have the constantsWalker initialized and registered, but it is still inactive.
* Writing the actual object constants to the code memory needs to be atomic regarding
* to GC. After everything is written, we activate the constantsWalker.
*/
try (NoAllocationVerifier verifier = NoAllocationVerifier.factory("InstalledCodeBuilder.install")) {
writeObjectConstantsToCode(objectConstants);
}
createCodeChunkInfos();
InstalledCodeObserver.InstalledCodeObserverHandle[] observerHandles = InstalledCodeObserverSupport.installObservers(codeObservers, metaInfoAllocator);
runtimeMethodInfo.setData((CodePointer) code, WordFactory.unsigned(codeSize), installedCode, constantsWalker, metaInfoAllocator, observerHandles);
} finally {
metaInfoAllocator.close();
}
Throwable[] errorBox = { null };
VMOperation.enqueueBlockingSafepoint("Install code", () -> {
try {
CodeInfoTable.getRuntimeCodeCache().addMethod(runtimeMethodInfo);
/*
* This call makes the new code visible, i.e., other threads can start executing it
* immediately. So all metadata must be registered at this point.
*/
installedCode.setAddress(code.rawValue(), method);
} catch (Throwable e) {
errorBox[0] = e;
}
});
if (errorBox[0] != null) {
throw rethrow(errorBox[0]);
}
compilation = null;
}
use of com.oracle.svm.core.heap.NoAllocationVerifier in project graal by oracle.
the class GarbageCollectorManagementFactory method collectImpl.
@SuppressWarnings("try")
private void collectImpl(String cause) {
final Log trace = Log.noopLog().string("[GCImpl.collectImpl:").newline().string(" epoch: ").unsigned(getCollectionEpoch()).string(" cause: ").string(cause).newline();
VMOperation.guaranteeInProgress("Collection should be a VMOperation.");
final HeapImpl heap = HeapImpl.getHeapImpl();
precondition();
/*
* Disable young generation allocations *inside* the collector, and detect any that slip in.
*/
trace.string(" Begin collection: ");
try (NoAllocationVerifier nav = noAllocationVerifier.open()) {
trace.string(" Verify before: ");
try (Timer vbt = verifyBeforeTimer.open()) {
HeapImpl.getHeapImpl().verifyBeforeGC(cause, getCollectionEpoch());
}
getAccounting().beforeCollection();
try (Timer ct = collectionTimer.open()) {
/*
* Always scavenge the young generation, then maybe scavenge the old generation.
* Scavenging the young generation will free up the chunks from the young
* generation, so that when the scavenge of the old generation needs chunks it will
* find them on the free list.
*
*/
if (getPolicy().collectIncrementally()) {
scavenge(true);
}
completeCollection = getPolicy().collectCompletely();
if (completeCollection) {
scavenge(false);
}
}
/* Distribute any discovered references to their queues. */
DiscoverableReferenceProcessing.Scatterer.distributeReferences();
}
getAccounting().afterCollection(completeCollection, collectionTimer);
trace.string(" Verify after: ");
try (Timer vat = verifyAfterTimer.open()) {
heap.verifyAfterGC(cause, getCollectionEpoch());
}
postcondition();
trace.string("]").newline();
}
Aggregations