Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GR-54108] Polyglot memory leak on simple python execution #8927

Open
allanfrankwork opened this issue May 15, 2024 · 1 comment
Open

[GR-54108] Polyglot memory leak on simple python execution #8927

allanfrankwork opened this issue May 15, 2024 · 1 comment
Assignees
Labels

Comments

@allanfrankwork
Copy link

Describe GraalVM and your environment :

  • GraalVM version or commit id if built from source: graalvm-community-openjdk-21.0.2+13.1
  • CE or EE: CE
  • JDK version: openjdk-21.0.2
  • OS and OS Version: Windows 11
  • Architecture: amd64
  • The output of java -Xinternalversion:
OpenJDK 64-Bit Server VM (21.0.2+13-jvmci-23.1-b30) for windows-amd64 JRE (21.0.2+13-jvmci-23.1-b30), built on 2024-01-06T13:07:49Z by "Buildbot" with MS VC++ 17.1 (VS2022)

Have you verified this issue still happens when using the latest snapshot?
Yes, but did have to run with -Dpolyglotimpl.DisableVersionChecks=true

Describe the issue
When running a simple python Hello world case (from https://www.graalvm.org/latest/reference-manual/python/) in a loop, the CACHE in com.oracle.graal.python.builtins.objects.function.BuiltinMethodDescriptor keeps growing.

I would expect this leads to a OOM eventually although have not reproduced this with the simple case. I have seen a production application experiencing OOM with 80% of memory consumed by this CACHE variable.

Code snippet or code repository that reproduces the issue

public class Main {
    public static void main(String[] args) {
        while(true) {
            try (var context = Context.create()) {
                System.out.println(context.eval("python", "'Hello Python!'").asString());
            }
        }
    }
}
pom.xml with:
    <dependencies>
        <dependency>
            <groupId>org.graalvm.polyglot</groupId>
            <artifactId>polyglot</artifactId>
            <version>24.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.graalvm.polyglot</groupId>
            <artifactId>python</artifactId>
            <version>24.0.1</version>
            <type>pom</type>
        </dependency>
    </dependencies>

Steps to reproduce the issue
Please include both build steps as well as run steps

  1. Put code into Main.java
  2. Put dependencies into pom.xml
  3. Run code. Run in debug and monitor com.oracle.graal.python.builtins.objects.function.BuiltinMethodDescriptor.CACHE. This keeps growing with 16 entries per python execution.

Expected behavior
After Context.close(), would expect Garbage collector to do its work. Or at least that the cache should not keep growing when executing the same code again.

Additional context
com.oracle.graal.python.builtins.objects.function.BuiltinMethodDescriptor.CACHE seems to contain builtin functions that look fine, but dump contents I see these entries keep growing:

UnaryBuiltinDescriptor{tuple.repr}

Can it be that some proxy class object is unique per execution leading to new entries getting put into the CACHE?

I have tried several different versions of contructing Engine, Source, Context, but they all experience ever-growing CACHE.

Thanks!

@fernando-valdez fernando-valdez self-assigned this May 16, 2024
@fernando-valdez fernando-valdez changed the title Polyglot memory leak on simple python execution [GR-54108] Polyglot memory leak on simple python execution May 16, 2024
@fernando-valdez
Copy link
Member

Thanks for reporting this issue. I created an internal ticket to track this issue: GR-54108

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants