Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8261578: jextract crashes with Crossing storage unit boundaries #451

Closed

Conversation

@mcimadamore
Copy link
Collaborator

@mcimadamore mcimadamore commented Feb 15, 2021

This patch overhauls the logic for bitfield detection, after discovering a number of related failures. The current logic attempts to find a unique container size for a bunch of adjacent bitfields (either 8, 16, 32 or 64 bits) and then allocates the bitfields into subsequent containers of same size.

The fact that the container size is decided once and for all at the beginning of parsing of the bitfield sequence is problematic, and breaks down in cases where containers are used only partially, or where padding is inserted.

To overcome these issues, I've now switched to a more flexible algorithm which, instead of fixing a container size before hands, just emits a new container whenever the cumulative offset of adjacent bitfield has reached a word boundary (either 8, 16, 32, 64 bits).

This makes the algorithm less strict, and less prone to crashes. However, since we're still reverse engineering bitfield information (as libclang doesn't give us that information), the solution will probably require more tweaks, especially in order to support packed structures, in which compilers emit bitfields which happily span across a word boundary.

For this reason, I did not included some of the examples listed in JDK-8261578 which make use of the packed attribute/pragma - that is unsupported anyway, see JDK-8259832. We should come back to these examples when support for pragma is added (for now I've added a link from the pragma JBS issue to this one, so that we'll not forget).

As for testing, I followed what other tests in this area did in the past - but I believe at some point we probably need to write better tests which use the jextract API to query bitfield offsets and sizes, because the tests, as currently written, do not assert much, other than that jextract is not failing badly.


Progress

  • Change must not contain extraneous whitespace
  • Change must be properly reviewed

Issue

  • JDK-8261578: jextract crashes with Crossing storage unit boundaries

Reviewers

Download

$ git fetch https://git.openjdk.java.net/panama-foreign pull/451/head:pull/451
$ git checkout pull/451

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Feb 15, 2021

👋 Welcome back mcimadamore! A progress list of the required criteria for merging this PR into foreign-jextract will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr label Feb 15, 2021
@mlbridge
Copy link

@mlbridge mlbridge bot commented Feb 15, 2021

Webrevs

@openjdk
Copy link

@openjdk openjdk bot commented Feb 15, 2021

@mcimadamore This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8261578: jextract crashes with Crossing storage unit boundaries

Reviewed-by: sundar

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been no new commits pushed to the foreign-jextract branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the foreign-jextract branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready label Feb 15, 2021
@mcimadamore
Copy link
Collaborator Author

@mcimadamore mcimadamore commented Feb 15, 2021

/integrate

@openjdk openjdk bot closed this Feb 15, 2021
@openjdk openjdk bot added integrated and removed ready rfr labels Feb 15, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Feb 15, 2021

@mcimadamore Pushed as commit 4d7180a.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

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