windward-studios / ikvm8

Other
173 stars 36 forks source link

Issues with Unsafe and Netty #4

Closed Draspax closed 5 years ago

Draspax commented 5 years ago

There seems to be issues with using Netty with IKVM. This was already a problem in IKVM 8.1 but as development stopped it was never fixed I guess.

Another guy also hit this problem: https://sourceforge.net/p/ikvm/mailman/message/35520859/

Basically sun.misc.Unsafe returns the wrong value for arrayIndexScale which causes an exception in io.netty.util.internal.shaded.org.jctools.util.UnsafeRefAccess

static {
        int scale = UnsafeAccess.UNSAFE.arrayIndexScale(Object[].class);
        if (4 == scale) {
            REF_ELEMENT_SHIFT = 2;
        } else {
            if (8 != scale) {
                throw new IllegalStateException("Unknown pointer size");
            }

            REF_ELEMENT_SHIFT = 3;
        }

        REF_ARRAY_BASE = (long)UnsafeAccess.UNSAFE.arrayBaseOffset(Object[].class);
    }

In Java the call "UnsafeAccess.UNSAFE.arrayIndexScale(Object[].class);" returns 4 for tests I have done but in .NET returns 1 hence the IllegalStateException.

ghost commented 5 years ago

Hi Draspax;

Please put in a pull request with the proposed changes for this. We're happy to review it and add it.

thanks - dave

Draspax commented 5 years ago

Fix has been merged and released.