-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
JDK-8273914: Indy string concat changes order of operations #5844
Conversation
👋 Welcome back cushon! A progress list of the required criteria for merging this PR into |
Webrevs
|
* Returns true if the argument should be converted to a string eagerly, to preserve | ||
* possible side-effects. | ||
*/ | ||
protected boolean shouldConvertToStringEagerly(Type argType) { |
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.
For me the implementation should be neither a primitive type nor a final class of java.lang. I think that at least the wrappers should not be converted eagerly
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.
@forax can you expand on the suggestion here?
The current implementation is not eagerly converting boxes for primitives types, which wrappers should not be converted eagerly?
Also note that one of the motivating examples was StringBuilder
, which is a final
class in java.lang
. It's not just about toString()
not having side-effects, it's also about insulting the operands from each others's side effects (e.g. myStringBuilder.append("foo") + myStringBuilder.append("bar")
)
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.
The current implementation is not eagerly converting boxes for primitives types, which wrappers should not be converted eagerly?
I was just thinking that not calling Boolean or Double.toString() explicitly was Ok
myStringBuilder.append("foo") + myStringBuilder.append("bar")
Aaaah, so only primitives + their boxes should not be evaluated eagerly.
/csr needed |
Please file a CSR for this issues to discuss the behavioral changes, even if to fix a bug. |
@jddarcy has indicated that a compatibility and specification (CSR) request is needed for this pull request. |
@jddarcy thanks, I have opened a CSR: https://bugs.openjdk.java.net/browse/JDK-8274863 |
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.
Can you explain the changes made in relation to the runtime test:
test/hotspot/jtreg/runtime/modules/AccessCheck/MethodAccessReadTwice.java
please. The connection to this fix is not at all apparent, nor what the conversion to jasm is achieving.
Thanks,
David
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.
Thank you for fixing this. It looks nominally fine, but I would defer to javac experts to approve this. Minor testing suggestions below.
* @test | ||
* @bug 8273914 | ||
* @summary Indy string concat changes order of operations | ||
* |
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.
Here and later: please add the test block with -XDstringConcat=inline
here as well, so that test would verify that every javac strategy produces the same result?
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.
Done, thanks
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.
(The WellKnownTypes
test still only exercises the indy strategies, because it's testing logic that only exists in those strategies.)
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.
But still, we probably want to confirm that inline
strategy yields the same answer in WellKnownTypes
? That's my thinking why to test inline
: that is a baseline.
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.
I agree in general about using inline
as a baseline, but WellKnownTypes
doesn't currently check the output of string concatenation, it checks the signature of the invokedynamic
it find in the test case.
What do you have in mind for inline
here? Should I update the test to assert on the output of string concatenation (and tolerate not being able to find an invokedynamic
, which could make the coverage for the indy strategies more fragile)? Or add a different test with similar inputs, and check the output of string concatenation on primitives and boxes?
I think it might make sense to rely on other tests to ensure inline
and the indy
strategies produce the same results, and use WellKnownTypes
as a test just for shouldConvertToStringEagerly
, which is only used by the indy
strategies.
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.
Ah, I missed that WellKnownTypes
does not verify concat output. Yes, that resolves my concern, we don't need to handle inline
there. Maybe rename WellKnownTypes
to WellKnownTypeSignatures
or something?
But yes, I think adding another test that verifies the "special" input types produce consistent results across all strategies would be useful.
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.
Sure, thanks--I renamed WellKnownTypes
to WellKnownTypeSignatures
, and added a new WellKnownTypes
that tests the actual concat behaviour on primitives for all of the strategies.
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.
Thank you, the last change resolves my comments.
Thanks, good question: That test is for JDK-8174954, which checks for an expected Using |
Mailing list message from David Holmes on hotspot-runtime-dev: On 8/10/2021 6:02 am, Liam Miller-Cushon wrote:
Okay, can you please add a comment to the jasm file that explains that. Thanks, |
Done |
@lahodaj, want to review the compiler change? |
How about code like:
Should that be covered as well? From looking at the patch (not really trying it), it does not seem to be covered? |
Tried it, still not correct:
I believe
This produces the correct result:
@cushon, could you do this change and add a relevant test case? |
Fixed, thanks! |
and add more functional test coverage for string concat of well-known types, covering all strategies.
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.
Current change passes tier{1,2,3,4}
for me. Still, I think compiler folks have to approve the javac change. @lahodaj, could you do it, or ask somebody else?
@shipilev this is also blocked on the CSR, I think the next step is for it to be 'reviewed by at least one engineer familiar with that technology area', is that something you'd be able to help with? https://bugs.openjdk.java.net/browse/JDK-8274863 |
@cushon This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
|
The CSR has been approved for 19, this is ready for review pending integration after the JDK 18 branch is cut. |
@cushon This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
@lahodaj would you be willing to review for the compiler group? |
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.
the compiler changes look good to me
@cushon This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 1099 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
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.
Looks reasonable.
/integrate |
Going to push as commit cfee451.
Your commit was automatically rebased without conflicts. |
This change makes string concatenation call
toString
on the arguments eagerly, to preserve the correct evaluation order of the arguments and the calls totoString
.Progress
Issues
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/5844/head:pull/5844
$ git checkout pull/5844
Update a local copy of the PR:
$ git checkout pull/5844
$ git pull https://git.openjdk.java.net/jdk pull/5844/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 5844
View PR using the GUI difftool:
$ git pr show -t 5844
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/5844.diff