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

Fix issues between reference counting and the custom JSON.parse implementation #673

Merged

Conversation

saulecabrera
Copy link
Member

Description of the change

This change contains two commits, each with a clear description of the change.

Checklist

  • I've updated the relevant CHANGELOG files if necessary. Changes to javy-cli and javy-core do not require updating CHANGELOG files.
  • I've updated the relevant crate versions if necessary. Versioning policy for library crates
  • I've updated documentation including crate documentation if necessary.

This commit introduces a minimal failing test case where SIMD JSON
parsing and reference couting causes a panic.

Analysis:

Even though our fork of rquickjs disallows GC, it doesn't prevent
reference counting. This, combined with the usage of
`JS_DefinePropertyValue` which decrements the reference count of each
String value inside a map, introduced the bug showcased in this commit.
This commit is follow-up to the previous commit, in which the
relationship between reference counting and String Object value creation
is fixed by:

- Avoiding the usage of `unsafe` APIs
- Ensuring that everytime a string value gets created it gets correctly
  taken into acount.

Using rquickjs' safe APIs ensures that new values get cloned, which
means that `JS_DupValue` is called, which correctly increases the
reference count.
@saulecabrera saulecabrera requested a review from jeffcharles June 19, 2024 22:33
Copy link
Collaborator

@jeffcharles jeffcharles left a comment

Choose a reason for hiding this comment

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

Good catch!

@saulecabrera
Copy link
Member Author

I'm still figuring out the CI failures, maybe it's something with GH actions. Locally everything passes 🤷🏽

@saulecabrera
Copy link
Member Author

I'm still figuring out the CI failures, maybe it's something with GH actions. Locally everything passes 🤷🏽

Err - a missing cfg and clippy

@saulecabrera saulecabrera merged commit 21e7c97 into bytecodealliance:main Jun 20, 2024
14 checks passed
@saulecabrera saulecabrera deleted the fix-gc-simd-json-parse branch June 20, 2024 11:14
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.

2 participants