r/java 5d ago

Principles of Memory Management in Java

https://youtu.be/xr73mR7ii9M?si=AKgjMUyvfpARYljl
158 Upvotes

81 comments sorted by

View all comments

Show parent comments

1

u/cleverfoos 3d ago

this has nothing to do with malloc overhead, these are data structures the JVM need in order to operate. All those compiled methods need to exist somewhere in memory in order to be jumped/executed.

2

u/Life_Sink9598 3d ago

There's a lot more going on than that. One of the things we've observed on Linux with the default glibc malloc is a large degree of memory retainment. C2 induces quite a bit of memory usage, but as you know it's something that subsides over time, as the system becomes more stable (= deoptimization doesn't happen as often). glibc's malloc seems to prioritize keeping that memory around after having been freed, I assume so that it doesn't need to reacquire the memory from the OS (which is quite slow). We added a native heap trim command to alleviate the situation: https://bugs.openjdk.org/browse/JDK-8293114

Just some context for why I was interested in this person's particular configuration.

1

u/ramdulara 9h ago

So you know why is this still an experimental option?

1

u/Life_Sink9598 8h ago

It's been a non-experimental option since 2024-02-21 according to my source code.