How can one look up how much direct memory is currently allocated (and may be allocated) by Java? As the evaluator of http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4879883 mentions, Java maintains these buffers outside the normal Java heap.
A:
There are probably other ways to do this with native code (or profiling, etc.), but something like this might work in Java:
Class c = java.nio.Bits.class;
Field maxMemory = c.getDeclaredField("maxMemory");
maxMemory.setAccessible(true);
Field reservedMemory = c.getDeclaredField("reservedMemory");
reservedMemory.setAccessible(true);
synchronized (c) {
Long maxMemoryValue = (Long)maxMemory.get(null);
Long reservedMemoryValue = (Long)reservedMemory.get(null);
}
kschneid
2010-10-12 19:00:16