Compiled call version seems to be slower

Ulf Zibis Ulf.Zibis at gmx.de
Mon Nov 30 16:26:24 PST 2009


Am 01.12.2009 01:01, Tom Rodriguez schrieb:
> On Nov 30, 2009, at 3:32 PM, Ulf Zibis wrote:
>
>   
>>>  You could reshape your code to look like that if you wanted to avoid multiple copies.
>>>  
>>>       
>> Hm, any idea how to do that ß
>>     
>
> You need to capture all possible return values into a local variable and return that in one place. You'll probably need to use a break to get out of the loop.  So a structure something like this:
>
> int result = -1;
> while (foo) {
>   if (cond) {
>     result = 1;
>     break;
>   }
>   if (cond2) {
>     result = 2;
>     break;
>   }
> }
> return result;
>
> it's ugly so make sure it's worth it.  There are probably other ways of structuring it too.
>   

Yes, same as Chuck proposed, that's a possible solution.
I guess you convince, that this javac behavior makes the 
try-finally-without-catch construct a not-to-do, but it's often used and 
often a recommended design in Java books.

-Ulf




More information about the hotspot-compiler-dev mailing list