windward-studios / ikvm8

Other
173 stars 36 forks source link

Fix arrayIndexScale #5

Closed Draspax closed 5 years ago

Draspax commented 5 years ago

When an object array is passed to arrayIndexScale it should return 4.

Draspax commented 5 years ago

Fix for issue described in https://github.com/wwrd/ikvm8/issues/4

igorkwwrd commented 5 years ago

4 is better than 1, definitely, and the submission is worth accepting.

I still concerned as this is about a reference size which may be 4 bytes but may be 8. It depends on what platform/architecture source code compiles and runs.

So, someone some day may hit an issue with a memory corruption because their references will be 8 bytes long.

Unsafe.arrayIndexScale(Object[].class) == 4 in java even in 64 bit because HotSpot is using compressed ordinary object pointers The VM option -XX:+UseCompressedOops is used by default. But if you run arrayIndexScale with -XX:-UseCompressedOops (turned off), it returns 8.

I have no idea of how to get the correct number from Unsafe. I even think it is not possible to do in Java. I don't also know how it really matters for IKVM usage.

markusschaber commented 5 years ago

I am not sure whether IKVM even supports CompressedOops, as it maps Java objects to .NET objects under the hood.

My guess is that IntPtr.Size from .NET API would be the correct size.