1

Are the static members of a class - static variables, static blocks, and static methods stored in the Metaspace region after Java 8? If not, where are they stored?

There is no concrete information regarding the same elsewhere. All that I was able to get the information was that static variables are allocated memory at the time of class loading. But my question is where exactly is the memory being allocated - stack or heap or metaspace?

Thanks in advance!

2
  • 3
    @Thomas Please check the link provided in the answer (openjdk.java.net/jeps/122). Here, it says that The proposed implementation will allocate class meta-data in native memory and move interned Strings and class statics to the Java heap. Commented Nov 26, 2021 at 14:12
  • Note that this is specific to the JVM implementation, i.e. JEP 122 specifically states it applies to HotSpot. Other implementations like OpenJ9 don't have Metaspace so they'd store the static fields somewhere else (from what I could find OpenJ9 only uses heap memory). Commented Nov 29, 2021 at 7:21

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.