Array accesses using sun.misc.Unsafe cause data corruption or SIGSEGV (original) (raw)

Mehmet Dogan mehmet at hazelcast.com
Tue Jun 9 11:03:54 UTC 2015


Btw, (thanks to one my colleagues), when address calculation in the loop is converted to

long address = baseAddress + (i * 8)

test passes. Only difference is next long pointer is calculated using integer 8 instead of long 8.

for (int i = 0; i < count; i++) {
    long address = baseAddress + (i * 8); // <--- here, integer 8 instead
of long 8

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

    long actual = unsafe.getLong(address);

    if (expected != actual) {
        throw new AssertionError("Expected: " + expected + ", Actual: " +
actual);
    }
}

On Tue, Jun 9, 2015 at 1:07 PM Mehmet Dogan <mehmet at hazelcast.com> wrote:

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.060-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.060-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.060-ea-b18' or '1.9.0-ea-b67'. Because both are failing. > I'm looking forward to hearing from you. > Thanks, -Mehmet Dogan- -- > @mmdogan

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



More information about the hotspot-compiler-dev mailing list