[H-GEN] Which is better?

Adrian Sutton adrian at intencha.com
Mon Apr 26 03:06:27 EDT 2004


On 26/04/2004, at 3:53 PM, Anthony Towns wrote:

> Consider if doCalcs() was something like (my Java's a bit rusty):
>
> 	class foo {
> 		static int i = 0;
> 		static int doCalcs(int v) {
> 			i = i + 3;
> 			return v - i;
> 		}
> 	}
>
> doCalcs(10) will return 7 on the first invocation, then 4, then 1,
> then -2, and so on.

In this case the method won't be inlined and would have to be run 
multiple times, but if it were something like:

static int doCalcs(int v) {
	return v;
}

or

static int doCalcs(int v) {
	return 5;
}

the JIT compiler would almost certainly inline it if the code was run 
enough times to warrant being compiled.  Generally the optimizations 
that the HotSpot compiler (which provides the JIT compilation for Sun 
and Sun derived JVMs) are absolutely astounding.  As most people have 
pointed out - don't try to predict it, you'll almost certainly be 
wrong.

Regards,

Adrian Sutton.
----------------------------------------------
Intencha "tomorrow's technology today"
Ph: 38478913 0422236329
Suite 8/29 Oatland Crescent
Holland Park West 4121
Australia QLD
www.intencha.com





More information about the General mailing list