Package engine.misc

Class 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
    • 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), otherwise false
    • Method Detail

      • findDeallocatableBuffer

        public ByteBuffer findDeallocatableBuffer​(Buffer buffer)
      • deallocate

        public void deallocate​(Buffer buffer)
      • getAttachmentOrByteBufferFieldMap

        public Map<Class<?>,​Field> getAttachmentOrByteBufferFieldMap()
      • setAttachmentOrByteBufferFieldMap

        public void setAttachmentOrByteBufferFieldMap​(Map<Class<?>,​Field> attachmentOrByteBufferFieldMap)
      • getDeallocatableBufferClassSet

        public Set<Class<?>> getDeallocatableBufferClassSet()
      • setDeallocatableBufferClassSet

        public void setDeallocatableBufferClassSet​(Set<Class<?>> deallocatableBufferClassSet)