UnsafeAtomicityTest crashes on SPARC

Tobias Hartmann tobias.hartmann at oracle.com
Tue Aug 30 06:50:07 UTC 2016


Hi,

this problem showed up in PIT:
https://bugs.openjdk.java.net/browse/JDK-8164968

I assigned it to runtime - feel free to re-assign.

Best regards,
Tobias

On 30.10.2015 12:52, Doerr, Martin wrote:
> Hi Aleksey,
> 
> we have seen JVM crashes when running the following test on SPARC:
> org.openjdk.jcstress.tests.vjug.UnsafeAtomicityTest
> 
> Maybe it is not supposed to run on platforms which don't support unaligned accesses?
> 
> I see 2 problems:
> 
> 1.       The current implementation uses the version of UnsafeHolder.U.putInt(null, offset, 0xFFFFFFFF) (and getInt) which is designed to access object fields. Seems like the JVM is allowed to crash with SIGBUS if it is misused for unaligned accesses. The JVM is designed to catch SIGBUS only in the other version which only takes the address UnsafeHolder.U.putInt(offset, 0xFFFFFFFF).
> 
> 2.       The signal handler in os_solaris_sparc needs a fix to catch BUS_ADRALN as well. The part "&& info->si_code == BUS_OBJERR"  of the condition "if (sig == SIGBUS && info->si_code == BUS_OBJERR && thread->doing_unsafe_access())" should get removed as it was done on other platforms.
> 
> With the problems fixed, it may be possible to catch the asynchronous exception which may get generated by the Unsafe access. The following stand-alone test program below can do it.
> 
> Hope this is interesting for you.
> Best regards,
>   Martin
> 
> 
> 
> import sun.misc.Unsafe;
> import sun.reflect.ReflectionFactory;
> import java.lang.reflect.Constructor;
> import java.lang.reflect.Field;
> import java.lang.reflect.Modifier;
> 
> public class TestUnsafe{
> 
>     public static Unsafe getUnsafe() throws Exception {
>         Constructor<Unsafe> unsafeConstructor = Unsafe.class.getDeclaredConstructor();
>         unsafeConstructor.setAccessible(true);
>         return unsafeConstructor.newInstance();
>     }
> 
>     private void test_unsafe(Unsafe u) {
>         long addr_raw = u.allocateMemory(1024);
>         long addr_misaligned = ((addr_raw + 512) & ~255) - 2;
>         //u.putInt(null, addr_misaligned, 0xFFFFFFFF); // crashes on some platforms with SIGBUS ADRALN
>         u.putInt(addr_misaligned, 0xFFFFFFFF); // should work on all platforms (catch SIGBUS if needed)
>     }
> 
>     public static void main(String args[]){
>         TestUnsafe xyz = new TestUnsafe();
>         Unsafe u;
>         try {
>           u = getUnsafe();
>         } catch (Exception e) {
>           e.printStackTrace();
>           return;
>         }
>         try {
>           xyz.test_unsafe(u);
>           System.gc();
>         } catch (Error e) {
>           e.printStackTrace(); // did we catch an async exception reported by Unsafe?
>         }
>     }
> 
> }
> 


More information about the hotspot-runtime-dev mailing list