guardWithTest

Attila Szegedi szegedia at gmail.com
Mon May 25 08:45:13 PDT 2009


Also, IIRC (and I might be wrong about that, memory is sometimes  
failing...), guardWithTest was introduced when there was no  
JavaMethodHandle; John pretty much specified few general-purpose  
method handle types creatable by static factory methods in the  
MethodHandles utility class, and that was it.

Attila.

On 2009.05.25., at 16:13, Fredrik Öhrström wrote:

> Arthur Peters skrev:
>> 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?
>>
>> -Arthur
> Well, I agree with you. It should be possible for you to use your own
> GuardWithTest implementation and it should compile efficiently.
>
> However you will find that it is impossible for you to create a  
> generic
> GuardWithTest that works on any method since the combinatorial
> explosion of possible method types cannot be anticipated practically
> beforehand.
>
> The factory creates the secret code that can adapt to any method type.
>
> However with a single backwards compatible change to JSR292 it would
> be possible for you to implement your own generic GuardWithTest!
>
> And in, fact, as an example I have used exactly the kind of if  
> statement
> solution that you propose. You can read about it here:
> http://blogs.oracle.com/ohrstrom/2009/05/pulling_a_machine_code_rabbit.html
>
> //Fredrik



More information about the mlvm-dev mailing list