Skip to content

Fix signedness error of max LOS size in C2#348

Merged
qinsoon merged 2 commits intommtk:jdk-21from
wks:fix/max_non_los_bytes_c2-jdk21
Mar 23, 2026
Merged

Fix signedness error of max LOS size in C2#348
qinsoon merged 2 commits intommtk:jdk-21from
wks:fix/max_non_los_bytes_c2-jdk21

Conversation

@wks
Copy link
Copy Markdown
Contributor

@wks wks commented Mar 18, 2026

The PlanConstraints::max_non_los_default_alloc_bytes constant is a usize and can be usize::MAX for some plans including NoGC. The C2 code erroneously considered it signed and did signed comparison against object sizes. Consequently, when allocating dynamically sized arrays, the C2-generated code always goes to the slow path. It slows down certain workloads (such as hsqldb and luindex in DaCapo 2006) by 20% in total time.

We fix this bug by always performing 64-bit unsigned comparison.

The `PlanConstraints::max_non_los_default_alloc_bytes` constant is a
`usize` and can be `usize::MAX` for some plans including NoGC.  The C2
code erroneously considered it signed and did signed comparison against
object sizes.  Consequently, when allocating dynamically sized arrays,
the C2-generated code always goes to the slow path.  It slows down
certain workloads (such as hsqldb and luindex in DaCapo 2006) by 20% in
total time.

We fix this bug by always performing 64-bit unsigned comparison.
@wks wks requested a review from qinsoon March 21, 2026 01:01
Copy link
Copy Markdown
Member

@qinsoon qinsoon left a comment

Choose a reason for hiding this comment

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

LGTM

@qinsoon
Copy link
Copy Markdown
Member

qinsoon commented Mar 22, 2026

I opened a PR to allow easier backporting to jdk-11. We should consider merging that PR first, and try the workflow with this PR.

@qinsoon
Copy link
Copy Markdown
Member

qinsoon commented Mar 22, 2026

mmtk/mmtk-core#1456 changed the default max_non_los_default_alloc_bytes from signed int32 max to unsigned uint64 max, which revealed this bug. It is just incidental that we only observed slowdown for NoGC from this issue, as every other plan overrides the value max_non_los_default_alloc_bytes.

@qinsoon qinsoon merged commit e6dcac0 into mmtk:jdk-21 Mar 23, 2026
10 checks passed
mergify Bot pushed a commit that referenced this pull request Mar 23, 2026
The `PlanConstraints::max_non_los_default_alloc_bytes` constant is a
`usize` and can be `usize::MAX` for some plans including NoGC. The C2
code erroneously considered it signed and did signed comparison against
object sizes. Consequently, when allocating dynamically sized arrays,
the C2-generated code always goes to the slow path. It slows down
certain workloads (such as hsqldb and luindex in DaCapo 2006) by 20% in
total time.

We fix this bug by always performing 64-bit unsigned comparison.

(cherry picked from commit e6dcac0)

# Conflicts:
#	mmtk/Cargo.lock
wks added a commit that referenced this pull request Mar 23, 2026
The `PlanConstraints::max_non_los_default_alloc_bytes` constant is a
`usize` and can be `usize::MAX` for some plans including NoGC. The C2
code erroneously considered it signed and did signed comparison against
object sizes. Consequently, when allocating dynamically sized arrays,
the C2-generated code always goes to the slow path. It slows down
certain workloads (such as hsqldb and luindex in DaCapo 2006) by 20% in
total time.

We fix this bug by always performing 64-bit unsigned comparison.

This is an automatic backport of pull request #348 done by [Mergify](https://mergify.com).

---------

Co-authored-by: Kunshan Wang <wks1986@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants