@SuppressWarnings("unchecked") public <T> FromNativeConverter<T, Pointer> getNativeConveter(Class<T> closureClass) { FromNativeConverter<T, Pointer> result = (FromNativeConverter<T, Pointer>) cache.get(closureClass); if (result != null) { return result; } result = (FromNativeConverter<T, Pointer>) ClosureFromNativeConverter. getInstance(Runtime.getSystemRuntime(), DefaultSignatureType.create(closureClass, (FromNativeContext) ctx), classLoader, ctm); cache.putIfAbsent(closureClass, result); return result; }
/** * Gets the native size of type of reference * * @param runtime The current runtime. * @return The size of the native type this reference points to */ public int nativeSize(Runtime runtime) { return runtime.addressSize(); } }
jnr.ffi.Runtime getRuntime() { return jnr.ffi.Runtime.getRuntime(libc()); }
public static ArrayIO getArrayIO(Runtime runtime) { if (runtime.byteOrder().equals(ByteOrder.BIG_ENDIAN)) { return runtime.addressSize() == 8 ? BE64ArrayIO.INSTANCE : BE32ArrayIO.INSTANCE; } else { return runtime.addressSize() == 8 ? LE64ArrayIO.INSTANCE : LE32ArrayIO.INSTANCE; } }
public final boolean isValid() { return pointer.address() != (INVALID_HANDLE_VALUE & jnr.ffi.Runtime.getSystemRuntime().addressMask()); }
/** * Allocates a new block of native memory and wraps it in a {@link Pointer} * accessor. * * @param runtime The current runtime. * @param type The native type to allocate memory for. * * @return a {@code Pointer} instance that can access the memory. */ public static Pointer allocateDirect(Runtime runtime, NativeType type) { return runtime.getMemoryManager().allocateDirect(runtime.findType(type).size()); }
public void setName(String name) { if (name == null) { setNamePointer(null); setNameLen(0); return; } byte[] nameBytes = name.getBytes(Charset.forName("US-ASCII")); Pointer p = Runtime.getSystemRuntime().getMemoryManager().allocateTemporary(nameBytes.length, true); p.put(0, nameBytes, 0, nameBytes.length); setNamePointer(p); setNameLen(nameBytes.length); }
private ClosureHelper() { try { ClosureManager closureManager = jnr.ffi.Runtime.getSystemRuntime().getClosureManager(); Field classLoaderField = NativeClosureManager.class.getDeclaredField("classLoader"); classLoaderField.setAccessible(true); classLoader = (AsmClassLoader) classLoaderField.get(closureManager); Field typeMapperField = NativeClosureManager.class.getDeclaredField("typeMapper"); typeMapperField.setAccessible(true); ctm = (CompositeTypeMapper) typeMapperField.get(closureManager); ctx = new SimpleNativeContext(Runtime.getSystemRuntime(), Collections.emptyList()); } catch (Exception e) { throw new FuseException("Unable to create helper", e); } } }
public final void set(jnr.ffi.Pointer ptr, T value) { ptr.putPointer(offset(), getRuntime().getClosureManager().getClosurePointer(closureClass, instance = value)); } }
private static Type lookupAliasedType(jnr.ffi.Runtime runtime, Collection<Annotation> annotations) { for (Annotation a : annotations) { TypeDefinition typedef = a.annotationType().getAnnotation(TypeDefinition.class); if (typedef != null) { return runtime.findType(typedef.alias()); } } return null; }
@Override public void postInvoke(Pointer[] pointers, long[] primitive, ToNativeContext context) { if (pointers != null && primitive != null) { MemoryManager mm = runtime.getMemoryManager(); for (int i = 0; i < pointers.length; i++) { pointers[i] = mm.newPointer(primitive[i]); } } } }
private long id(Object obj) { return ((0xcafebabeL << 32) | (System.identityHashCode(obj) & 0xffffffffL)) & runtime.addressMask(); }
.order(runtime.byteOrder()); int rv = lib.tjDecompress2( codec, ByteBuffer.wrap(jpegData), jpegData.length, outBuf,
public void setName(String name) { if (name == null) { setNamePointer(null); setNameLen(0); return; } byte[] nameBytes = name.getBytes(Charset.forName("US-ASCII")); Pointer p = Runtime.getSystemRuntime().getMemoryManager().allocateTemporary(nameBytes.length, true); p.put(0, nameBytes, 0, nameBytes.length); setNamePointer(p); setNameLen(nameBytes.length); }
public final boolean isValid() { return pointer.address() != (INVALID_HANDLE_VALUE & jnr.ffi.Runtime.getSystemRuntime().addressMask()); }
private ClosureHelper() { try { ClosureManager closureManager = jnr.ffi.Runtime.getSystemRuntime().getClosureManager(); Field classLoaderField = NativeClosureManager.class.getDeclaredField("classLoader"); classLoaderField.setAccessible(true); classLoader = (AsmClassLoader) classLoaderField.get(closureManager); Field typeMapperField = NativeClosureManager.class.getDeclaredField("typeMapper"); typeMapperField.setAccessible(true); ctm = (CompositeTypeMapper) typeMapperField.get(closureManager); ctx = new SimpleNativeContext(Runtime.getSystemRuntime(), Collections.emptyList()); } catch (Exception e) { throw new FuseException("Unable to create helper", e); } } }
/** * Allocates a new block of java memory and wraps it in a {@link Pointer} * accessor. * * @param type The type alias to allocate memory for. * * @return a {@code Pointer} instance that can access the memory. */ public static Pointer allocate(Runtime runtime, TypeAlias type) { return runtime.getMemoryManager().allocate(runtime.findType(type).size()); }
public static ArrayIO getArrayIO(Runtime runtime) { if (runtime.byteOrder().equals(ByteOrder.BIG_ENDIAN)) { return runtime.addressSize() == 8 ? BE64ArrayIO.INSTANCE : BE32ArrayIO.INSTANCE; } else { return runtime.addressSize() == 8 ? LE64ArrayIO.INSTANCE : LE32ArrayIO.INSTANCE; } }
public final void set(jnr.ffi.Pointer ptr, T value) { ptr.putPointer(offset(), getRuntime().getClosureManager().getClosurePointer(closureClass, instance = value)); } }
private static Type lookupAliasedType(jnr.ffi.Runtime runtime, Collection<Annotation> annotations) { for (Annotation a : annotations) { TypeDefinition typedef = a.annotationType().getAnnotation(TypeDefinition.class); if (typedef != null) { return runtime.findType(typedef.alias()); } } return null; }