Question about class loaders and Unsafe.getFieldOffset
I have a class that makes use of Unsafe.getFieldOffset and Unsafe.putLongVolatile to change the seeds of existing SplittableRandom instances wherever they're available, because replacing them every time I needed to change the seed was hurting performance badly. But I'm getting a weird test failure (https://github.com/Pr0methean/BetterRandom/blob/8e22c74a1e30a1b9c06df1d1e2536ca64d894089/betterrandom/src/test/java/io/github/pr0methean/betterrandom/prng/adapter/SplittableRandomReseederTest.java#L28) where the first 4 to 7 bytes of the retrieved seed will be FF's, and the rest will be as expected.
Is it possible that TestNG might be using a custom ClassLoader when I instantiate the SplittableRandom inside a test, that might be altering its field offsets compared to what SplittableRandomReseeder.<clinit> sees? If so, how do I turn this off?
Re: Question about class loaders and Unsafe.getFieldOffset
What happens when you invoke your method as if it were a regular method from a main() method ? Do you see the same sort of failures ? When you invoke SplittableRandomReseederTest.testGetSeed() via a main method, you are creating the instances. This could help us narrow down if the problem is with Reflection in general interfering or if it perhaps has got something to do with your code.
To the best of my knowledge, TestNG relies on reflection to instantiate your test class and invoke its methods, but does so only via the public APIs that Java provides. It doesn’t use anything else.
Thanks & Regards
"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/