Top Inners Fields Constructors Methods
org.jruby.ext.ffi.jffi

pack-priv final Class CachingNativeMemoryAllocator

extends Object
Class Inheritance
Imports
jnr.ffi.util.ref.FinalizableWeakReference, org.jruby.Ruby, org.jruby.ext.ffi.AllocatedDirectMemoryIO, .MemoryIO, java.lang.ref.Reference, .SoftReference, java.util.*, java.util.concurrent.ConcurrentHashMap, java.util.concurrent.atomic.AtomicBoolean

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
private static class
private static class
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private static final CachingNativeMemoryAllocator.Bucket[]
buckets

Keeps strong references to the memory bucket until cleanup

private static final ThreadLocal<Reference<CachingNativeMemoryAllocator.Allocator>>
protected static final MemoryIO
private static final Map<CachingNativeMemoryAllocator.AllocationGroup, Boolean>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private static long
align(long offset, long align)

pack-priv static MemoryIO
allocateAligned(Ruby
The Ruby runtime
runtime
,
int
The number of bytes to allocate
size
,
int
The minimum alignment of the memory
align
,
boolean
Whether the memory should be cleared (zeroed)
clear
)

Allocates native memory, aligned to a minimum boundary.

pack-priv static int
bucketIndex(int size)

pack-priv static void
clearMemory(long address, int size)

pack-priv static int
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bucketsback to summary
private static final CachingNativeMemoryAllocator.Bucket[] buckets

Keeps strong references to the memory bucket until cleanup

currentAllocatorback to summary
private static final ThreadLocal<Reference<CachingNativeMemoryAllocator.Allocator>> currentAllocator
IOback to summary
protected static final MemoryIO IO
referenceSetback to summary
private static final Map<CachingNativeMemoryAllocator.AllocationGroup, Boolean> referenceSet

Constructor Detail

CachingNativeMemoryAllocatorback to summary
pack-priv CachingNativeMemoryAllocator()

Method Detail

alignback to summary
private static long align(long offset, long align)
allocateAlignedback to summary
pack-priv static MemoryIO allocateAligned(Ruby runtime, int size, int align, boolean clear)

Allocates native memory, aligned to a minimum boundary.

Parameters
runtime:Ruby

The Ruby runtime

size:int

The number of bytes to allocate

align:int

The minimum alignment of the memory

clear:boolean

Whether the memory should be cleared (zeroed)

Returns:MemoryIO

A new org.jruby.ext.ffi.AllocatedDirectMemoryIO

bucketIndexback to summary
pack-priv static int bucketIndex(int size)
clearMemoryback to summary
pack-priv static void clearMemory(long address, int size)
roundUpToPowerOf2back to summary
pack-priv static int roundUpToPowerOf2(int n)
org.jruby.ext.ffi.jffi back to summary

pack-priv final Class CachingNativeMemoryAllocator.AllocatedMemoryIO

extends BoundedNativeMemoryIO
implements AllocatedDirectMemoryIO
Class Inheritance
All Implemented Interfaces
org.jruby.ext.ffi.AllocatedDirectMemoryIO

Field Summary

Modifier and TypeField and Description
private final CachingNativeMemoryAllocator.MemoryAllocation
private Object
Inherited from org.jruby.ext.ffi.jffi.BoundedNativeMemoryIO:
ADDRESS_SIZEIOLONG_SIZEparentsize

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
public boolean
public void
Inherited from org.jruby.ext.ffi.jffi.BoundedNativeMemoryIO:
arrayarrayLengtharrayOffsetasByteBufferdupequalsgetgetgetgetgetgetgetAddressgetBytegetDoublegetFloatgetIntgetLonggetMemoryIOgetNativeLonggetRuntimegetShortgetZeroTerminatedByteArraygetZeroTerminatedByteArrayhashCodeindexOfindexOforderputputputputputputputAddressputByteputDoubleputFloatputIntputLongputMemoryIOputNativeLongputShortputZeroTerminatedByteArraysetMemorysliceslice

Field Detail

