When I use the profiler in NetBeans 7.1, I am not seeing the expected invocation number for my methods.
To test this I created a simple program that has 3 methods that are each called ten thousand times.
public class profilerTest {
static int one;
static int two;
static int three;
public static void main(String args[]) {
for (int i = 0 ;i<= 10000; i++)one();
}
public static void one() {
System.out.println("one:" + one++);
two();
}
public static void two() {
System.out.println("two:" + two++);
three();
}
public static void three() {
System.out.println("three:" + three++);
}
}
I expect to see 10000 invocations per method in my profiler snapshot that I take at the end of the profiling. However, the results I get gives significantly lower numbers of invocations for each method, and they are also different for each of the three methods.
I'm curious to what is causing this, and if and how it's possible to get the actual invocation count for each method.
Here is a screenshot of the results:
I did some more digging, and found this bug report that talks about intrinsic methods and method inlining in the java hotspot compiler. The suggested fix there is to use -Xint option for jdk1.6. On JDK 1.7 however, this doesn't change my results.