Question about class loaders and Unsafe.getFieldOffset

8 views
Skip to first unread message

Chris Hennick

unread,
Sep 21, 2017, 6:42:48 PM9/21/17
to testng-users
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?

Chris Hennick

unread,
Sep 21, 2017, 7:21:35 PM9/21/17
to testng-users
Update: I've added an assert to check this, and the class is indeed the same one. But might TestNG be somehow interfering in a more complicated way with Unsafe and reflective field access?

Krishnan Mahadevan

unread,
Sep 21, 2017, 10:46:15 PM9/21/17
to testng...@googlegroups.com

Chris,

 

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

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages