Package engine.misc
Class DeallocationHelper
- java.lang.Object
-
- engine.misc.DeallocationHelper
-
public class DeallocationHelper extends Object
Helper to deallocate memory on the native heap allocated during the creation of a direct byte buffer. It supports numerous virtual machines including OpenJDK, Oracle/Sun Java, Android Dalvik Virtual Machine, Apache Harmony and GNU Classpath. This class uses the syntax of Java 1.7 but it can work correctly with Java 1.4 with a very few minor type changes when using the maps and the collections. It relies on lots of implementation details but it's robust enough to go on working (except when the implementors intentionally use a very general class to store the buffers) despite minor naming changes like those that occurred between Java 1.6 and Java 1.7. It supports Java 1.9 despite the move of the cleaner from the package sun.misc to jdk.internal.ref (in the module java.base). N.B: Releasing the native memory of a sliced direct NIO buffer, the one of a direct NIO buffer created with JNI or the one of any direct NIO buffer created by the virtual machine or by a framework not under your control doesn't prevent the calls to methods attempting to access such buffers. Those calls can throw an exception or crash the virtual machine depending on the implementations.- Author:
- Julien Gouesse
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DeallocationHelper.AndroidDeallocator
static class
DeallocationHelper.ApacheHarmonyDeallocator
static class
DeallocationHelper.Deallocator
tool responsible for releasing the native memory of a deallocatable byte bufferstatic class
DeallocationHelper.GnuClasspathDeallocator
static class
DeallocationHelper.OracleSunOpenJdkDeallocator
-
Constructor Summary
Constructors Constructor Description DeallocationHelper()
Default constructorDeallocationHelper(boolean ignoreClassesAndFieldsHints)
Main constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
deallocate(Buffer buffer)
ByteBuffer
findDeallocatableBuffer(Buffer buffer)
Map<Class<?>,Field>
getAttachmentOrByteBufferFieldMap()
Set<Class<?>>
getDeallocatableBufferClassSet()
DeallocationHelper.Deallocator
getDeallocator()
void
setAttachmentOrByteBufferFieldMap(Map<Class<?>,Field> attachmentOrByteBufferFieldMap)
void
setDeallocatableBufferClassSet(Set<Class<?>> deallocatableBufferClassSet)
void
setDeallocator(DeallocationHelper.Deallocator deallocator)
-
-
-
Constructor Detail
-
DeallocationHelper
public DeallocationHelper()
Default constructor
-
DeallocationHelper
public DeallocationHelper(boolean ignoreClassesAndFieldsHints)
Main constructor- Parameters:
ignoreClassesAndFieldsHints
-true
if the known implementation details should be ignored when looking for the classes and the fields used for the native memory of the direct buffers (they are then fully recomputed at runtime which is slower but safer), otherwisefalse
-
-
Method Detail
-
findDeallocatableBuffer
public ByteBuffer findDeallocatableBuffer(Buffer buffer)
-
deallocate
public void deallocate(Buffer buffer)
-
getDeallocator
public DeallocationHelper.Deallocator getDeallocator()
-
setDeallocator
public void setDeallocator(DeallocationHelper.Deallocator deallocator)
-
setAttachmentOrByteBufferFieldMap
public void setAttachmentOrByteBufferFieldMap(Map<Class<?>,Field> attachmentOrByteBufferFieldMap)
-
-