Language extensions ?

Robin Garner
Thu Mar 27 06:48:00 GMT 2003

----- Original Message -----
From: Alexandre Oliva <>
Date: 27 Mar 2003 01:35:29 -0300
To: "Robin Garner" <>
Subject: Re: Language extensions ?

> On Mar 27, 2003, "Robin Garner" <> wrote:
> > What would be _really_ nice would be if gcj provided an address type
> > as an extension to the language, and allowed unsafe casts, pointer
> > arithmetic etc. in ways similar to Modula 3 and C# (at least until
> > java saw the light :).
> I don't think this requires language extensions.  Here's a random
> thought that just occurred to me:
> public class VMMemory {
>   public static byte asByte[];
>   public static int asInt[];
>   public static long asLong[];
>   // ...
>   public static long getIndexAsChar(Object o);
>   public static long getIndexAsInt(Object o);
>   // ...
> }

So some (native ?) initialization code would have to set asByte, asLong etc to zero, so the arrays line up with the whole of virtual memory ...  and all words would have to be naturally aligned, or else you would need asLong_1, _2, ... _7 as well for the possible alignments of a long.  How does gcc do alignment on architectures like Intel ?

Dereferencing a pointer would cost several instructions, so it would be difficult for java code to compete with C.  More efficient than using native methods for everything, though.

> This may be a bit wasteful in that the array objects have to be
> created in advance, and bounds checking may get, well, tricky, but you
> get the idea.  Depending on the data structure used for arrays, you
> get direct access to memory almost for free, and you don't manipulate
> addresses, only indexes into the arrays.

I'm afraid you have no choice but to manipulate addresses, unless gcj stops storing addresses in object references and starts storing array indices :)  Imagine implementing a tracing collector ...

Sign-up for your own FREE Personalized E-mail at

More information about the Java mailing list