diff --git a/src/compile.cpp b/src/compile.cpp index 44e27ed088..89e1b6d658 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -2488,6 +2488,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, Compiler::Operand* table; if (instruction == getstatic) { + assert(t, fieldFlags(t, field) & ACC_STATIC); + if (fieldClass(t, field) != methodClass(t, context->method) and classNeedsInit(t, fieldClass(t, field))) { @@ -2501,6 +2503,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, table = frame->append(classStaticTable(t, fieldClass(t, field))); } else { + assert(t, (fieldFlags(t, field) & ACC_STATIC) == 0); + table = frame->popObject(); } @@ -3369,6 +3373,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, object staticTable = 0; if (instruction == putstatic) { + assert(t, fieldFlags(t, field) & ACC_STATIC); + if (fieldClass(t, field) != methodClass(t, context->method) and classNeedsInit(t, fieldClass(t, field))) { @@ -3381,6 +3387,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, } staticTable = classStaticTable(t, fieldClass(t, field)); + } else { + assert(t, (fieldFlags(t, field) & ACC_STATIC) == 0); } Compiler::Operand* value; diff --git a/src/interpret.cpp b/src/interpret.cpp index 72421baf6a..d3919f7117 100644 --- a/src/interpret.cpp +++ b/src/interpret.cpp @@ -1453,7 +1453,9 @@ interpret(Thread* t) object field = resolveField(t, codePool(t, code), index - 1); if (UNLIKELY(exception)) goto throw_; if (throwIfVolatileField(t, field)) goto throw_; - + + assert(t, (fieldFlags(t, field) & ACC_STATIC) == 0); + pushField(t, popObject(t), field); } else { exception = makeNullPointerException(t); @@ -1468,6 +1470,8 @@ interpret(Thread* t) if (UNLIKELY(exception)) goto throw_; if (throwIfVolatileField(t, field)) goto throw_; + assert(t, fieldFlags(t, field) & ACC_STATIC); + PROTECT(t, field); if (UNLIKELY(classInit(t, fieldClass(t, field), 3))) goto invoke; @@ -2401,6 +2405,8 @@ interpret(Thread* t) if (UNLIKELY(exception)) goto throw_; if (throwIfVolatileField(t, field)) goto throw_; + assert(t, (fieldFlags(t, field) & ACC_STATIC) == 0); + switch (fieldCode(t, field)) { case ByteField: case BooleanField: @@ -2467,6 +2473,8 @@ interpret(Thread* t) if (UNLIKELY(exception)) goto throw_; if (throwIfVolatileField(t, field)) goto throw_; + assert(t, fieldFlags(t, field) & ACC_STATIC); + PROTECT(t, field); if (UNLIKELY(classInit(t, fieldClass(t, field), 3))) goto invoke; diff --git a/src/machine.cpp b/src/machine.cpp index dfa94cd66b..cd5c552487 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -835,10 +835,6 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool) staticTypes[staticCount++] = code; } else { - if (value) { - abort(t); // todo: handle non-static field initializers - } - unsigned excess = (memberOffset % fieldSize(t, code)) % BytesPerWord; if (excess) { memberOffset += BytesPerWord - excess; diff --git a/test/Misc.java b/test/Misc.java index be83804e78..80c6bd7535 100644 --- a/test/Misc.java +++ b/test/Misc.java @@ -3,6 +3,8 @@ public class Misc { private static int beta; private static byte byte1, byte2, byte3; + private final int NonStaticConstant = 42; + private int gamma; private int pajama; private boolean boolean1; @@ -338,6 +340,8 @@ public class Misc { { Misc m = new Misc(); m.toString(); + expect(m.NonStaticConstant == 42); + expect(m.time == 0xffffffffffffffffL); long t = m.time; expect(t == 0xffffffffffffffffL);