Compiling Structural Types on the JVM

Here's a little sausage making article for JVM language implementors. In Compiling Structural Types on the JVM: A Comparison of Reflective and Generative Techniques from Scala’s Perspective, Gilles Dubochet and Martin Odersky describe

Scala’s compilation technique of structural types for the JVM. The technique uses Java reflection and polymorphic inline caches. Performance measurements of this technique are presented and analysed. Further measurements compare Scala’s reflective technique with the “generative” technique used by Whiteoak to compile structural types. The article ends with a comparison of reflective and generative techniques for compiling structural types. It concludes that generative techniques may, in specific cases, exhibit higher performances than reflective approaches, but that reflective techniques are easier to implement and have fewer restrictions.

There's no discussion of the the proposed JVM "method handles" and whether they might be an even better solution than runtime reflection.

Whiteoak was mentioned previously on LtU.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Link

Here's a link to the paper (behind the ACM paywall).

facepalm

Fixed the article with a um...watchamacallit...clickable hypertextual...um...link. No paywall.

Interface injection

There is another upcoming feature of the JVM called interface injection that allows a language runtime to make a class retro-actively implement an interface. This is helpful, for example, to retrofit an existing JDK class like String or Object or Class to implement an interface defined by another language's runtime. This paper seems like an obvious fit for this language feature, but I didn't see it mentioned.

Re: Interface Injection

I clicked on your title "Interface Injection" wondering if it was a joke on James Iry's "facepalm". Sigh. You missed an opportunity, Ben.

It might be worth producing an LtU topic on the subject of Interface Injection for Java 7. A few links:

Blog by John Rose

Technical article at Sun

A prototype seems to be available through OpenJDK.

Agreed. I had written up a

Agreed. I had written up a blog post on structural typing and mentioned interface injection seems perfect for it:

http://www.draconianoverlord.com/2010/01/17/caller-side-structural-typing.html

To me the biggest flaw with Scala's approach is that the API designer must decide when a caller does/does not get to use structural typing--which in practice means basically never.

With interface injection, the API designer doesn't care--now any interface can be switched out with a structural type via some caller-side JVM magic.