GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Memory leak related to jmethoid after profiling session is stopped · async-profiler/async-profiler · Discussion #1528

Memory leak related to jmethoid after profiling session is stopped #1528

Closed
yanglong1010 started this conversation in General
Memory leak related to jmethoid after profiling session is stopped #1528
@yanglong1010 yanglong1010
Oct 10, 2025 · 1 comment
Return to top
Discussion options
  • Uh oh!

    There was an error while loading. Please reload this page.

yanglong1010
Oct 10, 2025

Hi,

We recently encountered a real case about jmethodid memory leak.

After the profiling session (just 1 minute) is stopped, the RSS of the Java process will keep increasing, from 8G to 16G in several hours, and finally be killed by the OOM Killer.

The reason is the app used a library to evaluate expressions in each request, and the library defines new classes on the fly.
The metaspace is normal, because the generated classes can be unloaded. But the memory used to store jmethodids is never released, even if the profiling session is stopped, the jmethodids of new classes will still be generated greedily.

I think a protection should be added to async-profiler, to prevent similar problems from happening.

How about the following proposal:

  1. When profiling session is stopped, disable JVMTI_EVENT_CLASS_PREPARE also. And in the start of next session, iterate all known classed to generate jmethodids, just like the first time async-profiler is loaded. This can help if async-profiler is used as one time tool.
  2. If async-profiler is used as a continuous profiler, shall we add an adjustable number limit to jmethodids to be generated, after the limit is reached, jmethodid generation is disabled with a warn to stdout.
  3. The mechanism above only works on JDK 25 and bellow (https://bugs.openjdk.org/browse/JDK-8268406), since from JDK 26, the jmethodid memory leak is resolved in JDK.
image
<dependency>
    <groupId>com.googlecode.aviator</groupId>
    <artifactId>aviator</artifactId>
    <version>5.4.1</version>
</dependency>
import com.googlecode.aviator.AviatorEvaluator;
import com.googlecode.aviator.AviatorEvaluatorInstance;

public class AviatorTest {
    public static long sink = 0;
    public static void main(String[] args) {
        AviatorEvaluatorInstance ins = AviatorEvaluator.getInstance();
        long n = 0;
        while (true) {
            Object result = ins.execute(n + " + math.round(" + n + ")");
            sink += (Long)result;
        }
    }
}
You must be logged in to vote
All reactions

Replies: 1 comment

Comment options
  • Uh oh!

    There was an error while loading. Please reload this page.

apangin
Oct 13, 2025
Maintainer

Thank you for the report.
We are aware of this issue. It should be OK to add a hard-coded limit on the maximum number of jmethodIDs as a temporary measure. For a cleaner fix, I'd like to get rid of jmethodID usage entirely. This will be possible once we deprecate AsyncGetCallTrace-based stack walker.

You must be logged in to vote
All reactions
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
💬
General
Labels
None yet
2 participants
@yanglong1010 @apangin
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.