lucy-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nick Wellnhofer (JIRA)" <>
Subject [lucy-issues] [jira] [Commented] (CLOWNFISH-12) Clownfish interfaces
Date Fri, 26 Feb 2016 21:56:18 GMT


Nick Wellnhofer commented on CLOWNFISH-12:

I have another proposal for implementing interfaces based on the following paper.

Efficient Implementation of Java Interfaces: Invokeinterface Considered Harmless

This approach uses a hashtable of function pointers with generated code for conflict resolution.
It's geared toward JITted code, but with a fixed table size and some argument mangling, it
should be possible to implement it in C. The overall space and time overhead should be acceptable,
and object pointers can be used directly as interface values.

See here for a sketch:

> Clownfish interfaces
> --------------------
>                 Key: CLOWNFISH-12
>                 URL:
>             Project: Apache Lucy-Clownfish
>          Issue Type: New Feature
>          Components: Core
>            Reporter: Nick Wellnhofer
>            Priority: Minor
>             Fix For: 0.6.0
> Java-style interfaces would be a nice feature for Clownfish. Here's a sketch of how it
could be implemented. It's basically an adaption of the technique described by Bjarne Stroustrup
in his paper [Multiple Inheritance for C++|].
> If a subclass implements an interface, an additional instance variable pointing to an
interface method table is created. A pointer to this instance variable represents an interface
reference. The interface method table contains
> * the offset of the pointer to the interface method table from the start of the object.
> * a variable length array of method pointers to the implementations of the interface's
> * optionally a pointer to an Interface object for introspection.
> Every subclass/interface combination needs a separate interface method table. Subclasses
that don't override any of the interface methods of a parent class can reuse the parent class's
> The memory layout would look like this:
> {noformat}
>      object
>    +--------+
>    | head   |
>    | vtable |     itable
>    | ivars  |   +---------+
> -->| itable +-->| offset  |
>    | ivars  |   | method1 |
>    +--------+   | method2 |
>                 | method3 |
>                 | method4 |
>                 | ...     |
>                 +---------+
> {noformat}
> Converting an object to an interface reference is done by returning a pointer to the
itable struct member. Converting back to the object is done by subtracting the offset in the
itable. Method invocation from an interface reference is done by looking up the method pointer
and calling it with the original object.
> In host languages, an interface is represented by a class with the interface's methods.
Objects of this class contain the interface reference (address of the itable instance variable).

This message was sent by Atlassian JIRA

View raw message