UnsafeAtomicityTest crashes on SPARC

David Holmes david.holmes at oracle.com
Tue Aug 30 10:38:18 UTC 2016


<fixed Aleksey's email as he is no longer with Oracle >

On 30/08/2016 6:15 PM, Doerr, Martin wrote:
> Hi Tobias,
>
> I think the problem is that JVM_handle_solaris_signal only catches SIGBUS with si_code BUS_OBJERR:
> if (sig == SIGBUS && info->si_code == BUS_OBJERR && thread->doing_unsafe_access())
>
> We have removed "&& info->si_code == BUS_OBJERR" in our JVM. It should also catch other types like BUS_ADRALN.

I'm not yet convinced that we should be anticipating/supporting 
unaligned access from Unsafe. But I'll look into this more closely later 
this week.

Thanks,
David

> Best regards,
> Martin
>
>
> -----Original Message-----
> From: Tobias Hartmann [mailto:tobias.hartmann at oracle.com]
> Sent: Dienstag, 30. August 2016 08:50
> To: Doerr, Martin <martin.doerr at sap.com>; Aleksey Shipilev (aleksey.shipilev at oracle.com) <aleksey.shipilev at oracle.com>
> Cc: hotspot-runtime-dev at openjdk.java.net
> Subject: Re: UnsafeAtomicityTest crashes on SPARC
>
> 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