Tobias has posted 1 posts at DZone. View Full User Profile

My JVM Wishlist (Part 1): Interface injection

07.16.2008
| 13417 views |
  • submit to reddit

How could interface injection implement a Meta Object Protocol?


There is a great project initialized by Attila Szegedi of the JVM-languages community to create a common meta object protocol (MOP) for all languages on the JVM. With interface injection this would be a simple task.


  1. Let all objects in your language (that supports the MOP) implement the (probably not injectable) interface java.dyn.SupportsMetaObjectProtocol. An interface with only one method: java.dyn.MetaObjectProtocol getMetaObjectProtocol(); This would return the implementation of the java.dyn.MetaObjectProtocol interface for your particular language.

  2. The java.dyn.MetaObjectProtocol contains methods for getting method handles for each dynamic language construct that the community have agreed to be a good common construct, such as getters and setters for subscript operations. These method handles would come from the actual implementation of them for your particular language, and would therefore benefit from every imaginable optimization you have cooked up for your language.

  3. When the main interface of my language is being injected into a class from your language it finds that your class implements java.dyn.SupportsMetaObjectProtocol and uses that to get the method handles for all dynamic language constructs supported by my language, rebinding them them to the method names used in my language.

And as simple as that interface injection has been used to implement a common ground for all languages on the Java platform with absolutely no overhead.

I'm not saying that this is the way to implement a meta object protocol for the Java platform, I am just suggesting one way to do it, someone a lot smarter than me might come up with a much better implementation.

To sum things up: I can't wait until the JVM supports interface injection.

Published at DZone with permission of its author, Tobias Ivarsson.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)