From d4656e8a52c08c3e32714fcbb3480cec9aa247e8 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Thu, 25 Oct 2007 13:20:39 -0600 Subject: [PATCH] handle ConstantValue attributes for static fields --- src/interpret.cpp | 16 ++++++---------- src/machine.cpp | 35 +++++++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/interpret.cpp b/src/interpret.cpp index 00611c6e52..4aa2b747e5 100644 --- a/src/interpret.cpp +++ b/src/interpret.cpp @@ -2062,12 +2062,10 @@ interpret(Thread* t) object v = arrayBody(t, codePool(t, code), index - 1); - if (objectClass(t, v) == arrayBody(t, t->m->types, Machine::IntType)) { - pushInt(t, intValue(t, v)); - } else if (objectClass(t, v) - == arrayBody(t, t->m->types, Machine::FloatType)) + if (objectClass(t, v) == arrayBody(t, t->m->types, Machine::IntType) + or objectClass(t, v) == arrayBody(t, t->m->types, Machine::FloatType)) { - pushInt(t, floatValue(t, v)); + pushInt(t, intValue(t, v)); } else if (objectClass(t, v) == arrayBody(t, t->m->types, Machine::StringType)) { @@ -2085,12 +2083,10 @@ interpret(Thread* t) object v = arrayBody(t, codePool(t, code), index - 1); - if (objectClass(t, v) == arrayBody(t, t->m->types, Machine::LongType)) { - pushLong(t, longValue(t, v)); - } else if (objectClass(t, v) - == arrayBody(t, t->m->types, Machine::DoubleType)) + if (objectClass(t, v) == arrayBody(t, t->m->types, Machine::LongType) + or objectClass(t, v) == arrayBody(t, t->m->types, Machine::DoubleType)) { - pushLong(t, doubleValue(t, v)); + pushLong(t, longValue(t, v)); } else { abort(t); } diff --git a/src/machine.cpp b/src/machine.cpp index 1ea418623f..e004be98c0 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -518,7 +518,7 @@ parseUtf8(Thread* t, Stream& s, unsigned length) if (a == 0xC0 and b == 0x80) { byteArrayBody(t, value, vi++) = 0; } else { - abort(t); // todo + abort(t); // todo: handle non-ASCII characters } } else { byteArrayBody(t, value, vi++) = a; @@ -555,7 +555,7 @@ parsePool(Thread* t, Stream& s) } break; case CONSTANT_Float: { - object value = makeFloat(t, s.readFloat()); + object value = makeInt(t, s.readFloat()); set(t, pool, ArrayBody + (i * BytesPerWord), value); } break; @@ -566,7 +566,7 @@ parsePool(Thread* t, Stream& s) } break; case CONSTANT_Double: { - object value = makeDouble(t, s.readDouble()); + object value = makeLong(t, s.readDouble()); set(t, pool, ArrayBody + (i * BytesPerWord), value); ++i; } break; @@ -767,15 +767,29 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool) object fieldTable = makeArray(t, count, true); PROTECT(t, fieldTable); + object staticValueTable = makeArray(t, count, true); + PROTECT(t, staticValueTable); + for (unsigned i = 0; i < count; ++i) { unsigned flags = s.read2(); unsigned name = s.read2(); unsigned spec = s.read2(); + object value = 0; + PROTECT(t, value); + unsigned attributeCount = s.read2(); for (unsigned j = 0; j < attributeCount; ++j) { - s.read2(); - s.skip(s.read4()); + object name = arrayBody(t, pool, s.read2() - 1); + unsigned length = s.read4(); + + if (strcmp(reinterpret_cast("ConstantValue"), + &byteArrayBody(t, name, 0)) == 0) + { + value = arrayBody(t, pool, s.read2() - 1); + } else { + s.skip(length); + } } object field = makeField @@ -789,8 +803,14 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool) class_); if (flags & ACC_STATIC) { + set(t, staticValueTable, ArrayBody + (staticOffset * BytesPerWord), + value); fieldOffset(t, field) = staticOffset++; } else { + if (value) { + abort(t); // todo: handle non-static field initializers + } + unsigned excess = memberOffset % fieldSize(t, field); if (excess) { memberOffset += BytesPerWord - excess; @@ -806,7 +826,10 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool) set(t, class_, ClassFieldTable, fieldTable); if (staticOffset) { - object staticTable = makeArray(t, staticOffset, true); + object staticTable = makeArray(t, staticOffset, false); + memcpy(&arrayBody(t, staticTable, 0), + &arrayBody(t, staticValueTable, 0), + staticOffset * BytesPerWord); set(t, class_, ClassStaticTable, staticTable); }