This is the mail archive of the mailing list for the Java project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Alpha vs. new ABI

Tom Tromey wrote:
> There was some talk on the gcc list a few weeks ago about 0-length
> arrays.  I thought the consensus was that they would only be supported
> at the end of a structure.  So while this might work right now, I'm
> concerned that it will stop working at some point in the future.

As I remember it, there are two valid reasons for zero-length arrays:

1) variable-sized structures
2) avoid special case if an array size macro evaluates to zero

In the first case, the array definitely must be last, but I thought the C99
syntax is preferred anyhow.  The second case must continue to work because it is
widely used (e.g. in the Linux kernel).

But I am not sure that a zero-length will continue to guarantee alignment.  A
member like "jdouble unused[0]" may as well have alignment of char.  (I'm not a
language expert, that's my interpretation of the current practice in gcc.)

> One suggestion that came up before was to change both the compiler and
> the runtime to agree on alignment of the data member of JArray.  Then
> we could reduce _Jv_GetArrayElementFromElementType to a trivially
> inlineable function.

Isn't that the reason gcj now enforces a minimum of ptr alignment on the data
member of arrays?  I know Alex made that change for the new ABI, but I don't
remember exactly why.

> In the runtime we could implement this by putting
> __attribute__((aligned (something))) on the `data' field.
> `something' would be chosen to be maximal alignment for the platform.
> Maybe just `8' would suffice for now.

That'll waste 4 bytes on x86.

Whatever the case, the alignment specified in array.h should _exactly_ match the
behavior in the frontend.  Right now it doesn't.  I'm not familiar enough with
__attribute__((aligned)) etc. to recommend anything.

> I also don't know how risky it is, but I think it is likely the test
> suite would catch errors.  On the alpha I currently see that
> `helloworld' fails, and for other failures I seem to recall that we
> added at least one test case specifically to detect array data
> alignment bugs.

With Per's suggested patch my Alpha build passes most of the libjava testsuite.

The previous array alignment bugs had to do with static arrays, which aren't
currently a problem (or, more precisely, fail just as dynamic arrays do).

Jeff Sturm

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]