Question about class loaders and Unsafe.getFieldOffset

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Question about class loaders and Unsafe.getFieldOffset

Chris Hennick
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?

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Question about class loaders and Unsafe.getFieldOffset

Chris Hennick
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?

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Question about class loaders and Unsafe.getFieldOffset

⇜Krishnan Mahadevan⇝

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/

 

From: <[hidden email]> on behalf of Chris Hennick <[hidden email]>
Reply-To: <[hidden email]>
Date: Friday, September 22, 2017 at 4:51 AM
To: testng-users <[hidden email]>
Subject: [testng-users] Re: Question about class loaders and Unsafe.getFieldOffset

 

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?

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.