-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Harden painless test against "fun" caching #24077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The JVM caches `Integer` objects. This is known. A test in Painless was relying on the JVM not caching the particular integer `1000`. It turns out that when you provide `-XX:+AggressiveOpts` the JVM *does* cache `1000`, causing the test to fail when that is specified. This replaces `1000` with a randomly selected integer that we test to make sure *isn't* cached by the JVM. *Hopefully* this test is good enough. It relies on the caching not changing in between when we check that the value isn't cached and when we run the painless code. The cache now is a simple array but there is nothing preventing it from changing. If it does change in a way that thwarts this test then the test fail fail again. At least when that happens the next person can see the comment about how it is important that the integer isn't cached and can follow that line of inquiry. Closes elastic#24041
|
Thanks to user2237683 over at http://stackoverflow.com/questions/15052216/how-large-is-the-integer-cache/15773195#15773195 for digging into |
|
I believe this also needs to go to the 5.3 branch but I'm not sure about timing. |
jdconrad
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for hunting this down!
jasontedor
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, great find @nik9000. LGTM.
|
Thanks for reviewing @jdconrad and @jasontedor! |
The JVM caches `Integer` objects. This is known. A test in Painless was relying on the JVM not caching the particular integer `1000`. It turns out that when you provide `-XX:+AggressiveOpts` the JVM *does* cache `1000`, causing the test to fail when that is specified. This replaces `1000` with a randomly selected integer that we test to make sure *isn't* cached by the JVM. *Hopefully* this test is good enough. It relies on the caching not changing in between when we check that the value isn't cached and when we run the painless code. The cache now is a simple array but there is nothing preventing it from changing. If it does change in a way that thwarts this test then the test fail fail again. At least when that happens the next person can see the comment about how it is important that the integer isn't cached and can follow that line of inquiry. Closes #24041
We had a TODO about adding tests around cached boxing. In elastic#24077 I tracked down the uncached boxing tests and saw the TODO. Cached boxing testing is a fairly small extension to that work.
The JVM caches `Integer` objects. This is known. A test in Painless was relying on the JVM not caching the particular integer `1000`. It turns out that when you provide `-XX:+AggressiveOpts` the JVM *does* cache `1000`, causing the test to fail when that is specified. This replaces `1000` with a randomly selected integer that we test to make sure *isn't* cached by the JVM. *Hopefully* this test is good enough. It relies on the caching not changing in between when we check that the value isn't cached and when we run the painless code. The cache now is a simple array but there is nothing preventing it from changing. If it does change in a way that thwarts this test then the test fail fail again. At least when that happens the next person can see the comment about how it is important that the integer isn't cached and can follow that line of inquiry. Closes #24041
We had a TODO about adding tests around cached boxing. In #24077 I tracked down the uncached boxing tests and saw the TODO. Cached boxing testing is a fairly small extension to that work.
We had a TODO about adding tests around cached boxing. In #24077 I tracked down the uncached boxing tests and saw the TODO. Cached boxing testing is a fairly small extension to that work.
The JVM caches
Integerobjects. This is known. A test in Painlesswas relying on the JVM not caching the particular integer
1000.In older versions of java only -127, 128 were cached. That isn't
always true anymore. It turns out that when you provide
-XX:+AggressiveOptsthe JVM does cache1000, causing thetest to fail when that is specified.
This replaces
1000with a randomly selected integer that we testto make sure isn't cached by the JVM. Hopefully this test is
good enough. It relies on the caching not changing in between when
we check that the value isn't cached and when we run the painless
code. The cache now is a simple array but there is nothing
preventing it from changing. If it does change in a way that thwarts
this test then the test fail fail again. At least when that happens
the next person can see the comment about how it is important
that the integer isn't cached and can follow that line of inquiry.
Closes #24041