Skip to content

fix: avoid unsafe grouped int writes on aarch64+jdk8 - #21

Open
luckylucky0001 wants to merge 3 commits into
rg/base-7834-originalfrom
rg/7834-original
Open

luckylucky0001 wants to merge 3 commits into
rg/base-7834-originalfrom
rg/7834-original

Conversation

@luckylucky0001

Copy link
Copy Markdown
Owner

Fixes alibaba#7828

Why

On affected aarch64 + JDK 8 HotSpot C2 builds, grouped integer writes through unaligned Unsafe memory operations can be miscompiled and lose digits. This is the write-side counterpart of alibaba#7732 / alibaba#7755.

What

  • Route IOUtils grouped int writes on byte and char buffers through safe per-digit fallbacks only for the existing AARCH64_JDK8 gate.
  • Add exhaustive helper tests for 0-999 and fixed-width 4-digit writes, plus serialization regressions through UTF-16 and UTF-8 writers.
  • Keep all other platforms on the optimized fast path.

This branch is intentionally stacked on alibaba#7755 because it reuses the architecture/JVM gate introduced there. If maintainers prefer an independent patch after alibaba#7755 lands, I can rebase/split it.

@wenshao could you help review this follow-up?

Validation

Windows x86_64 JDK 1.8.0_333 with -DargLine=-Dos.arch=aarch64:

mvnw.cmd -pl core -Dtest='IOUtilsTest,JSONWriterUTF16Test,JSONWriterUTF8Test' '-DargLine=-Dos.arch=aarch64' test
Tests run: 146, Failures: 0, Errors: 0, Skipped: 0
Checkstyle violations: 0

A real affected aarch64 + Oracle JDK 8 host was not available in this environment.


Evaluation replay of alibaba#7834 (alibaba#7834). This PR stays open unless a separately authorized merge workflow runs.

…baba#7732, alibaba#3763)

Commit 291d744 (2.0.55) introduced UNSAFE.getLong SWAR in
JSONReaderUTF16.readFieldNameHashCode for 8-char stepping with
containsSlashOrQuoteUTF16 bit ops. The C2 compiler on aarch64+JDK8
miscompiles this SWAR path, causing field-name boundary errors
(illegal fieldName, expect ':'). Under high concurrency the
miscompiled method is cached in CodeCache, making all subsequent
JSON parsing fail permanently (alibaba#3763).

Fix: add AARCH64_JDK8 platform flag in JDKUtils; in the three
readFieldNameHashCode* entry points, fall back to the safe char[]
scanning path (readFieldNameHashCode0) when running on aarch64+JDK8.

Performance impact: only affects aarch64+JDK8 field-name parsing
(SWAR -> char[]). All other platforms are unaffected.

Test: Issue7732 regression test with real payloads from the issue
report (LoginUser, Device, SipRouteCache). Issue3763 concurrency
test unchanged. Both pass on x86.
…os.arch, add !OPENJ9

Per wenshao/qwen-code review on PR alibaba#7755 (2026-08-14):

* JSONReaderUTF16.readFieldNameHashCode0: drop (byte) cast so Latin-1 chars 0x80-0xFF pack unsigned, matching Fnv.hashCode64(char[], ...). Without this, parsing any UTF-16 JSON whose field name ends in 0x80-0xFF on aarch64+JDK8 mis-parses deterministically.

* JDKUtils: move System.getProperty("os.arch") into the existing try/catch so SecurityException on PropertyPermission("os.arch","read") degrades gracefully instead of killing <clinit>.

* JDKUtils.AARCH64_JDK8: also exclude OPENJ9 - the workaround targets HotSpot C2 miscompilation only.

* JSONReaderUTF16: add comments at the three AARCH64_JDK8 guards citing alibaba#7732/alibaba#3763 and noting retirement condition (JDK 8u472+).

* Issue7732: add testLatin1FieldName test for 0x80-0xFF field names plus ¼½¾ round-trip, gating the fix.

Refs: alibaba#7732, alibaba#3763, PR alibaba#7755 review by wenshao
@luckylucky0001

Copy link
Copy Markdown
Owner Author

本机 medium 档代码评审结果

上游来源:alibaba#7834。样本:原版 PR。
提交:6b2f28d8370c4e8c78d11247ea8b58d34e16eec7;基线:30dd009d196687d23e1bb718a6649dac3b356bda。
评审版本:aca8f632f59bb360;结果时间:2026-09-23T19:11:56.087Z。只对应上述提交;与旧版评论分别记录。

结论分三种:通过;需关注(AI 意见和无法验证的内容,不阻止合并);阻断(只在执行证据证实本 PR 引入缺陷,或仓库自己的 CI 失败时)。单条意见:已确认=通过稳定复现、归因和证据准入的缺陷;疑似=尚未排除、证据仍不足;待确认=未复现、既有行为或未完成验证;团队强制规则=命中团队规则,需人工确认。

推理档位 结果 验证完整 测试通过/总数 跳过 测试报告完整 准入证据 infra unknown flaky 基线已失败 建议人工介入记录
medium 阻断:仓库 CI 失败 否 368/369 0 否 0 0 2 0 0 2

medium 失败计数分域:PR 侧 unknown 2;基线侧失败 0 项,其中 unknown 0 项。unknown 保持原分类,不构成准入证据。

medium 基线对照:13 个文件有记录,0 个文件失败,7 个文件验证未完成。基线使用旧源码与 PR 侧相同测试,0 个文件观察到旧源码红 → PR 绿;未知失败仍需人工核查。表中“基线已失败”仅统计 PR 也出现的既有失败。

请求模型:doubao-seed-evolving。实际返回模型:medium=doubao-seed-evolving-latest-version。

medium · 阻断:仓库 CI 失败:Test JDK 11 on windows-latest、Test Reflect JDK 11 on ubuntu-24.04、Test JDK 21 on windows-latest、Test JDK 11 on ubuntu-24.04、Test JDK 25 on windows-latest、Test JDK 17 on ubuntu-24.04。

medium 结论

  • 待确认 · minor · core/src/test/java/com/alibaba/fastjson2/util/IOUtilsTest.java:54:修复未在真实受影响 aarch64+Oracle JDK8 上验证,回归测试在普通平台即使无修复也会通过。尚未获得完整、可重复且可归因的证据。

建议人工介入项不作为确认缺陷或自动修复的证据;尚未排除的疑似缺陷仍需核查。本结果只覆盖该提交、本次已执行测试与medium 档评审。

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