fix static field alignment calculation

The previous code caused overlap between 64-bit fields and subsequent
fields under certain circumstances on 32-bit systems.
This commit is contained in:
Joel Dice 2012-03-17 22:45:35 -06:00
parent 9a50e69587
commit 674c560494
2 changed files with 6 additions and 10 deletions

View File

@ -502,10 +502,8 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
}
if (fieldFlags(t, field) & ACC_STATIC) {
unsigned excess = (targetStaticOffset % targetSize)
% TargetBytesPerWord;
if (excess) {
targetStaticOffset += TargetBytesPerWord - excess;
while (targetStaticOffset % targetSize) {
++ targetStaticOffset;
}
buildStaticOffset = fieldOffset(t, field);

View File

@ -1164,9 +1164,8 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool)
unsigned size = fieldSize(t, code);
if (flags & ACC_STATIC) {
unsigned excess = (staticOffset % size) % BytesPerWord;
if (excess) {
staticOffset += BytesPerWord - excess;
while (staticOffset % size) {
++ staticOffset;
}
fieldOffset(t, field) = staticOffset;
@ -1205,9 +1204,8 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool)
for (unsigned i = 0, offset = 0; i < staticCount; ++i) {
unsigned size = fieldSize(t, RUNTIME_ARRAY_BODY(staticTypes)[i]);
unsigned excess = offset % size;
if (excess) {
offset += BytesPerWord - excess;
while (offset % size) {
++ offset;
}
unsigned value = intArrayBody(t, staticValueTable, i);