values types for Java

Bryce McKinlay bryce@mckinlay.net.nz
Tue Oct 21 08:58:00 GMT 2003


On Oct 21, 2003, at 8:24 PM, Per Bothner wrote:

> Bryce McKinlay wrote:
>
>> However I'm not keen on the idea of implementing this as a GCJ 
>> extension with some kind of hacked-up syntax. The benefits of 
>> something only supported by GCJ would be limited and the syntax would 
>> not make them elegant to use.
>
> Note I'm not suggesting any syntax changes.  I'm suggesting a
> *convention* to make it easy for a compiler like GCJ to
> implement a fully portable Java class as a stack-allocatable
> value class instead of heap allocation.

What I meant was that if we were to implement structs, we'd be better 
to go all the way and create a simple syntax which makes code using 
them elegant, in addition to a performance optimization.

public struct Point
{
   int x; // fields implicitly final
   int y;
}

This would still compile to portable bytecodes - much like the Java 1.5 
extensions such as generics, there are source code extensions but the 
generated class files can still run on existing VM implementations.

Its worth noting that all of the upcoming language extensions focus on 
improving code productivity, clarity, and safety rather than being 
performance-orientated. One could conclude that if we can make the 
argument that certain programming problems are better solved using 
structs then it would have a better chance as a JSR.

> On the other hand if we had a preliminary imlementation with some
> performance numbers, that might be both a selling point for gcj,
> and it might make it easier to justify a JSR.

Indeed.

Regards

Bryce.




More information about the Java mailing list