[GR-54108] Polyglot memory leak on simple python execution
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
- Put code into Main.java
- Put dependencies into pom.xml
- 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!
Thanks for reporting this issue. I created an internal ticket to track this issue: GR-54108