use of com.oracle.svm.core.snippets.SubstrateForeignCallTarget in project graal by oracle.
the class PosixCEntryPointSnippets method failFatally.
@Uninterruptible(reason = "Unknown thread state.")
@SubstrateForeignCallTarget
private static void failFatally(int code, CCharPointer message) {
FILE stderr = fdopen(2, FAIL_FATALLY_FDOPEN_MODE.get());
fprintfSD(stderr, FAIL_FATALLY_MESSAGE_FORMAT.get(), message, code);
LibC.exit(code);
}
use of com.oracle.svm.core.snippets.SubstrateForeignCallTarget in project graal by oracle.
the class PosixCEntryPointSnippets method createIsolate.
@Uninterruptible(reason = "Thread state not yet set up.")
@SubstrateForeignCallTarget
private static int createIsolate(CEntryPointCreateIsolateParameters parameters, int vmThreadSize) {
WordPointer isolate = StackValue.get(SizeOf.get(WordPointer.class));
isolate.write(Word.nullPointer());
int error = PosixIsolates.create(isolate, parameters);
if (error != Errors.NO_ERROR) {
return error;
}
if (UseHeapBaseRegister.getValue()) {
setHeapBase(PosixIsolates.getHeapBase(isolate.read()));
}
if (MultiThreaded.getValue()) {
PosixVMThreads.ensureInitialized();
}
return attachThread(isolate.read(), vmThreadSize);
}
use of com.oracle.svm.core.snippets.SubstrateForeignCallTarget in project graal by oracle.
the class PosixCEntryPointSnippets method attachThread.
@Uninterruptible(reason = "Thread state not yet set up.")
@SubstrateForeignCallTarget
private static int attachThread(Isolate isolate, int vmThreadSize) {
int sanityError = PosixIsolates.checkSanity(isolate);
if (sanityError != Errors.NO_ERROR) {
return sanityError;
}
if (UseHeapBaseRegister.getValue()) {
setHeapBase(PosixIsolates.getHeapBase(isolate));
}
if (MultiThreaded.getValue()) {
if (!PosixVMThreads.isInitialized()) {
return Errors.UNINITIALIZED_ISOLATE;
}
IsolateThread thread = PosixVMThreads.VMThreadTL.get();
if (VMThreads.isNullThread(thread)) {
// not attached
thread = LibC.calloc(WordFactory.unsigned(1), WordFactory.unsigned(vmThreadSize));
VMThreads.attachThread(thread);
// Store thread and isolate in thread-local variables.
PosixVMThreads.VMThreadTL.set(thread);
PosixVMThreads.IsolateTL.set(thread, isolate);
}
writeCurrentVMThread(thread);
}
return Errors.NO_ERROR;
}
use of com.oracle.svm.core.snippets.SubstrateForeignCallTarget in project graal by oracle.
the class PosixCEntryPointSnippets method detachThreadMT.
@SubstrateForeignCallTarget
@Uninterruptible(reason = "Thread state going away.")
@RestrictHeapAccess(access = RestrictHeapAccess.Access.NO_ALLOCATION, reason = "Must not (thread-local) allocate while detaching a thread.")
private static int detachThreadMT(IsolateThread thread) {
int result = Errors.NO_ERROR;
/*
* Set thread status to exited. This makes me immune to safepoints (the safepoint mechanism
* ignores me). Also clear any pending safepoint requests, since I will not honor them.
*/
VMThreads.StatusSupport.setStatusExited();
Safepoint.setSafepointRequested(Safepoint.SafepointRequestValues.RESET);
// try-finally because try-with-resources can call interruptible code
VMThreads.THREAD_MUTEX.lockNoTransition();
try {
detachJavaLangThreadMT(thread);
// clear references to thread to avoid unintended use
writeCurrentVMThread(VMThreads.nullThread());
PosixVMThreads.VMThreadTL.set(VMThreads.nullThread());
VMThreads.detachThread(thread);
} catch (Throwable t) {
result = Errors.UNSPECIFIED;
} finally {
VMThreads.THREAD_MUTEX.unlock();
LibC.free(thread);
}
return result;
}
use of com.oracle.svm.core.snippets.SubstrateForeignCallTarget in project graal by oracle.
the class ArraycopySnippets method doArraycopy.
/**
* The actual implementation of {@link System#arraycopy}, called via the foreign call
* {@link #ARRAYCOPY}.
*/
@SubstrateForeignCallTarget
private static void doArraycopy(Object fromArray, int fromIndex, Object toArray, int toIndex, int length) {
if (fromArray == null || toArray == null) {
throw new NullPointerException();
}
DynamicHub fromHub = KnownIntrinsics.readHub(fromArray);
DynamicHub toHub = KnownIntrinsics.readHub(toArray);
if (LayoutEncoding.isPrimitiveArray(fromHub.getLayoutEncoding())) {
if (fromArray == toArray && fromIndex < toIndex) {
boundsCheck(fromArray, fromIndex, toArray, toIndex, length);
primitiveCopyBackward(fromArray, fromIndex, fromArray, toIndex, length, fromHub.getLayoutEncoding());
return;
} else if (fromHub == toHub) {
boundsCheck(fromArray, fromIndex, toArray, toIndex, length);
primitiveCopyForward(fromArray, fromIndex, toArray, toIndex, length, fromHub.getLayoutEncoding());
return;
}
} else if (LayoutEncoding.isObjectArray(fromHub.getLayoutEncoding())) {
if (fromArray == toArray && fromIndex < toIndex) {
boundsCheck(fromArray, fromIndex, toArray, toIndex, length);
objectCopyBackward(fromArray, fromIndex, fromArray, toIndex, length, fromHub.getLayoutEncoding());
return;
} else if (fromHub == toHub || toHub.isAssignableFrom(fromHub)) {
boundsCheck(fromArray, fromIndex, toArray, toIndex, length);
objectCopyForward(fromArray, fromIndex, toArray, toIndex, length, fromHub.getLayoutEncoding());
return;
} else if (LayoutEncoding.isObjectArray(toHub.getLayoutEncoding())) {
boundsCheck(fromArray, fromIndex, toArray, toIndex, length);
objectStoreCheckCopyForward(fromArray, fromIndex, toArray, toIndex, length);
return;
}
}
throw new ArrayStoreException();
}
Aggregations