Does java do runtime optimization?

I am observing this weird behaviour while profiling a java application.

It seems like java actually inlines methods while running.

For example, consider

int foo() {

int x;

x = bar(x);

return x;

}

if foo is called 100 times, it calls bar() the first few times (28 times ) but soon stops calling bar().

When I have a System.out inside bar(), it is called 100 times.. Without it, I see it being called 28 times and then it doesn't.

Any comments?

[541 byte] By [neeluap] at [2007-9-26 1:35:07]
# 1
You're seeing Just-In-Time Compilation (or perhaps Hotspot) in action. JIT will do its own profiling and selectively inline what commonly executed methods it can.Try running with the -classic switch first on your java command line.
DragonMan at 2007-6-29 2:19:05 > top of Java-index,Archived Forums,Java Programming...
# 2
Yes, Java does do runtime optimizations but I don't see how you can count the calls to bar without affecting it.What do you have in the method bar()?
jsalonen at 2007-6-29 2:19:05 > top of Java-index,Archived Forums,Java Programming...