RFC: Late G1 Barrier Expansion (Draft JEP)
Roland Westrelin
rwestrel at redhat.com
Tue Feb 6 15:12:52 UTC 2024
> I have written (together with Erik Österlund) a draft JEP for simplifying C2's handling of G1 barriers. The JEP description is available in JBS:
>
> https://bugs.openjdk.org/browse/JDK-8322295
How does this interact with register allocation? Can the call somehow
only save what's live at the call or do they assume the worst case and
save everything? What about allocation of temp registers to use in the
barrier code?
What about having slow path code out of line given the control flow is
not exposed to c2?
FWIW, shendandoah read barriers use a form of macro expansion. One issue
with macro nodes is that they need to carry all the state that's needed
for the expansion (raw memory in particular) and that gets in the way of
optimizations applied to the macro node. In Shenandoah, that state is
not attached to the macro node. Instead, barrier nodes are expanded in a
specific loop opts pass that materializes raw memory state around the
barrier subgraph. After expansion, Shenandoah also has a pass of loop
opts after expansion. In pseudo code, the shenandoah barrier is:
if (heap_stable) {
// do nothing
} else {
// more control flow slow call etc.
}
If there are 2 back to back barriers, then the heap_stable checks can be
merged:
if (heap_stable) {
// do nothing
} else {
// more control flow slow call etc. (1)
}
if (heap_stable) {
// do nothing
} else {
// more control flow slow call etc. (2)
}
becomes:
if (heap_stable) {
// do nothing
} else {
// more control flow slow call etc. (1)
// more control flow slow call etc. (2)
}
And heap_stable is in a loop without safepoints, then unswitching
happens on that check. So:
for (int i = 0; i < 1000; i++) {
if (heap_stable) {
// do nothing
} else {
// more control flow slow call etc.
}
}
should be transformed to:
if (heap_stable) {
for (int i = 0; i < 1000; i++) {
// do nothing
}
} else {
for (int i = 0; i < 1000; i++) {
// more control flow slow call etc.
}
}
As a result in some cases the loop body can run as if there's no
barrier.
Roland.
More information about the hotspot-gc-dev
mailing list