Fox2Code / FabricZero

Compatibility enhancement mod (Abandoned)
MIT License
17 stars 5 forks source link

Why not using UnsafeAccessor Library to get sun.misc.Unsafe instance with better compatibility and convenience. #11

Closed lvyitian closed 3 years ago

lvyitian commented 3 years ago

Library: https://bintray.com/karlatemp/unsafe-accessor/unsafe-accessor/ Github(outdated): https://github.com/Karlatemp/UnsafeAccessor How does it work: https://karlatemp.github.io/blog-me/reflect/0.index.html It uses a much more ingenious method to get Unsafe instance without trigger “WARNING: An illegal reflective access operation has occurred”. I think it can fix the compatibility issue with java 9+ perfectly. Just add jcenter to maven repo list and add content below to build.gradle: implementation 'io.github.karlatemp:unsafe-accessor:1.2.0' Use io.github.karlatemp.unsafeaccessor.Root.getUnsafe() to get wrapped Unsafe and then call wrappedUnsafe.getUnsafe() to get sun.misc.Unsafe. It also provides some useful methods like void io.github.karlatemp.unsafeaccessor.Root.setAccessible(AccessibleObject object, boolean isAccessible) and MethodHandles.Lookup io.github.karlatemp.unsafeaccessor.Root.getTrusted().

Fox2Code commented 3 years ago

Thanks for that, I will use it in the project to help increase VM compatibility. Because I don't have the time to work on this mod, I used it as a fallback in the already existing system.