I have been using Yourkit 8.0 to profile a mathematically-intensive application running under Mac OS X (10.5.7, Apple JDK 1.6.0\_06-b06-57), and have noticed some strange behavior in the CPU profiling results.

For instance - I did a profiling run using sampling, which reported that 40% of the application's 10-minute runtime was spent in the StrictMath.atan method. I found this puzzling, but I took it at it's word and spent a bit of time replacing atan with an extremely simply polynomial fit.

When I ran the application again, it took almost exactly the same time as before (10 minutes) - but my atan replacement showed up nowhere in the profiling results. Instead, the runtime percentages of the other major hotspots simply increased to make up for it.

To summarize:

RESULTS WITH StrictMath.atan (native method)  

Total runtime: 10 minutes  

Method 1: 20%  

Method 2: 20%  

Method 3: 20%  

StrictMath.atan: 40%  

RESULTS WITH simplified, pure Java atan  

Total runtime: 10 minutes  

Method 1: 33%  

Method 2: 33%  

Method 3: 33%  

(Methods 1,2,3 do not perform any atan calls)

Any idea what is up with this behavior? I got the same results using EJ-Technologies' JProfiler. It seems like the JDK profiling API reports inaccurate results for native methods, at least under OS X.