tolerate ConstantValue attributes on non-static fields, since the compiler ensures that they are initialized in any constructors for that class (i.e., the VM does not need to do anything special to initialize them)

This commit is contained in:
Joel Dice 2009-01-10 12:25:52 -07:00
parent e86acf4543
commit 54ad7c4e98
4 changed files with 21 additions and 5 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);