JDK-8316653 : Large NMethodSizeLimit triggers assert during C1 code buffer allocation
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 11,17,21,22
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2023-09-14
  • Updated: 2025-06-04
  • Resolved: 2023-11-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 22
22 b25Fixed
Related Reports
Blocks :  
Relates :  
Relates :  
Description
### Failure analysis ###
The failure occurs due to a cast from an unsigned to a signed integer, which results in an overflow.

### Original report ###
A DESCRIPTION OF THE PROBLEM :
The develop vm option NMethodSizeLimit can cause JVM crash if we set a big value for it, no matter the running test program.

For example, for the following test program:

```java
public class NMethodSizeLimitTest {
    public static void main(String[] args) {
        System.out.println("Success Loaded!");
    }
}
```

If we run this program on Ubuntu with OpenJDK11 using the following command:

```java
pathTo/jdk11u/build/linux-x86_64-normal-server-fastdebug/jdk/bin/java -XX:NMethodSizeLimit=21474
83647 -cp . NMethodSizeLimitTest
```

The output of the above command is:

```java
# To suppress the following error report, specify this argument
# after -XX: or in .hotspotrc:  SuppressErrorAt=/codeCache.cpp:487
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/home/JVM/JVMs/LineCov/jdk11u/src/hotspot/share/code/codeCache.cpp:487), pid=3159, tid=3182
#  assert(size > 0) failed: Code cache allocation request must be > 0 but is -1932735136
#
# JRE version: OpenJDK Runtime Environment (11.0.21) (fastdebug build 11.0.21-internal+0-adhoc.root.jdk11u)
# Java VM: OpenJDK 64-Bit Server VM (fastdebug 11.0.21-internal+0-adhoc.root.jdk11u, mixed mode, tiered, compressed oops, g1 gc, linux-amd64)
# Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport %p %s %c %d %P" (or dumping to /home/tmp/core.3159)
#
# An error report file with more information is saved as:
# /home/tmp/hs_err_pid3159.log
#
# Compiler replay data is saved as:
# /home/tmp/replay_pid3159.log
#
# If you would like to submit a bug report, please visit:
#   https://bugreport.java.com/bugreport/crash.jsp
#
Current thread is 3182
Dumping core ...
Aborted (core dumped)
```

Ubuntu Version:

```java
NAME="Ubuntu"
VERSION="18.04.5 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.5 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
```

Also, this will cause the JVM to crash on OpenJDK8.


FREQUENCY : always



Comments
Changeset: c36ec2ca Author: Daniel Lundén <daniel.lunden@gmail.com> Committer: Roberto Castañeda Lozano <rcastanedalo@openjdk.org> Date: 2023-11-16 07:41:13 +0000 URL: https://git.openjdk.org/jdk/commit/c36ec2ca70248c2e4676fd725fbb132c3b929908
16-11-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/16656 Date: 2023-11-14 14:16:55 +0000
14-11-2023

The problem is that NMethodSizeLimit controls the size of the C1 code buffer and is casted from uint to int which may result in a negative number: https://github.com/openjdk/jdk/blob/90d5041b6a055d6266140ffea2aa9a3b08b32209/src/hotspot/share/c1/c1_Compilation.hpp#L211 The actual size is also a combination of Compilation::desired_max_code_buffer_size() + Compilation::desired_max_constant_size(): https://github.com/openjdk/jdk/blob/90d5041b6a055d6266140ffea2aa9a3b08b32209/src/hotspot/share/c1/c1_Compiler.cpp#L79 The valid range of the NMethodSizeLimit flag needs to be adjusted accordingly. ILW = Assert during debug (bailout in product), with extreme value of debug flag, no workaround but lower flag value = MLH = P4
11-10-2023

Issue is not reproduced. Crash is not observed. OS: Ubuntu 20.08 JDK 8u381: Pass JDK 11.0.20: Pass JDK 17.0.8: Pass Output: Error occurred during initialization of VM Could not reserve enough space in CodeHeap 'profiled nmethods' (0K) Moving it to dev team for further analysis.
21-09-2023