views:

149

answers:

1

Is there a way to control the optimization level of the java compiler that Eclipse uses when building a project? Or is this question not relevant anymore, is all optimization deferred to the vm?

The reason I'm asking is that I recently wrote a quick test doing this:

private static int test_f(int i) { return i * 42; }

...

int z = 41;
for(int i = 0; i < 10000; ++i) { z = z*42; }         // this loop runs in X seconds
for(int i = 0; i < 10000; ++i) { z = test_f(z); }    // this loop runs in 10*X seconds

The results of this tests imples test_f() is not being inlined, even though it really is a prime candidate for it. It should also be possible to do this inlining at compile time.

The environment/target vm is Android/Dalvik.

UPDATE: I investigated this further, and it turns out Dalvik doesn't do inlining at this date.

+1  A: 

Yes, optimization is basically done by the JIT these days for desktop Java, so compilers don't do things like inlining. -O isn't even listed as an option by javac these days (although it doesn't break compilation; I suspect it makes no difference).

Don't forget that Dalvik doesn't have a JIT.

Jon Skeet