[Jack-Devel] packed data structures in jack2

PrevNext  Index
DateWed, 18 Jul 2012 20:41:12 -0700
From Basil Nutmeg <[hidden] at li95-58 dot members dot linode dot com>
To[hidden] at lists dot jackaudio dot org
Follow-UpStéphane Letz Re: [Jack-Devel] packed data structures in jack2
Hello,

I found Jack2 was crashing on my ARM cpu, and I traced it down to a
misuse of __attribute__((packed)).

This CPU doesn't support misaligned memory references. packed structs are
supported, by having the compiler emit a longer sequence of instructions.
However, consider this code from common/JackAtomicArrayState.h:

... CAS(Counter1(old_val), Counter1(new_val), (UInt32*)&fCounter) ...

fCounter is a member of a class which is packed, and this happens to make
it misaligned. Its address is taken and passed off to a different
function, where it appears to the compiler to be an ordinary pointer. The
compiler justifiably assumes the pointer is aligned, so it emits normal
code, and the code crashes at runtime because the pointer isn't actually
aligned.

Looking around, I was surprised to see that lots of classes in Jack2 are
marked packed, for example classes like JackConnectionManager,
JackClientControl, and JackEngineControl, and I'm puzzled.

Making JackEngineControl packed, for example, shrinks its nominal size
from 1040 to 1032 (on this platform). It doesn't look like there are that
many JackEngineControl instances floating around at runtime, so this isn't
actually saving much memory. And it doesn't appear to be serialized
anywhere. And on the down side, packed makes many of JackEngineControl's
fields misaligned, making them slower to access.

Also, it's possible to shrink JackEngineControl to size 1032 just by
reordering the fields, without using packed at all.

So I'm curious, why so much use of packed? Is there some reason I missed,
or is it just a general attempt to save memory? If the latter, could I
politely suggest this approach be reconsidered?

Thanks,

-- Basil
PrevNext  Index

1342669279.6949_0.ltw:2,a <20120719034112.GA27528 at li95-58 dot members dot linode dot com>