UnsafeAtomicityTest crashes on SPARC

Tobias Hartmann tobias.hartmann at oracle.com
Tue Aug 30 09:32:40 UTC 2016


Hi Martin,

On 30.08.2016 11:10, Doerr, Martin wrote:
> Hi Tobias,
> 
> correct, the test will either need to get changed or disabled on SPARC. It was originally written for x86 and the code was illegal for platforms which can't access unaligned memory (as explained in my original email below under 1.).
> In the meantime, the unsafe implementation has changed and I think that the "GuardUnsafeAccess" in "put(T x)" should help. So yes, if the test is supposed to run on SPARC, the remaining part to fix is to catch the java.lang.InternalError.
> 
> I think the signal handler part is a real bug which should get fixed.

Okay, thanks for the clarification! I filed a bug to keep track of this:
https://bugs.openjdk.java.net/browse/JDK-8165014

Best regards,
Tobias

> 
> Best regards,
> Martin
> 
> 
> -----Original Message-----
> From: Tobias Hartmann [mailto:tobias.hartmann at oracle.com] 
> Sent: Dienstag, 30. August 2016 10:52
> 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 Martin,
> 
> On 30.08.2016 10:15, 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.
> 
> That seems reasonable to me but the test would still need to catch the java.lang.InternalError, right?
> 
> I leave this to the runtime team to decide.
> 
> Thanks,
> Tobias
> 
>> 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