fix sun.misc.Unsafe.getLongVolatile for static fields on 32-bit platforms

The existing code did not handle static field lookups for
synchronization on 32-bit systems, which is necessary because such
systems generally don't support atomic operations on 64-bit values.
This commit is contained in:
Joel Dice 2012-09-11 19:21:51 -06:00
parent 90fa4c9b69
commit c918cbced1
2 changed files with 26 additions and 6 deletions

View File

@ -2292,11 +2292,28 @@ fieldForOffsetInClass(Thread* t, object c, unsigned offset)
object
fieldForOffset(Thread* t, object o, unsigned offset)
{
object field = fieldForOffsetInClass(t, objectClass(t, o), offset);
if (field) {
return field;
} else {
object c = objectClass(t, o);
if (classVmFlags(t, c) & SingletonFlag) {
c = singletonObject(t, o, 0);
object table = classFieldTable(t, c);
if (table) {
for (unsigned i = 0; i < objectArrayLength(t, table); ++i) {
object field = objectArrayBody(t, table, i);
if ((fieldFlags(t, field) & ACC_STATIC)
and fieldOffset(t, field) == offset)
{
return field;
}
}
}
abort(t);
} else {
object field = fieldForOffsetInClass(t, c, offset);
if (field) {
return field;
} else {
abort(t);
}
}
}

View File

@ -1128,7 +1128,7 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool)
unsigned count = s.read2();
if (count) {
unsigned staticOffset = BytesPerWord * 2;
unsigned staticOffset = BytesPerWord * 3;
unsigned staticCount = 0;
object fieldTable = makeArray(t, count);
@ -1242,7 +1242,10 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool)
uint8_t* body = reinterpret_cast<uint8_t*>
(&singletonBody(t, staticTable, 0));
for (unsigned i = 0, offset = 0; i < staticCount; ++i) {
memcpy(body, &class_, BytesPerWord);
singletonMarkObject(t, staticTable, 0);
for (unsigned i = 0, offset = BytesPerWord; i < staticCount; ++i) {
unsigned size = fieldSize(t, RUNTIME_ARRAY_BODY(staticTypes)[i]);
while (offset % size) {
++ offset;