Hi,
A nice feature we offer customers is our Tracer API which allows custom trace extensions to be plugged into our management console as well as access to our JVMPI agent counters - high resolution clock time, cpu time, gc time, thread blocking and waiting, object allocation size, and clock adjusted).
http://www.jinspired.com/products/jdbinsight/api/com/jinspired/jxinsight/trace/Tracer.htmlimport com.jinspired.jxinsight.trace.Tracer;
import java.util.*;
public class Main {
public static void main(String[] args) {
long[] start; long end[];
Object[] array;
start = Tracer.getThreadCounters();
array = new Object[0];
end = Tracer.getThreadCounters();
System.out.println("new Object[0] = " + (end[Tracer.ALLOCATION] - start[Tracer.ALLOCATION]) + " bytes");
start = Tracer.getThreadCounters();
array = new Object[1];
end = Tracer.getThreadCounters();
System.out.println("new Object[1] = " + (end[Tracer.ALLOCATION] - start[Tracer.ALLOCATION]) + " bytes");
start = Tracer.getThreadCounters();
array = new Object[2];
end = Tracer.getThreadCounters();
System.out.println("new Object[2] = " + (end[Tracer.ALLOCATION] - start[Tracer.ALLOCATION]) + " bytes");
start = Tracer.getThreadCounters();
array = new Object[20];
end = Tracer.getThreadCounters();
System.out.println("new Object[20] = " + (end[Tracer.ALLOCATION] - start[Tracer.ALLOCATION]) + " bytes");
start = Tracer.getThreadCounters();
array = new Object[20][0];
end = Tracer.getThreadCounters();
System.out.println("new Object[20][0] = " + (end[Tracer.ALLOCATION] - start[Tracer.ALLOCATION]) + " bytes");
start = Tracer.getThreadCounters();
array = new Object[20][1];
end = Tracer.getThreadCounters();
System.out.println("new Object[20][1] = " + (end[Tracer.ALLOCATION] - start[Tracer.ALLOCATION]) + " bytes");
start = Tracer.getThreadCounters();
array = new Object[20][2];
end = Tracer.getThreadCounters();
System.out.println("new Object[20][2] = " + (end[Tracer.ALLOCATION] - start[Tracer.ALLOCATION]) + " bytes");
start = Tracer.getThreadCounters();
array = new Object[40];
end = Tracer.getThreadCounters();
System.out.println("new Object[40] = " + (end[Tracer.ALLOCATION] - start[Tracer.ALLOCATION]) + " bytes");
new HashMap(); // preload classes
start = Tracer.getThreadCounters();
new HashMap();
end = Tracer.getThreadCounters();
System.out.println("new HashMap() = " + (end[Tracer.ALLOCATION] - start[Tracer.ALLOCATION]) + " bytes");
new Hashtable(); // preload classes
start = Tracer.getThreadCounters();
new Hashtable();
end = Tracer.getThreadCounters();
System.out.println("new HashTable() = " + (end[Tracer.ALLOCATION] - start[Tracer.ALLOCATION]) + " bytes");
new TreeMap(); // preload classes
start = Tracer.getThreadCounters();
new TreeMap();
end = Tracer.getThreadCounters();
System.out.println("new TreeMap() = " + (end[Tracer.ALLOCATION] - start[Tracer.ALLOCATION]) + " bytes");
start = Tracer.getThreadCounters();
array = new Object[100];
end = Tracer.getThreadCounters();
System.out.println("new Object[100] = " + (end[Tracer.ALLOCATION] - start[Tracer.ALLOCATION]) + " bytes");
new ArrayList(); // preload classes
start = Tracer.getThreadCounters();
new ArrayList(100);
end = Tracer.getThreadCounters();
System.out.println("new ArrayList(100) = " + (end[Tracer.ALLOCATION] - start[Tracer.ALLOCATION]) + " bytes");
new Vector(); // preload classes
start = Tracer.getThreadCounters();
new Vector(100);
end = Tracer.getThreadCounters();
System.out.println("new Vector(100) = " + (end[Tracer.ALLOCATION] - start[Tracer.ALLOCATION]) + " bytes");
start = Tracer.getThreadCounters();
synchronized(Tracer.class) {
try {
Tracer.class.wait(10000);
} catch (InterruptedException e) {}
}
end = Tracer.getThreadCounters();
System.out.println("Thread.sleeep(10000) = " + (end[Tracer.WAITING] - start[Tracer.WAITING]) + " microseconds");
}
}
Results JDK 1.4.2
========================
new Object[0] = 16 bytes
new Object[1] = 16 bytes
new Object[2] = 24 bytes
new Object[20] = 96 bytes
new Object[20][0] = 416 bytes
new Object[20][1] = 416 bytes
new Object[20][2] = 576 bytes
new Object[40] = 176 bytes
new HashMap() = 120 bytes
new HashTable() = 96 bytes
new TreeMap() = 40 bytes
new Object[100] = 416 bytes
new ArrayList(100) = 440 bytes
new Vector(100) = 440 bytes
Thread.sleeep(10000) = 9581829 microseconds
Please note you will have to run the Java process with our agent loaded using -Xrunjdbinsight:a=t
William Louth
JXInsight Product Architect
CTO, JInspired
"J*EE tuning, testing and tracing with JXInsight"
http://www.jinspired.com