FloatArrayPlugin & 64bitting
Dave Mason
dmason at sarg.ryerson.ca
Fri Apr 29 19:09:55 UTC 2005
>>>>> On Fri, 29 Apr 2005 09:28:15 -0700, Ian Piumarta <ian.piumarta at inria.fr> said:
> sqMemoryAccess.h defines two macros to replace such casts:
> sqInt oopForPointer(char *rawPoitner)
> char *pointerForOop(sqInt anOop).
> These are effectively no-ops on all combinations other than the
>>> On Apr 29, 2005, at 09:08, Dave Mason wrote:
>> I also assume that firstIndexableField returns a type that is
>> compatible with sqInt.
OK, thanks Ian, I think I understand now. So Tim's original code:
argPtr = ((float *) (interpreterProxy->firstIndexableField(arg)));
for (i = 0; i <= (length - 1); i += 1) {
if ((longAt(argPtr + i)) == 0) {
return interpreterProxy->primitiveFail();
}
should really be a lot more like:
{sqInt argOop = oopForPointer(interpreterProxy->firstIndexableField(arg));
for (i = 0; i <= (length - 1); i += 1) {
if ((floatAt(argOop + i)) == 0.0) {
return interpreterProxy->primitiveFail();
}
}
although, as you say, intAt might be better, depending on context
(but, in general, longAt is just wrong, unless this is actually an
array of doubles).
The reason I suggest converting to sqInt rather than leaving
everything as pointers is because I assume the indexableFields are
allocated on sqInt boundaries, so argOop+i will reference the ith
field, while argPtr+i will reference the ith float, which, on a 64-bit
machine won't be the same if the fields are on sqInt boundaries. This
would be a pretty subtle bug, in that arrays that had the zeros at the
end might not call primitiveFail as expected.
(This paragraph is really just to Ian, as I try to come up to speed on
some of this, and I'm sure the code is actually correct.) I really
need to download the code and look at it, but failing that, I
obviously mis-understand something because if the macros are no-ops
then the arithmetic above looks wrong. argOop+i will be an integer
operation, which is fine for objects of length 1, but not for objects
of length sizeof(sqInt). The only way I can see this working is if
sqInt isn't actually an int but an int* or long* (depending on
architecture) and all the macros do is offset them to/from the vm
image's memory pool.
../Dave
More information about the Vm-dev
mailing list