On Thu, Jun 13, 2013 at 2:55 PM, Simone Bordet <simone...@gmail.com> wrote:
> Hi,
>
> On Thu, Jun 13, 2013 at 2:45 PM, Martin Thompson <mjp...@gmail.com> wrote:
>> Lovely little Java performance issue with Generics. Thanks to Gil Tene for
>> pointing this out.
>>
>>
>> http://developer.amd.com/community/blog/a-java-generics-performance-puzzler/
>>
>> What a shame Generics were not reified and done right!
>
> Seems more a non optimal JIT implementation to me.
> The JIT should be able to remove the checkcast bytecode once it sees
> that's not needed, no ?
>
> I mean the JRockit JIT compiler was able to inline to a constant even
> 3 MethodHandler calls (see
> http://medianetwork.oracle.com/video/player/589206011001, at 12:30) ,
> would not HotSpot be able to just remove an unneeded checkcast ?
The final part (that I overlooked) talks about not being possible to
remove the checkcast because it _may_ throw an exception, but I find
the reasoning similar to not being able to remove the null checks -
yet there are ways to do this.
Plus, is not the semantic broken ?
If I were able to put something that was not of the right type into
the source list, then
destList.add(sourceList.get(i))
should throw the same ClassCastException, no ?
--
You received this message because you are subscribed to the Google Groups "mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mechanical-symp...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
To unsubscribe from this group and stop receiving emails from it, send an email to mechanical-sympathy+unsub...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to mechanical-symp...@googlegroups.com.
The point can be seen by looking at the generated assembly code, and seeing the checkcast staring back at you. The caller is required to place a checkcast there because it is casting an Object to a specific class and is about to use the object as such. I don't care if it's for a type specific put, a getfield, or an invoke, it can't do any of those safely without the check, and must through an exception if the class is wrong (which can easily be made to happen in valid unchevked ways by storing a wrong object type into the collection).
So if someone can show generated assembly for this sort of thing (a get from a generic collection that had a million things deposited in it before, followed by a getfield on the thing you got) which somehow does not perform the check cast, I'm
very interested.
And BTW, AFAIK the reason null checks can be optimzed away when this cant is simple: null checks are implicitly (hardware) supported on all access through virtual memory : low address memory is protevted such that an access through a null will always SEGV, and the JVMs are smart enough to catch the SEGV and realize what happened ("I was accessing this thing through a nul pointer"). There is no equivalent hardware assist for detecting "I accessed a field on a wrong object type" - that just results in undetected data corruption.
Thanks. I get why the JVM needs to pull the MyClass header if the local variable bytecode is emitted, and doubly so if you actually call a method on the local variable.
My question was why can't javac detect that the local variable is just used as Object (as in the original example, not yours where you call getOddOrEven) and emit bytecode equivalent to my static method? Since this is inside a method body, it should be safe.
--
Il giorno 15/giu/2013 01:01, "Gil Tene" <g...@azulsystems.com> ha scritto:
>
> The very first instruction in the sequence (mov ebx,DWORD PTR [eax+0x4]) is the load of the klass field from the header.
Thanks !