From 907382bceecc963cb520a5d1505988eee94396ac Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 31 Mar 2008 18:34:57 -0600 Subject: [PATCH] fix broken field alignment in parseFieldTable which caused longs to overlap other fields on 32-bit systems in certain cases --- src/machine.cpp | 4 ++-- test/Misc.java | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/machine.cpp b/src/machine.cpp index 848b111588..e6f391ee32 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -861,7 +861,7 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool) if (flags & ACC_STATIC) { unsigned size = fieldSize(t, code); - unsigned excess = staticOffset % size; + unsigned excess = (staticOffset % size) % BytesPerWord; if (excess) { staticOffset += BytesPerWord - excess; } @@ -878,7 +878,7 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool) abort(t); // todo: handle non-static field initializers } - unsigned excess = memberOffset % fieldSize(t, code); + unsigned excess = (memberOffset % fieldSize(t, code)) % BytesPerWord; if (excess) { memberOffset += BytesPerWord - excess; } diff --git a/test/Misc.java b/test/Misc.java index f75b38d92c..d4a2b3251c 100644 --- a/test/Misc.java +++ b/test/Misc.java @@ -2,7 +2,22 @@ public class Misc { private static int alpha; private static int beta; private static byte byte1, byte2, byte3; + private int gamma; + private int pajama; + private boolean boolean1; + private boolean boolean2; + private long time; + + public Misc() { + expect(! boolean1); + expect(! boolean2); + + time = 0xffffffffffffffffL; + + expect(! boolean1); + expect(! boolean2); + } private String foo(String s) { return s;