On Monday 07 December 2009 17:26:03 Joe.Whitney 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).
You would need to add support to the JVM as well, of course. Unless you are thinking of using Clojure's CLR backend. > 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). The JVM is incapable of expressing structs so no JVM-based language can support them. CLR-based languages supporting structs (e.g. C# and F#) simply delegate the work to the CLR. > 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. When the JVM was designed and built it was common to rely upon a uniform representation and efficient allocation by the runtime to obtain decent performance without having to support arbitrary value types. Languages like OCaml also do this. Since then, the CLR has shown that value types (structs and primitive types) can relieve a lot of stress from the GC and that this is much more important in the context of multicores because concurrent GCs are (and will probably always be) inherently slow. > 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. Yes. In a recent discussion on this list, structs were cited as probably the single most important feature to add to the JVM. I wouldn't hold your breath though: I waited for tail calls to be added to the JVM for years before giving up and writing my own VM with structs and tail calls specifically designed for scientific computing... -- Dr Jon Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?e -- 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.
