RFR: 8316653: Large NMethodSizeLimit triggers assert during C1 code buffer allocation

Roberto Castañeda Lozano rcastanedalo at openjdk.org
Tue Nov 14 18:54:12 UTC 2023


On Tue, 14 Nov 2023 14:16:55 GMT, Daniel Lundén <duke at openjdk.org> wrote:

> This changeset fixes an overflow issue for the develop flag `-XX:NMethodSizeLimit`.
> 
> 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`

Looks good!

src/hotspot/share/code/codeCache.cpp line 526:

> 524:   assert_locked_or_safepoint(CodeCache_lock);
> 525:   assert(size > 0, "Code cache allocation request must be > 0 but is %d", size);
> 526:   if (size <= 0) {

Suggestion:

  assert(size > 0, "Code cache allocation request must be > 0");
  if (size == 0) {

-------------

Marked as reviewed by rcastanedalo (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/16656#pullrequestreview-1730496276
PR Review Comment: https://git.openjdk.org/jdk/pull/16656#discussion_r1393095825


More information about the hotspot-compiler-dev mailing list