Book Image

Java Memory Management

By : Maaike van Putten, Dr. Seán Kennedy
Book Image

Java Memory Management

By: Maaike van Putten, Dr. Seán Kennedy

Overview of this book

Understanding how Java organizes memory is important for every Java professional, but this particular topic is a common knowledge gap for many software professionals. Having in-depth knowledge of memory functioning and management is incredibly useful in writing and analyzing code, as well as debugging memory problems. In fact, it can be just the knowledge you need to level up your skills and career. In this book, you’ll start by working through the basics of Java memory. After that, you’ll dive into the different segments individually. You’ll explore the stack, the heap, and the Metaspace. Next, you’ll be ready to delve into JVM standard garbage collectors. The book will also show you how to tune, monitor and profile JVM memory management. Later chapters will guide you on how to avoid and spot memory leaks. By the end of this book, you’ll have understood how Java manages memory and how to customize it for the benefit of your applications.
Table of Contents (10 chapters)

JVM usage of the Metaspace

The Metaspace is a special area of native memory outside of the heap. Native memory is memory provided by the operating system to an application for its own use. The JVM uses the Metaspace to store class-related information, that is, the class’s runtime representation. This is the class’s metadata; hence the metadata is stored in the Metaspace.

Metadata

Metadata is information about data. For example, columns in a database are metadata about the data in the columns. Thus, if a column name is Name and a specific row value is John, then Name is metadata about John.

This metadata consists of the following:

  • Class files
  • Structure and methods of the class
  • Constants
  • Annotations
  • Optimizations

Thus, in metadata, the JVM has everything it requires to work with the class.

PermGen

Prior to Java 8, the metadata was stored in an area (contiguous with the heap) known as PermGen, or permanent generation. PermGen...