Skip to content

Omit null checks on return values when they're known to be not null#60

Draft
raneashay wants to merge 1 commit intomicrosoft:mainfrom
raneashay:ashay/null-check-opt
Draft

Omit null checks on return values when they're known to be not null#60
raneashay wants to merge 1 commit intomicrosoft:mainfrom
raneashay:ashay/null-check-opt

Conversation

@raneashay
Copy link

This patch augments the C2 bytecode parser's call node emission to skip
the null check on return values that are of reference type, if the
analysis can prove that returned values are never null. To determine
nullability, this patch makes use of the Byte Code Escape Analyzer,
which exposes methods to determine whether (1) the return value is
freshly allocated (and thus non-null) or (2) the return value is one of
the arguments, in which case, the caller's analysis of the arguments can
be extended to the callee's return value.

Key to this patch is a modification to the Byte Code Escape Analyzer's
logic for determining whether method's argument escapes. Prior to this
patch, the analysis was too conservative, resulting in constrcutor
(<init>) methods (which initialize freshy allocated objects) being
marked as escaping. This patch updates the logic so that the object
being initialized is not marked as escaping. All other arguments to
<init> are treated identically as before.

This patch also adds positive and negative checks on IR nodes in the
final ideal graph to exercise changes in this patch.

This patch augments the C2 bytecode parser's call node emission to skip
the null check on return values that are of reference type, if the
analysis can prove that returned values are never null.  To determine
nullability, this patch makes use of the Byte Code Escape Analyzer,
which exposes methods to determine whether (1) the return value is
freshly allocated (and thus non-null) or (2) the return value is one of
the arguments, in which case, the caller's analysis of the arguments can
be extended to the callee's return value.

Key to this patch is a modification to the Byte Code Escape Analyzer's
logic for determining whether method's argument escapes.  Prior to this
patch, the analysis was too conservative, resulting in constrcutor
(`<init>`) methods (which initialize freshy allocated objects) being
marked as escaping.  This patch updates the logic so that the object
being initialized is not marked as escaping.  All other arguments to
`<init>` are treated identically as before.

This patch also adds positive and negative checks on IR nodes in the
final ideal graph to exercise changes in this patch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant