Skip to content

gcj optimization pass

Today I wrote a GCC optimizer pass. The new pass is specific to
gcj and does a simple form of devirtualization. The idea here is
that if we have some extra information about a method call, we can
turn an indirect virtual call into a direct call.

My pass does this in one particular case. If the “receiver”
object of a virtual call was allocated with new in the
current method, then we know its exact type, and we can devirtualize.
This is conceptually trivial on the SSA form.

I wrote this pass since I had been playing with similar code for
my LLVM-based JIT, and I wanted to compare LLVM and GCC here — I’d
never written a GCC optimization pass and was curious about the
effort involved.

It turns out to be simple. This pass is about 200 lines of code.
And, when building libgcj, there were more than 6000 cases where it
triggered. I’m encouraged by this and now I’m considering writing
more gcj-specific optimization passes. Some ideas:

  • “Strength reduce” interface calls to ordinary virtual calls.
    The only difficulty here is in the bookkeeping; it could be
    inserted into the current pass.
  • Special handling for StringBuffer and
    StringBuilder.
  • A simple gcj-specific VRP-like pass, to handle array bounds
    checks, null pointer checks, redundant checkcast calls,
    and the like.

I guess some of these would make ok SoC projects.

One Trackback/Pingback

  1. [...] can be useful for other VMs. Below a GCJ developer describes a simple devirtualization pass.http://tromey.com/blog/?p=12This answer .Please specify the necessary improvements. Edit Link Text Show answer summary [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*