RFR: 8316653: Large NMethodSizeLimit triggers assert during C1 code buffer allocation
Daniel Lundén
duke at openjdk.org
Tue Nov 14 14:23:38 UTC 2023
This changeset fixes an overflow issue for the develop flag `-XX:NMethodSizeLimit` (`intx`, `range(0, max_jint)`).
In summary, `java -XX:NMethodSizeLimit=2147483647` triggers an assert in `CodeCache::allocate`:
# assert(size > 0) failed: Code cache allocation request must be > 0 but is -1932735136
Why?
1. The function `code_buffer_size` computes `NMethodSizeLimit + NMethodSizeLimit/10` as a signed integer (may overflow).
2. The `BufferBlob::create` function takes `code_buffer_size()` as argument and uses it (among other things, such as `sizeof(BufferBlob)`) to compute an unsigned size.
3. `BufferBlob::operator new` treats the unsigned size as signed (may overflow).
Changes:
- Change all data types in the above chain to `uint` and leave the flag range for `NMethodSizeLimit` untouched (`range(0, max_jint)`). This ensures no overflow.
- Add a new regression test.
### Testing
Platforms: windows-x64, linux-x64, linux-aarch64, macosx-x64, macosx-aarch64.
- `tier1`
- HotSpot parts of `tier2` and `tier3`
-------------
Commit messages:
- Add test case
- Readd assert for case when size == 0
- Fix issue
Changes: https://git.openjdk.org/jdk/pull/16656/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=16656&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8316653
Stats: 26 lines in 8 files changed: 14 ins; 0 del; 12 mod
Patch: https://git.openjdk.org/jdk/pull/16656.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/16656/head:pull/16656
PR: https://git.openjdk.org/jdk/pull/16656
More information about the hotspot-compiler-dev
mailing list