Skip to content

Conversation

@nik9000
Copy link
Member

@nik9000 nik9000 commented Apr 12, 2017

The JVM caches Integer objects. This is known. A test in Painless
was 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:+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

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
@nik9000
Copy link
Member Author

nik9000 commented Apr 12, 2017

Thanks to user2237683 over at http://stackoverflow.com/questions/15052216/how-large-is-the-integer-cache/15773195#15773195 for digging into -XX:+AggressiveOpts. I had figured out that the size of the cache was the trouble but didn't have a smoking gun linking it to the build failures. Mentioning -XX:+AggressiveOpts clued me in.

@nik9000 nik9000 requested a review from jdconrad April 12, 2017 21:53
@nik9000 nik9000 added review v5.4.0 v6.0.0-alpha1 >test Issues or PRs that are addressing/adding tests labels Apr 12, 2017
@nik9000
Copy link
Member Author

nik9000 commented Apr 12, 2017

I believe this also needs to go to the 5.3 branch but I'm not sure about timing.

Copy link
Contributor

@jdconrad jdconrad left a 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!

Copy link
Member

@jasontedor jasontedor left a 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.

@nik9000 nik9000 merged commit 25119a7 into elastic:master Apr 17, 2017
@nik9000
Copy link
Member Author

nik9000 commented Apr 17, 2017

Thanks for reviewing @jdconrad and @jasontedor!

nik9000 added a commit that referenced this pull request Apr 17, 2017
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
nik9000 added a commit to nik9000/elasticsearch that referenced this pull request Apr 18, 2017
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.
nik9000 added a commit that referenced this pull request Apr 21, 2017
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
@nik9000 nik9000 deleted the fix_aggressive_opts branch June 7, 2017 14:52
nik9000 added a commit that referenced this pull request Oct 10, 2017
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.
nik9000 added a commit that referenced this pull request Oct 10, 2017
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.
@clintongormley clintongormley added :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache and removed :Plugin Lang Painless labels Feb 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >test Issues or PRs that are addressing/adding tests v5.4.0 v6.0.0-alpha1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants