From c918cbced149a34a1d0ab78922ac21c0d04f80b8 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 11 Sep 2012 19:21:51 -0600 Subject: [PATCH] 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. --- src/classpath-openjdk.cpp | 25 +++++++++++++++++++++---- src/machine.cpp | 7 +++++-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/classpath-openjdk.cpp b/src/classpath-openjdk.cpp index 003b2ef1e2..da31d9b687 100644 --- a/src/classpath-openjdk.cpp +++ b/src/classpath-openjdk.cpp @@ -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); + } } } diff --git a/src/machine.cpp b/src/machine.cpp index 790c9fa1aa..6ae39f7b30 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -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 (&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;