Skip to content

fix: avoid unsafe UTF-16 fast paths on aarch64 JDK 8 - #7852

Open
xuzhaorui wants to merge 1 commit into
alibaba:mainfrom
xuzhaorui:fix/jdk8-aarch64-unaligned-char-access
Open

fix: avoid unsafe UTF-16 fast paths on aarch64 JDK 8#7852
xuzhaorui wants to merge 1 commit into
alibaba:mainfrom
xuzhaorui:fix/jdk8-aarch64-unaligned-char-access

Conversation

@xuzhaorui

Copy link
Copy Markdown

What this PR does / why we need it?

On AArch64 with Oracle JDK 8, C2 can miscompile unaligned Unsafe accesses used by the UTF-16 parsing and writing fast paths. This can make repeated parsing of false produce an incorrect value and can corrupt repeated UTF-16 string serialization.

This change disables only the affected fast paths on that runtime and keeps the existing optimized paths for other environments.

Summary of your change

  • Add AARCH64_JDK8 runtime detection for JDK 8 AArch64, excluding Android, GraalVM, and OpenJ9.
  • Use character-by-character comparison for IOUtils.isALSE(char[]) and notALSE(char[]) on the affected runtime.
  • Route JDK 8 AArch64 UTF-16 writers to the safe implementation instead of the Unsafe-based implementation.
  • Add regression coverage for repeated boolean parsing and string serialization.

Related: #7834. This PR focuses on the boolean parsing and UTF-16 string serialization paths reported in #7838; it does not change the other Unsafe access sites covered by #7834.

本地环境为 x86_64 + JDK 17,无法直接复现 AArch64 + JDK 8 的 C2 错误;因此回归测试在当前环境验证行为不回退,目标平台上的安全分支由运行时检测启用。

Validation:

  • ./mvnw -pl core test — 7990 tests passed.
  • ./mvnw -pl core -Dfastjson2.creator=reflect -Dtest=Issue7838Test test — 2 tests passed.
  • ./mvnw -pl core -Dtest=Issue7838Test test — 2 tests passed.
  • ./mvnw -pl core validate — passed with 0 Checkstyle violations.

No documentation changes are needed.

Please indicate you've done the following:

  • Made sure tests are passing and test coverage is added if needed.
  • Made sure commit message follow the rule of Conventional Commits specification.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


xuzhaorui seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

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