static void initializeSimpleTypes(Target_com_oracle_truffle_nfi_impl_NFIContext context) { // it's important to initialize POINTER first, since the primitive array types depend on it initializeNativeSimpleType(context, NativeSimpleType.POINTER, ffi_type_pointer.get()); initializeNativeSimpleType(context, NativeSimpleType.VOID, ffi_type_void.get()); initializeNativeSimpleType(context, NativeSimpleType.UINT8, ffi_type_uint8.get()); initializeNativeSimpleType(context, NativeSimpleType.SINT8, ffi_type_sint8.get()); initializeNativeSimpleType(context, NativeSimpleType.UINT16, ffi_type_uint16.get()); initializeNativeSimpleType(context, NativeSimpleType.SINT16, ffi_type_sint16.get()); initializeNativeSimpleType(context, NativeSimpleType.UINT32, ffi_type_uint32.get()); initializeNativeSimpleType(context, NativeSimpleType.SINT32, ffi_type_sint32.get()); initializeNativeSimpleType(context, NativeSimpleType.UINT64, ffi_type_uint64.get()); initializeNativeSimpleType(context, NativeSimpleType.SINT64, ffi_type_sint64.get()); initializeNativeSimpleType(context, NativeSimpleType.FLOAT, ffi_type_float.get()); initializeNativeSimpleType(context, NativeSimpleType.DOUBLE, ffi_type_double.get()); initializeNativeSimpleType(context, NativeSimpleType.STRING, ffi_type_pointer.get()); initializeNativeSimpleType(context, NativeSimpleType.OBJECT, ffi_type_pointer.get()); }
static void leave() { int code = CEntryPointActions.leaveDetachThread(); if (code != 0) { CEntryPointActions.failFatally(code, errorMessage.get()); } } }
@Override @Uninterruptible(reason = "Called during isolate tear-down.") public int tearDown(PointerBase heapBase) { Word size = Isolates.IMAGE_HEAP_END.get().subtract(Isolates.IMAGE_HEAP_BEGIN.get()); if (VirtualMemoryProvider.get().free(heapBase, size) != 0) { return CEntryPointErrors.MAP_HEAP_FAILED; } return CEntryPointErrors.NO_ERROR; } }
static void leave() { int code = CEntryPointActions.leave(); if (code != 0) { CEntryPointActions.failFatally(code, errorMessage.get()); } } }
static void leave() { int code = CEntryPointActions.leaveTearDownIsolate(); if (code != 0) { CEntryPointActions.failFatally(code, errorMessage.get()); } } }
static void enter(Isolate isolate) { int code = CEntryPointActions.enterIsolate(isolate); if (code != 0) { CEntryPointActions.failFatally(code, errorMessage.get()); } } }
@Uninterruptible(reason = "Thread state not yet set up.") public static PointerBase getHeapBase(Isolate isolate) { if (!SubstrateOptions.SpawnIsolates.getValue()) { return IMAGE_HEAP_BEGIN.get(); } return isolate; }
static void enter(IsolateThread thread) { int code = CEntryPointActions.enter(thread); if (code != 0) { CEntryPointActions.failFatally(code, errorMessage.get()); } } }
static void enter() { int code = CEntryPointActions.enterCreateIsolate(WordFactory.nullPointer()); if (code != 0) { CEntryPointActions.failFatally(code, errorMessage.get()); } } }
@SuppressWarnings("unused") static void enter(ThreadStartData data) { int code = CEntryPointActions.enterAttachThread(data.getIsolate()); if (code != 0) { CEntryPointActions.failFatally(code, errorMessage.get()); } } }
@SuppressWarnings("unused") static void enter(WindowsThreadStartData data) { int code = CEntryPointActions.enterAttachThread(data.getIsolate()); if (code != 0) { CEntryPointActions.failFatally(code, errorMessage.get()); } } }
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) public static UnsignedWord getPageSize() { Word value = CACHED_PAGE_SIZE.get().read(); if (value.equal(WordFactory.zero())) { long queried = sysconf(_SC_PAGE_SIZE()); value = WordFactory.unsigned(queried); CACHED_PAGE_SIZE.get().write(value); } return value; }
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) private static void initCaches() { WinBase.SYSTEM_INFO sysInfo = StackValue.get(WinBase.SYSTEM_INFO.class); WinBase.GetSystemInfo(sysInfo); int pageSize = sysInfo.dwPageSize(); Word value = WordFactory.unsigned(pageSize); CACHED_PAGE_SIZE.get().write(value); int granularity = sysInfo.dwAllocationGranularity(); value = WordFactory.unsigned(granularity); CACHED_ALLOC_GRAN.get().write(value); }
/** Remove an entry. */ public static boolean removeJavaVM(JNIJavaVM javavm) { WordPointer p = HEAD.get().readWord(0); while (p.isNonNull()) { Word capacity = p.read(0); for (Word i = unsigned(1); i.belowOrEqual(capacity); i = i.add(1)) { JNIJavaVM entry = p.read(i); if (entry.equal(javavm)) { p.write(i, nullPointer()); return true; } } p = p.read(capacity.add(1)); // next } return false; }
@Uninterruptible(reason = UNINTERRUPTIBLE_REASON) @CEntryPoint(name = "get_isolate", documentation = { "Given an isolate thread structure, determines to which isolate it belongs and returns", "the address of its isolate structure. If an error occurs, returns NULL instead."}) @CEntryPointOptions(prologue = NoPrologue.class, epilogue = NoEpilogue.class, nameTransformation = NameTransformation.class) public static Isolate getIsolate(IsolateThread thread) { Isolate isolate = WordFactory.nullPointer(); if (thread.isNull()) { // proceed to return null } else if (SubstrateOptions.MultiThreaded.getValue()) { long offset = ISOLATETHREAD_ISOLATE_OFFSET.get().read(); isolate = ((Pointer) thread).readWord(WordFactory.unsigned(offset)); } else if (SubstrateOptions.SpawnIsolates.getValue() || thread.equal(CEntryPointSetup.SINGLE_THREAD_SENTINEL)) { isolate = (Isolate) ((Pointer) thread).subtract(CEntryPointSetup.SINGLE_ISOLATE_TO_SINGLE_THREAD_ADDEND); } return isolate; }
/** Gather non-null entries in a buffer and provide the total number of non-null entries. */ @Uninterruptible(reason = "Called from uninterruptible code.") public static void gather(JNIJavaVMPointer buffer, int bufferLength, CIntPointer totalCountPointer) { int totalCount = 0; WordPointer p = HEAD.get().readWord(0); while (p.isNonNull()) { Word capacity = p.read(0); for (Word i = unsigned(1); i.belowOrEqual(capacity); i = i.add(1)) { JNIJavaVM entry = p.read(i); if (entry.isNonNull()) { if (totalCount < bufferLength) { buffer.write(totalCount, entry); } totalCount++; } } p = p.read(capacity.add(1)); // next } totalCountPointer.write(totalCount); } }
@Override public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) { if (SubstrateUtil.HOSTED) { // AOT compilation: record patch that is fixed up later int before = masm.position(); AMD64Address address = masm.getPlaceholder(before); if (dataInfo.isSymbolReference()) { // Pure symbol reference: the data contains the symbol's address, load it masm.movq(asRegister(result), address); } else { // Data: load its address masm.leaq(asRegister(result), address); } crb.compilationResult.recordDataPatch(before, new CGlobalDataReference(dataInfo)); } else { // Runtime compilation: compute the actual address Pointer globalsBase = CGlobalDataInfo.CGLOBALDATA_RUNTIME_BASE_ADDRESS.get(); Pointer address = globalsBase.add(dataInfo.getOffset()); masm.movq(asRegister(result), address.rawValue()); if (dataInfo.isSymbolReference()) { // load data, which contains symbol's address masm.movq(asRegister(result), new AMD64Address(asRegister(result))); } } } }