C2 Scalar Replacement Behavior?
Vladimir Kozlov
Vladimir.Kozlov at Sun.COM
Mon Nov 17 12:35:17 PST 2008
Edward Lee wrote:
> A couple questions about object scalar replacement in opto
> (PhaseMacroExpand::eliminate_allocate_node):
Edward,
Please note, eliminate_allocate_node() is only the final
stage of the scalar replacement. Other parts of optimizer
also work for it.
>
> 1) Object allocations are eliminated only if they're only written to.
> It seems that any field loads prevent it from being scalar replaced,
> but I would have thought that after scalar replacement, a pair of
> stores/loads would become plain plain def/use. Is there any particular
> reason for this?
All uses of scalar replaceable object's fields should be replaced
with values stored into the fields (or with default value 0 if
there were no stores). It happens during Global Value Numbering
optimizations (see LoadNode::split_through_phi() and
MemNode::optimize_memory_chain() in memnode.cpp).
We have to keep allocations if optimizer was not able to eliminate
all loads (for example, volatile fields).
>
> 2) Allocations with multiple CheckCastPP nodes aren't eliminated. Is
> it because it's known that allocations with non-unique CheckCastPP
> definitely will have uses that make them non-eliminate-able? If not,
Only one unique CheckCastPP could be used to keep fields type aliasing
information during GVN optimizations.
> it seems that can_eliminate_allocation() would just need an extra
> nested DU loop over each of the allocation's CheckCastPPs.
The check in can_eliminate_allocation() is only a safeguard.
An object is marked as scalar_replaceable "optimistically"
if it has several CheckCastPP. It will be removed only if
optimizer will fold multiple CheckCastPP to one
and there are no any fields references.
>
> Just to make sure I'm understanding the code correctly, scalar
> replacement behaves as..
>
> 1) Do escape analysis and mark allocations that NoEscape as possibly
> scalar_replacable
Correct. And it also create new unique phis and type aliasing information
for all fields references of scalar_replaceable objects.
> 2) For allocations with a single casts, make sure fields are only
> stored to and the object is not returned/passed as arguments
Correct. Also an object will not be scalar replaced if values
of all fields are not found (value_from_mem() returns NULL).
> 2.1) Additionally keep track of safepoint uses for..
> 3) scalar_replacement() converts safepoint uses of the allocation into
> SafePointScalarObjectNodes
Correct. It is used to created a data used for an object reconstruction
during deoptimization.
> 4) Clean up uses of allocation by converting stores nodes into their
> memory input and fix projections for control, memory, i/o
Correct.
>
> Ed
Thanks,
Vladimir
More information about the hotspot-dev
mailing list