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 _______________________________________________ mlvm-dev mailing list mlvm-dev@openjdk.java.net http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev