Not really what you're after, but in order to allow system native
methods to be implemented in Java on the iSeries we put in place a
mechanism to allow one object to be mapped over another, and then a
way to be able to specify the precise layout of fields.  As a
simplistic example, the Double.doubleToLongBits method could be
implemented by creating a Double object, then mapping a Long object
over the top of it and extracting the long value.  (This specific use
wasn't really useful, of course, since the cost of creating the Long
object would swamp any savings.)  Unsafe as Hell, of course, since
fields could be mapped arbitrarily and unchecked casting performed,
along with arbitrary address arithmetic, but OK for "trustworthy" code
that was replacing unsafe C native methods anyway.

(Since this was pre-annotation, we used a String literal in the class
to inform us of the mappings, etc.  The literal would only be looked
for and interpreted for classes loaded from a privileged directory.)

The major advantage was that the Java could then be inlined by the
JIT, resulting in the efficiency of JIT "built-ins" without the
attendant complexity and maintenance difficulties.

On Dec 7, 11:26 am, "Joe.Whitney" <[email protected]> wrote:
> Hello,
>
> I am trying to understand what barriers, if any, exist to supporting C-
> style structs in JVM languages.  I have considered trying to add
> support of such to Clojure for my own research programming (I work on
> local search algorithms for bioinformatics applications).  I assume
> that the right way to do this will involve emitting byte code, but I
> have not yet studied the byte code or its verification by the JVM in
> enough detail.  I thought this group might be able to answer the
> following questions before I invest time in a fruitless search for a
> good solution:
>
> 1) Is there any inherent limitation in the bytecode, or the JVM
> verification algorithm, which makes it impractical to represent
> structured, non-reference types?  Intuitively it seems that functions
> and operations on structs are reducible to functions and operations on
> basic types (int, float and friends).  But, while C# supports structs,
> Java does not and I have not seen any indication that it will, and I
> have not seen a JVM language which does either.  (Maybe Scala does?
> Not familiar enough with it to be sure).  I can't tell if this is just
> for "religious" reasons, but it seems to me an obviously useful
> feature and there should be a good reason it isn't included.
>
> 2) If this has already been implemented for some language, can someone
> provide a link to details of how it was implemented?
>
> This feature is very important for certain algorithmic applications,
> where one wants to store a very large number of small records -- the
> memory/performance penalty (especially memory) of having one or more
> extra pointers per record using reference types (Objects) is really
> frustrating.  I'm sure this must be well-trodden ground for JVM
> language implementors but I haven't been able to track down a
> comprehensive discussion online.
>
> Many thanks in advance for your insights,
>
> Joe

--

You received this message because you are subscribed to the Google Groups "JVM 
Languages" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jvm-languages?hl=en.


Reply via email to