Array accesses using sun.misc.Unsafe cause data corruption or SIGSEGV

Mehmet Dogan mehmet at hazelcast.com
Tue Jun 9 10:07:22 UTC 2015


Hi all,

While I was testing my app using java 8, I encountered the previously
reported sun.misc.Unsafe issue.

https://bugs.openjdk.java.net/browse/JDK-8076445
http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/2015-April/017685.html

Issue status says it's resolved with resolution "Cannot Reproduce".  But
unfortunately it's still reproducible using "1.8.0_60-ea-b18" and
"1.9.0-ea-b67".

Test is very simple:

```
public static void main(String[] args) throws Exception {
        Unsafe unsafe = findUnsafe();
        // 10000 pass
        // 100000 jvm crash
        // 1000000 fail
        int count = 100000;
        long size = count * 8L;
        long baseAddress = unsafe.allocateMemory(size);

        try {
            for (int i = 0; i < count; i++) {
                long address = baseAddress + (i * 8L);

                long expected = i;
                unsafe.putLong(address, expected);

                long actual = unsafe.getLong(address);

                if (expected != actual) {
                    throw new AssertionError("Expected: " + expected + ",
Actual: " + actual);
                }
            }
        } finally {
            unsafe.freeMemory(baseAddress);
        }
    }
```
It's not failing up to version 1.8.0.31, by starting 1.8.0.40 test is
failing constantly.

- With iteration count 10000, test is passing.
- With iteration count 100000, jvm is crashing with SIGSEGV.
- With iteration count 1000000, test is failing with AssertionError.

When one of compilation (-Xint) or inlining (-XX:-Inline) or
on-stack-replacement (-XX:-UseOnStackReplacement) is disabled, test is not
failing at all.

I tested on platforms:
- Centos-7/openjdk-1.8.0.45
- OSX/oraclejdk-1.8.0.40
- OSX/oraclejdk-1.8.0.45
- OSX/oraclejdk-1.8.0_60-ea-b18
- OSX/oraclejdk-1.9.0-ea-b67

Previous issue comment (
https://bugs.openjdk.java.net/browse/JDK-8076445?focusedCommentId=13633043#comment-13633043)
says "Cannot reproduce based on the latest version". I hope that latest
version is not mentioning to '1.8.0_60-ea-b18' or '1.9.0-ea-b67'. Because
both are failing.

I'm looking forward to hearing from you.

Thanks,
-Mehmet Dogan-
-- 

@mmdogan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20150609/7ce4e16e/attachment.html>


More information about the hotspot-compiler-dev mailing list