Repository navigation
Consider guards or instanceof in field privatizer - #6187
Conversation
|
jenkins build all |
|
Jenkins build riscv |
|
At a high level I think that this fix is too narrow to fully address the root problem Consider a loop that accesses the instance field As a simple example, we could start with an eliminate the cast because and finally hoist If we think that only guards and And this example isn't to say that we should look for conditionals based on an So I think that to be robust/future proof (without disabling the optimization), we have to do one or more of the following:
|
|
@jdmpapin : are you ok with delivering this PR as a tactical fix and the remaining issues you uncovered worked on afterward (assuming an issue is opened to track that work)? I believe some of these problems have existed for many years. |
|
I am reassigning this to @0xdaryl since I will be away for a few days next week. |
Yes, that's alright (with the further check for null tests, since I believe that @hzongaro has written that already) |
Yes - sorry about the delay. I'll just clean up the commit comments and update the pull request shortly. |
|
Moving this back to draft temporarily while I rerun testing with the latest changes. |
|
Devin @jdmpapin, thanks again for your thoughtful review. Commit 9464bb0 papers over the concern you had about As you suggested, these changes try to avoid the problematic situations. A robust, complete fix that accurately detects the problematic situations and that either avoids privatizing or uses conditional tests for the copy of the privatized field into and out of a temporary is required. This follow on work will be tracked in issue #6199. |
jdmpapin
left a comment
There was a problem hiding this comment.
LGTM - just a couple of minor notes on comments in the code
|
Jenkins build all |
|
Jenkins build riscv |
A reference or store to a field that came from an inlined method might be guarded by a virtual guard. In any particular execution of the loop, such a field might not actually exist in the object that's being referenced. To avoid that situation, this change adds a simple check for the existence of a virtual guard within the loop and considers it to be an escape point in the containsEscapePoints method. Similarly, instanceof tests might guard casts that will be used to access fields that wouldn't necessarily exist every time a loop is executed, so they are considered escape points as well. Signed-off-by: Henry Zongaro <zongaro@ca.ibm.com>
instanceof operations can be hoisted out of loops by PRE. This could expose a bug in Field Privatizer in which a field access that is guarded might be privatized, resulting in the field being referenced and stored to unconditionally. A temporary patch in Field Privatizer checks for uses of instanceof and null comparisons inside of loops to guard against the conditions that expose the bug. This change removes the SupportedForPRE property from the instanceof operator to prevent its being hoisted out a loop, avoiding one more situation that could expose the bug. Once the bug is fixed properly in Field Privatizer, the SupportedForPRE property will be added back to instanceof. Signed-off-by: Henry Zongaro <zongaro@ca.ibm.com>
A comparison with a null reference might be used to guard a field access. The Field Privatizer does not take such conditional access into account in deciding whether to privatize a field, which can result in its unconditionally copying a field's value into a temporary variable by dereferencing null. This change adds a very simple check for comparisons with null inside of a loop to help to guard against that situation. That will avoid the bug in most cases, but follow up changes that are more robust, general and accurate in avoiding the problem are planned. Signed-off-by: Henry Zongaro <zongaro@ca.ibm.com>
f8abb9f to
f9c32ab
Compare
Thanks, Daryl @0xdaryl. I squashed the commits related to whitespace changes and corrections to comments. Otherwise, the latest version is the same as the version that was reviewed. |
A reference or store to a field that came from an inlined method might be guarded by a virtual guard. In any particular execution of the loop, such a field might not actually exist in the object that's being referenced. To avoid that situation, this change adds a simple check for the existence of a virtual guard within the loop and considers it to be an escape point in the
containsEscapePointsmethod.Similarly,
instanceoftests might guard casts that will be used to access fields that wouldn't necessarily exist every time a loop is executed, so they are considered escape points as well.This pull request fixes OpenJ9 issue #13524