[LLVMdev] Re: Newbie questions

Tom Tromey tromey at redhat.com
Tue May 2 10:24:05 PDT 2006

>>>>> "Alkis" == Alkis Evlogimenos <alkis at evlogimenos.com> writes:

>> E.g., suppose we want to devirtualize not because a method
>> is being called on the result of 'new' (since this is a particularly
>> simple case) but because a method is being called on an object whose
>> class happens to be 'final'.  In this case we need to know some
>> properties of the java type.

Alkis> I think this example is even simpler than the method caled on the
Alkis> result of new. When translating invokevitual on objects of final
Alkis> classes just call the method directly and don't perform an indirect
Alkis> function call though the vtable. Ditto for final methods.

I think I didn't flesh out the example enough.

A java compiler will emit invokevirtual calls using the qualifying
type as seen in the source.  So for instance, in a case like:

    Object x = "string";
    int z = x.hashCode();

(which is dumb, but you get the idea :-) the compiler will generate an
invokevirtual of 'Object.hashCode'.

However, at runtime the jit could infer that the real type of 'x' is
always String, and so emit a direct call to String.hashCode instead.

In non-trivial cases it is a lot simpler to do this kind of thing on
the SSA representation (as I'm sure you know :-).  And in this case
you need to be able to map from the LLVM representation back to the
java types.


More information about the llvm-dev mailing list