|
|
@ -35,13 +35,12 @@ import java.lang.reflect.InvocationTargetException; |
|
|
|
import java.lang.reflect.Method; |
|
|
|
import java.lang.reflect.Method; |
|
|
|
import java.nio.Buffer; |
|
|
|
import java.nio.Buffer; |
|
|
|
import java.nio.ByteBuffer; |
|
|
|
import java.nio.ByteBuffer; |
|
|
|
import java.nio.DoubleBuffer; |
|
|
|
|
|
|
|
import java.util.logging.Level; |
|
|
|
import java.util.logging.Level; |
|
|
|
import java.util.logging.Logger; |
|
|
|
import java.util.logging.Logger; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* This class contains the reflection based way to remove DirectByteBuffers in java < 9, |
|
|
|
* This class contains the reflection based way to remove DirectByteBuffers in |
|
|
|
* allocation is done via ByteBuffer.allocateDirect |
|
|
|
* java < 9, allocation is done via ByteBuffer.allocateDirect |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public final class ReflectionAllocator implements BufferAllocator { |
|
|
|
public final class ReflectionAllocator implements BufferAllocator { |
|
|
|
private static Method cleanerMethod = null; |
|
|
|
private static Method cleanerMethod = null; |
|
|
@ -59,7 +58,8 @@ public final class ReflectionAllocator implements BufferAllocator { |
|
|
|
viewedBufferMethod = loadMethod("sun.nio.ch.DirectBuffer", "attachment"); |
|
|
|
viewedBufferMethod = loadMethod("sun.nio.ch.DirectBuffer", "attachment"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Apache Harmony (allocated directly, to not trigger allocator used logic in BufferUtils)
|
|
|
|
// Apache Harmony (allocated directly, to not trigger allocator used
|
|
|
|
|
|
|
|
// logic in BufferUtils)
|
|
|
|
ByteBuffer bb = ByteBuffer.allocateDirect(1); |
|
|
|
ByteBuffer bb = ByteBuffer.allocateDirect(1); |
|
|
|
Class<?> clazz = bb.getClass(); |
|
|
|
Class<?> clazz = bb.getClass(); |
|
|
|
try { |
|
|
|
try { |
|
|
@ -106,7 +106,8 @@ public final class ReflectionAllocator implements BufferAllocator { |
|
|
|
if (viewedBuffer != null) { |
|
|
|
if (viewedBuffer != null) { |
|
|
|
destroyDirectBuffer((Buffer) viewedBuffer); |
|
|
|
destroyDirectBuffer((Buffer) viewedBuffer); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
Logger.getLogger(BufferUtils.class.getName()).log(Level.SEVERE, "Buffer cannot be destroyed: {0}", toBeDestroyed); |
|
|
|
Logger.getLogger(BufferUtils.class.getName()).log(Level.SEVERE, |
|
|
|
|
|
|
|
"Buffer cannot be destroyed: {0}", toBeDestroyed); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|