TimeAndSpaceIO / SmoothieMap

A gulp of low latency Java
295 stars 30 forks source link

Calling clear() throws IllegalArgumentException #6

Closed rishabh9 closed 4 years ago

rishabh9 commented 5 years ago

On calling clear() the below exception is thrown:

Exception in thread "main" java.lang.IllegalArgumentException
    at java.base/jdk.internal.misc.Unsafe.invalidInput(Unsafe.java:437)
    at java.base/jdk.internal.misc.Unsafe.checkPrimitiveArray(Unsafe.java:557)
    at java.base/jdk.internal.misc.Unsafe.checkPrimitivePointer(Unsafe.java:576)
    at java.base/jdk.internal.misc.Unsafe.setMemoryChecks(Unsafe.java:747)
    at java.base/jdk.internal.misc.Unsafe.setMemory(Unsafe.java:718)
    at jdk.unsupported/sun.misc.Unsafe.setMemory(Unsafe.java:527)
    at net.openhft.smoothie.Segment.clear(Segment.java:507)
    at net.openhft.smoothie.SmoothieMap.clear(SmoothieMap.java:1244)
    at Main.main(Main.java:11)

The below code can easily reproduce the issue. I am using OpenJDK 9.0.4.

import net.openhft.smoothie.SmoothieMap;

import java.util.Map;
import java.util.Optional;

public class Main {

    public static void main(String[] args) {
        Map<String, Optional<String>> map = new SmoothieMap<>(10);
        map.put("Hello", Optional.of("World!"));
        map.clear();
    }
}

Could someone please take a look into this?

leventov commented 5 years ago

Thanks for this report, interesting. Actually I'm in the process of rewriting SmoothieMap at the moment so I won't release any fix quickly, but if you want to to continue experimenting with SmoothieMap, you could replace that setMemory() call in Segment.java:507 with a loop:

for (long offset = HASH_TABLE_OFFSET; offset < HASH_TABLE_OFFSET + HASH_TABLE_SIZE * HASH_TABLE_SLOT_SIZE; offset += Long.BYTES) {
    U.putLong(this, offset, 0L);
}
rishabh9 commented 5 years ago

Thank you for the information. I'll give that a try. Shall we leave the ticket open? This information will help others.

On Fri 30 Nov, 2018, 00:47 Roman Leventov <notifications@github.com wrote:

Thanks for this report, interesting. Actually I'm in the process of rewriting SmoothieMap at the moment so I won't release any fix quickly, but if you want to to continue experimenting with SmoothieMap, you could replace that setMemory() call in Segment.java:507 with a loop:

for (long offset = HASH_TABLE_OFFSET; offset < HASH_TABLE_SIZE * HASH_TABLE_SLOT_SIZE; offset += Long.BYTES) { U.putLong(this, offset, 0L); }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/TimeAndSpaceIO/SmoothieMap/issues/6#issuecomment-442957521, or mute the thread https://github.com/notifications/unsubscribe-auth/AALX-bU_xbu-aF1Btk84j1p1hj8ApAJsks5u0DLbgaJpZM4Y3UZR .

leventov commented 4 years ago

This should now be fixed in SmoothieMap 2.0.1