Strange profiling results: definitely non-bottleneck method pops up

Posted by jkff on Stack Overflow See other posts from Stack Overflow or by jkff
Published on 2010-05-07T12:37:35Z Indexed on 2010/05/07 13:18 UTC
Read the original article Hit count: 299

Filed under:
|
|
|

I'm profiling a program using sampling profiling in YourKit and JProfiler, and also "manually" (I launch it and press Ctrl-Break several times to get thread dumps).

All three methods give me extremely strange results: some tens of percents of time spent in a 3-line method that does not even do any allocation or synchronization and doesn't have loops etc. Moreover, after I made this method into a NOP and even removed its invocation completely, the observable program performance didn't change at all (although it got a negligible memory leak, since it was a method for freeing a cheap resource).

I'm thinking that this might be because of the constraints that JVM puts on the moments at which a thread's stacktrace may be taken, and it somehow turns out that in my program it is exactly the moments where this method is invoked, although there is absolutely nothing special about it or the context in which it is invoked.

What can be the explanation for this phenomenon? What are the aforementioned constraints? What further measurements can I take to clarify the situation?

© Stack Overflow or respective owner

Related posts about java

Related posts about Performance