John Rose schrieb: > On Sep 11, 2008, at 8:51 AM, Jochen Theodorou wrote: > >> can you say how much Hotspot can do to reduce the overhead of something >> >> like >> >> >> Class x = xInstance==null? NullObject.class : xInstance.getClass() >> >> Class y = yInstance==null? null: yInstance.getClass() > > HotSpot is very good at hiding null checks, especially when nulls are > rare (as is the common case). Such user-written null checks are > optimized on the same footing as all the implicit null checks required > by many bytecodes (e.g., field, element, and method references). That > is to say, all such null checks are optimized very well, usually folded > into an immediately following memory reference, with a hint to the SEGV > trap handler about what to do if the hardware reports an indirection > through null. That is to say, such checks are free, if in fact the > branch is never (or very rarely) taken.
well.. since an argument can be nullit is not unlikely that the branch will be taken. Method calls on null might be rare, so that part may be rare.... which reminds me... if I remember correctly, then invokedynamic won't allow calls on null. Of course I don't really want to invoke a method on null, but on NullObject, where null is the input on my stack as receiver... this sounds like a problem. will a MethodHandle even be entered if the receiver is null and will be replaced in the MethodHandle itself? That means I won't call methods on null using an unreflected method, but a bound MethodHandle might get null as input for the receiver part... Will that be allowed? Hmm.. mabe it istill not clear... let us say the stack contains this: null and I want to call a method foo(), that means null is the receiver. But instead of using the unreflected MH for foo() I use something that replaces the receiver in a BMH.. so inside it will be a valid method call, but will I come to this point even? bye blackdrag -- Jochen "blackdrag" Theodorou The Groovy Project Tech Lead (http://groovy.codehaus.org) http://blackdragsview.blogspot.com/ http://www.g2one.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "JVM Languages" group. To post to this group, send email to jvm-languages@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/jvm-languages?hl=en -~----------~----~----~----~------~----~------~--~---