liveBook · Manning

Metaspace

As explained in Troubleshooting Java, Second Edition

Metaspace is JVM-managed native memory that stores class metadata needed during Java application execution.

Metaspace is JVM-managed native memory that stores class metadata required while a Java application runs. VisualVM exposes its allocation separately from ordinary heap usage. section 5.2.3

Investigate metaspace when:

  • The application reports an OutOfMemoryError related to metaspace. section 5.2.3
  • Memory allocation grows unexpectedly while frameworks or libraries use Java reflection, dynamic proxies, or indirect calls. section 5.2.3
  • A persistence process misuses Hibernate by loading too many database records into one context. section 5.2.3

A metaspace investigation

Open VisualVM’s memory allocation widget and inspect the Metaspace tab. If usage continues to rise, examine reflection-heavy frameworks and scheduled database processing rather than treating a larger Java heap as the root-cause fix. section 5.2.3

How Troubleshooting Java, Second Edition covers it

How deep it goes
Defines class-metadata storage and shows VisualVM observation, but stops short of explaining JVM metadata internals.
Examples
Uses VisualVM’s Metaspace tab and a Hibernate process that loads many database records.
What it assumes
Assumes basic Java application and memory concepts while defining metaspace from zero.
What you can do after
Diagnose metaspace growth by inspecting VisualVM and investigating reflection-heavy or persistence-framework usage.
How it connects
Connects metaspace with JVM memory, OutOfMemoryError, Java reflection, dynamic proxies, Hibernate, and VisualVM.

This explainer was generated by Manning's knowledge graph from the text of Troubleshooting Java, Second Edition. The section links point to the parts of the book it draws on.