-
Enhancement
-
Resolution: Unresolved
-
P4
-
25
For a sequence of writes to the same field o.f without interleaved safepoint polls:
(pre-barrier)
o.f = o_1
(post-barrier)
(pre-barrier)
o.f = o_2
(post-barrier)
...
(pre-barrier)
o.f = o _(n-1)
(post-barrier)
(pre-barrier)
o.f = o_n
(post-barrier)
it is safe to elide inner pre- and post-barriers as follows:
(pre-barrier)
o.f = o_1
o.f = o_2
...
o.f = o _(n-1)
o.f = o_n
(post-barrier)
In the words of [~tschatzl] (who suggested this optimization in an offline conversation):
"1. For a sequence of stores to the same location, the optimization must keep the pre-barrier of the first store. Otherwise the snapshot graph will be destroyed.
2. For a sequence of stores to the same location, the optimization must keep the post-barrier of the last store. Otherwise any filters will not be applied to the reference that will "stay" during garbage collection (If there were no filters, it would not matter who wrote the card table value)."
This optimization can also be applied to patterns with conditional writes, e.g.:
(pre-barrier)
o.f = o1
(post-barrier) (1)
if (condition) {
(pre-barrier) (2)
o.f = o2
(post-barrier)
}
Eliding barriers in this case requires dominance and post-dominance analysis, to recognize that it is valid to elide (2) but not (1) (or else we might risk not running any post-barrier if condition does not hold). The current late barrier elision logic perform domination-based analysis, and should be extended to also perform post-domination based analysis.
Care needs to be taken to ensure that the first pre-barrier and last post-barrier are not elided by other reasons, e.g. if the written value is null.
(pre-barrier)
o.f = o_1
(post-barrier)
(pre-barrier)
o.f = o_2
(post-barrier)
...
(pre-barrier)
o.f = o _(n-1)
(post-barrier)
(pre-barrier)
o.f = o_n
(post-barrier)
it is safe to elide inner pre- and post-barriers as follows:
(pre-barrier)
o.f = o_1
o.f = o_2
...
o.f = o _(n-1)
o.f = o_n
(post-barrier)
In the words of [~tschatzl] (who suggested this optimization in an offline conversation):
"1. For a sequence of stores to the same location, the optimization must keep the pre-barrier of the first store. Otherwise the snapshot graph will be destroyed.
2. For a sequence of stores to the same location, the optimization must keep the post-barrier of the last store. Otherwise any filters will not be applied to the reference that will "stay" during garbage collection (If there were no filters, it would not matter who wrote the card table value)."
This optimization can also be applied to patterns with conditional writes, e.g.:
(pre-barrier)
o.f = o1
(post-barrier) (1)
if (condition) {
(pre-barrier) (2)
o.f = o2
(post-barrier)
}
Eliding barriers in this case requires dominance and post-dominance analysis, to recognize that it is valid to elide (2) but not (1) (or else we might risk not running any post-barrier if condition does not hold). The current late barrier elision logic perform domination-based analysis, and should be extended to also perform post-domination based analysis.
Care needs to be taken to ensure that the first pre-barrier and last post-barrier are not elided by other reasons, e.g. if the written value is null.