UI改进
This commit is contained in:
@@ -5,6 +5,8 @@ import java.lang.ref.PhantomReference;
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.ReferenceQueue;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.BufferOverflowException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
@@ -13,6 +15,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.kne.debug.TimeDebugger;
|
||||
|
||||
import jdk.internal.misc.Unsafe;
|
||||
public class ByteBufferAllocator {
|
||||
private List<ByteBufferPool> bbfps=new ArrayList<>();
|
||||
|
||||
@@ -75,9 +79,38 @@ public class ByteBufferAllocator {
|
||||
new ByteBufferPhantomReference(bbfs,refq,bbf,bbfp);
|
||||
return bbfs;
|
||||
}
|
||||
private static ByteBuffer allocateHeap(int capacity) {
|
||||
return ByteBuffer.wrap(new byte[capacity]);
|
||||
private static jdk.internal.misc.Unsafe usf;
|
||||
private static Method meth;
|
||||
static {
|
||||
Class<?> name;
|
||||
try {
|
||||
name = Class.forName("jdk.internal.misc.Unsafe");
|
||||
Field field = name.getDeclaredField("theUnsafe");
|
||||
field.setAccessible(true);
|
||||
usf= (Unsafe) field.get(null);
|
||||
meth=name.getMethod("allocateUninitializedArray", Class.class,int.class);
|
||||
|
||||
} catch (java.lang.reflect.InaccessibleObjectException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static ByteBuffer allocateHeap(int capacity) {
|
||||
//return ByteBuffer.wrap((byte[]) usf.allocateUninitializedArray(byte.class, capacity));
|
||||
if(usf!=null&&meth!=null) {
|
||||
try {
|
||||
return ByteBuffer.wrap((byte[]) usf.allocateUninitializedArray(byte.class, capacity));
|
||||
} catch (Exception e) {
|
||||
return ByteBuffer.wrap(new byte[capacity]);
|
||||
}
|
||||
}else {
|
||||
return ByteBuffer.wrap(new byte[capacity]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private ByteBufferPool getByteBufferPool(int capacity) {
|
||||
int elen=0;
|
||||
for (int i = 0; i < bbfps.size(); i++) {
|
||||
|
||||
Reference in New Issue
Block a user