<commit_before>---
layout: post
title:  "Oh the Places Your Java Memory Goes"
date:   2017-04-28 10:11:00
---

Java heap memory does not make up 100-percent of a JVM process's memory
allocation. There are many categories of non-heap memory in a JVM process
that often account for more RAM than the heap when they are summed up. It's not uncommon to set your maximum heap size to 512 MB, `-Xmx512m`, and have your process consume more than 1 gigabyte of RAM
in total.

If you're not interested in learning about non-heap categories, you can
jump to [Suggestions for Improving JVM Memory Use](#suggestions) to get some
practical tips. But if you read through this post, you'll learn where your
Java process's memory is going and why. Let's take a look at these destinations.

### JVM Memory Categories

The most significant categories of JVM memory are:

* **Heap** - The heap is where your Class instantiations or "Objects" are stored.
* **Thread stacks** - Each thread has its own call stack. The stack stores primitive local variables and object references along with the call stack (list of method invocations) itself. The stack is cleaned up as stack frames move out of context so there is no GC performed here.
* **Metaspace** - Metaspace stores the Class definitions of your Objects, and some other metadata.
* **Code cache** - The JIT compiler stores native code it generates in the code cache to improve performance by reusing it.
* **Buffer pools** - Many libraries and frameworks allocate buffers outside of the heap to improve performance. These buffer pools can be used to share memory between Java code and native code, or map regions of a file into memory.
* **OS memory** - The operating system keeps heap and stacks for a Java process independent of the heap and stacks managed by the JVM itself. There is also memory consumed for each native library loaded (such as `libjvm.so`). This is usually very small.<commit_msg>Revisions<commit_after>---
layout: post
title:  "Oh the Places Your Java Memory Goes"
date:   2017-04-28 10:11:00
---

Java heap memory does not make up 100-percent of a JVM process's memory
allocation. There are many categories of non-heap memory in a JVM process
that often account for more RAM than the heap when they are summed up. It's possible to set your maximum heap size to 512 MB, `-Xmx512m`, and have your process consume more than 1 gigabyte of RAM
in total.

If you're not interested in learning about non-heap categories, you can
jump to [Suggestions for Improving JVM Memory Use](#suggestions) to get some
practical tips. But if you read through this post, you'll learn where your
Java process's memory is going and why. Let's take a look at these destinations.

### JVM Memory Categories

The most significant categories of JVM memory are:

* **Heap** - The heap is where your Class instantiations or "Objects" are stored.
* **Thread stacks** - Each thread has its own call stack. The stack stores primitive local variables and object references along with the call stack (list of method invocations) itself. The stack is cleaned up as stack frames move out of context so there is no GC performed here.
* **Metaspace** - Metaspace stores the Class definitions of your Objects, and some other metadata.
* **Code cache** - The JIT compiler stores native code it generates in the code cache to improve performance by reusing it.
* **Buffer pools** - Many libraries and frameworks allocate buffers outside of the heap to improve performance. These buffer pools can be used to share memory between Java code and native code, or map regions of a file into memory.
* **OS memory** - The operating system keeps heap and stacks for a Java process independent of the heap and stacks managed by the JVM itself. There is also memory consumed for each native library loaded (such as `libjvm.so`). This is usually very small.
{'fraction_non_alphanumeric': 0.05541170378042465, 'fraction_numerical': 0.012428793371310202, 'mean_word_length': 4.248641304347826, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3135919', 'n_tokens_mistral': 1011, 'n_tokens_neox': 929, 'n_words': 620}