Skip to content

Weaken subtyping assertion for invokevirtual of an interface method - #14886

Merged
0xdaryl merged 1 commit into
eclipse-openj9:masterfrom
jdmpapin:invokevirtual-iface-assert
Apr 9, 2022
Merged

0xdaryl merged 1 commit into
eclipse-openj9:masterfrom
jdmpapin:invokevirtual-iface-assert

Conversation

@jdmpapin

@jdmpapin jdmpapin commented Apr 7, 2022

Copy link
Copy Markdown
Contributor

We don't necessarily know that callSiteClass is a subtype of the _receiverClass, which may have been refined to a more specific interface. In particular, the following situation can arise:

  • This call site is calling callSiteClass.callee(), and callSiteClass inherits callee() from an interface defInterface, so the callee method appears to be defInterface.callee().

  • The receiver comes from somewhere in the calling context with signature subInterface, which is a sub-interface of defInterface.

  • _receiverClass is refined from defInterface to subInterface based on the calling context.

  • callSiteClass implements defInterface but not subInterface. We know for certain that it implements defInterface because it inherits the callee from there. The assertion now checks this less specific typing relationship instead of checking against _receiverClass.

  • Actual receivers are most likely to be instances of subclasses of callSiteClass that do implement subInterface. They might also be instances of callSiteClass but not subInterface (e.g. instances of exactly callSiteClass), which can happen despite the signature because signatures are unreliable when they name interface types.

When this happens, callSiteClass is not a refinement of _receiverClass (i.e. of subInterface), but it is a better refinement of defInterface. It's fine to go on and replace _receiverClass, since effectively that's just forgetting the earlier refinement and then refining again with callSiteClass instead.

Fixes #14526

We don't necessarily know that callSiteClass is a subtype of the
_receiverClass, which may have been refined to a more specific
interface. In particular, the following situation can arise:

- This call site is calling callSiteClass.callee(), and callSiteClass
  inherits callee() from an interface defInterface, so the callee method
  appears to be defInterface.callee().

- The receiver comes from somewhere in the calling context with
  signature subInterface, which is a sub-interface of defInterface.

- _receiverClass is refined from defInterface to subInterface based on
  the calling context.

- callSiteClass implements defInterface but not subInterface. We know
  for certain that it implements defInterface because it inherits the
  callee from there. The assertion now checks this less specific typing
  relationship instead of checking against _receiverClass.

- Actual receivers are most likely to be instances of subclasses of
  callSiteClass that do implement subInterface. They might also be
  instances of callSiteClass but not subInterface (e.g. instances of
  exactly callSiteClass), which can happen despite the signature because
  signatures are unreliable when they name interface types.

When this happens, callSiteClass is not a refinement of _receiverClass
(i.e. of subInterface), but it is a better refinement of defInterface.
It's fine to go on and replace _receiverClass, since effectively that's
just forgetting the earlier refinement and then refining again with
callSiteClass instead.
@jdmpapin
jdmpapin requested a review from 0xdaryl April 8, 2022 13:35

@lmgray lmgray left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can vouch for the fix as far as the original problem I reported is concerned -- using a test fix from @jdmpapin , I looped our previously failing build 100+ times with no failures -- previously, this build would fail consistently every 3-5 builds

@0xdaryl

0xdaryl commented Apr 8, 2022

Copy link
Copy Markdown
Contributor

Jenkins test sanity.functional,extended.functional all jdk11,jdk17

@0xdaryl 0xdaryl self-assigned this Apr 9, 2022
@0xdaryl

0xdaryl commented Apr 9, 2022

Copy link
Copy Markdown
Contributor

Please create a 0.32 release PR for this fix as well.

@jdmpapin

Copy link
Copy Markdown
Contributor Author

Opened #14898 for 0.32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assertion failed CallSiteClass is incompatible with the receiverClass. running sonarqube scan using maven 3.8.4+ semeru 11.0.14.1

3 participants