allocationback to summary
private final CachingNativeMemoryAllocator.MemoryAllocation allocation
sentinelback to summary
private Object sentinel

Constructor Detail

AllocatedMemoryIOback to summary
private AllocatedMemoryIO(Ruby runtime, Object sentinel, CachingNativeMemoryAllocator.MemoryAllocation allocation, int size)

Method Detail

freeback to summary
public void free()

Implements org.jruby.ext.ffi.AllocatedDirectMemoryIO.free.

isAutoReleaseback to summary
public boolean isAutoRelease()

Implements org.jruby.ext.ffi.AllocatedDirectMemoryIO.isAutoRelease.

setAutoReleaseback to summary
public void setAutoRelease(boolean autorelease)

Implements org.jruby.ext.ffi.AllocatedDirectMemoryIO.setAutoRelease.

org.jruby.ext.ffi.jffi back to summary

private final Class CachingNativeMemoryAllocator.AllocationGroup

extends FinalizableWeakReference<Object>
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final CachingNativeMemoryAllocator.Magazine

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv CachingNativeMemoryAllocator.MemoryAllocation
allocate(boolean clear)

public void
finalizeReferent()

Implements jnr.ffi.util.ref.FinalizableReference.finalizeReferent.

Invoked on a background thread after the referent has been garbage collected unless security restrictions prevented starting a background thread, in which case this method is invoked when new references are created.

Field Detail

magazineback to summary
pack-priv final CachingNativeMemoryAllocator.Magazine magazine

Constructor Detail

AllocationGroupback to summary
pack-priv AllocationGroup(CachingNativeMemoryAllocator.Magazine magazine, Object sentinel)

Method Detail

allocateback to summary
pack-priv CachingNativeMemoryAllocator.MemoryAllocation allocate(boolean clear)
finalizeReferentback to summary
public void finalizeReferent()

Implements jnr.ffi.util.ref.FinalizableReference.finalizeReferent.

Doc from jnr.ffi.util.ref.FinalizableReference.finalizeReferent.

Invoked on a background thread after the referent has been garbage collected unless security restrictions prevented starting a background thread, in which case this method is invoked when new references are created.

org.jruby.ext.ffi.jffi back to summary

private final Class CachingNativeMemoryAllocator.Allocator

extends Object
Class Inheritance
  • java.lang.Object
  • org.jruby.ext.ffi.jffi.CachingNativeMemoryAllocator.Allocator

Field Summary

Modifier and TypeField and Description
pack-priv final CachingNativeMemoryAllocator.AllocationGroup[]

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv CachingNativeMemoryAllocator.AllocatedMemoryIO
allocate(Ruby runtime, int size, boolean clear)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allocationGroupsback to summary
pack-priv final CachingNativeMemoryAllocator.AllocationGroup[] allocationGroups

Constructor Detail

Allocatorback to summary
private Allocator()

Method Detail

allocateback to summary
pack-priv CachingNativeMemoryAllocator.AllocatedMemoryIO allocate(Ruby runtime, int size, boolean clear)
org.jruby.ext.ffi.jffi back to summary

private final Class CachingNativeMemoryAllocator.Bucket

extends Object
Class Inheritance

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class

Field Summary

Modifier and TypeField and Description
pack-priv final Set<CachingNativeMemoryAllocator.Bucket.CacheElement>
pack-priv final int

Constructor Summary

AccessConstructor and Description
pack-priv
Bucket(int size)

Method Summary

Modifier and TypeMethod and Description
pack-priv synchronized CachingNativeMemoryAllocator.Magazine
pack-priv synchronized void
private synchronized void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cacheback to summary
pack-priv final Set<CachingNativeMemoryAllocator.Bucket.CacheElement> cache
sizeback to summary
pack-priv final int size

Constructor Detail

Bucketback to summary
pack-priv Bucket(int size)

Method Detail

getMagazineback to summary
pack-priv synchronized CachingNativeMemoryAllocator.Magazine getMagazine()
recycleback to summary
pack-priv synchronized void recycle(CachingNativeMemoryAllocator.Magazine magazine)
removeCacheElementback to summary
private synchronized void removeCacheElement(CachingNativeMemoryAllocator.Bucket.CacheElement e)
org.jruby.ext.ffi.jffi back to summary

pack-priv final Class CachingNativeMemoryAllocator.Bucket.CacheElement

extends FinalizableWeakReference<Object>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final AtomicBoolean
private final CachingNativeMemoryAllocator.Magazine

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
finalizeReferent()

Implements jnr.ffi.util.ref.FinalizableReference.finalizeReferent.

Invoked on a background thread after the referent has been garbage collected unless security restrictions prevented starting a background thread, in which case this method is invoked when new references are created.

Field Detail

disposedback to summary
private final AtomicBoolean disposed
magazineback to summary
private final CachingNativeMemoryAllocator.Magazine magazine

Constructor Detail

CacheElementback to summary
pack-priv CacheElement(CachingNativeMemoryAllocator.Magazine magazine)

Method Detail

finalizeReferentback to summary
public void finalizeReferent()

Implements jnr.ffi.util.ref.FinalizableReference.finalizeReferent.

Doc from jnr.ffi.util.ref.FinalizableReference.finalizeReferent.

Invoked on a background thread after the referent has been garbage collected unless security restrictions prevented starting a background thread, in which case this method is invoked when new references are created.

org.jruby.ext.ffi.jffi back to summary

private final Class CachingNativeMemoryAllocator.Magazine

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final CachingNativeMemoryAllocator.MemoryAllocation[]
pack-priv final CachingNativeMemoryAllocator.Bucket
private volatile boolean
pack-priv static final int
private int

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv CachingNativeMemoryAllocator.MemoryAllocation
allocate(boolean clear)

pack-priv synchronized void
pack-priv synchronized void
pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allocationsback to summary
private final CachingNativeMemoryAllocator.MemoryAllocation[] allocations
bucketback to summary
pack-priv final CachingNativeMemoryAllocator.Bucket bucket
fragmentedback to summary
private volatile boolean fragmented
MAX_BYTES_PER_MAGAZINEback to summary
pack-priv static final int MAX_BYTES_PER_MAGAZINE
nextIndexback to summary
private int nextIndex

Constructor Detail

Magazineback to summary
pack-priv Magazine(CachingNativeMemoryAllocator.Bucket bucket)

Method Detail

allocateback to summary
pack-priv CachingNativeMemoryAllocator.MemoryAllocation allocate(boolean clear)
disposeback to summary
pack-priv synchronized void dispose()
recycleback to summary
pack-priv synchronized void recycle()
setFragmentedback to summary
pack-priv void setFragmented()
org.jruby.ext.ffi.jffi back to summary

private final Class CachingNativeMemoryAllocator.MemoryAllocation

extends Object
Class Inheritance
  • java.lang.Object
  • org.jruby.ext.ffi.jffi.CachingNativeMemoryAllocator.MemoryAllocation

Field Summary

Modifier and TypeField and Description
pack-priv final long
pack-priv volatile int
pack-priv final CachingNativeMemoryAllocator.Magazine
pack-priv static final int
pack-priv static final int

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv final void
pack-priv final void
free()

pack-priv final boolean
pack-priv final boolean
public void
setAutoRelease(boolean autorelease)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

addressback to summary
pack-priv final long address
flagsback to summary
pack-priv volatile int flags
magazineback to summary
pack-priv final CachingNativeMemoryAllocator.Magazine magazine
RELEASEDback to summary
pack-priv static final int RELEASED
UNMANAGEDback to summary
pack-priv static final int UNMANAGED

Constructor Detail

MemoryAllocationback to summary
pack-priv MemoryAllocation(CachingNativeMemoryAllocator.Magazine magazine, long address)

Method Detail

disposeback to summary
pack-priv final void dispose()
freeback to summary
pack-priv final void free()
isReleasedback to summary
pack-priv final boolean isReleased()
isUnmanagedback to summary
pack-priv final boolean isUnmanaged()
setAutoReleaseback to summary
public void setAutoRelease(boolean autorelease)