guardWithTest

Charles Oliver Nutter charles.nutter at sun.com
Sun May 24 12:46:05 PDT 2009


Arthur Peters wrote:
> I'm a lurker, but I have a question.
> 
> What makes guardWithTest better or faster than simply using a method 
> handle of a method with an if statement in it?
> 
> Like:
> Object meth(...args...)  {
>   if(pred)
>     guard;
>   else
>     callTargetMethod;
> }
> 
> Can the JVM optimize the guardWithTest version better? Does it handle 
> primitive types better?

I believe the primary difference is that the JVM can "know" about 
guardWithTest and therefore it will not interfere in 
optimization/inlining of the associated handles. Writing your own Java 
implementation would introduce a single generic piece of code into 
many/most/all call paths, obscuring any unique, inlinable path.

- Charlie



More information about the mlvm-dev mailing list