> For the complete documentation index, see [llms.txt](https://tingreavinash.gitbook.io/the-tech-toolbox/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tingreavinash.gitbook.io/the-tech-toolbox/notes/java-fundamentals/jvm-internals.md).

# JVM Internals

## JVM (Java Virtual Machine)

The JVM is an abstract machine that runs compiled Java code. It provides a layer of abstraction between the operating system and the Java code, allowing Java programs to be executed on any platform. Here are some important points to keep in mind about the JVM:

* **Class Loader** - Loads Java classes into memory at runtime
* **Execution Engine** - Executes the compiled Java code
* **Garbage Collector** - Manages memory allocation and deallocation
* **Java Native Interface (JNI)** - Allows Java code to call and be called by native applications and libraries
* **Java Development Kit (JDK)** - Includes the JVM as well as the tools needed for Java development

## Garbage Collection

Garbage collection is the process of automatically freeing up memory that is no longer being used by a program. The JVM includes a garbage collector that automatically manages memory allocation and deallocation. Here are some key points about garbage collection:

* **Heap** - The area of memory where objects are allocated
* **Generational Garbage Collection** - The garbage collector divides the heap into generations and collects objects based on their age and reachability
* **Young Generation** - The area of the heap where new objects are allocated
* **Old Generation** - The area of the heap where long-lived objects are allocated
* **PermGen/Metaspace** - The area of the heap where metadata about classes is stored. In Java 8, PermGen was replaced with Metaspace which is a non-heap memory.
* **Garbage Collection Algorithms** - The JVM provides several garbage collection algorithms, including:
  * **Serial Collector** - Single-threaded, compacting collector that is suitable for small applications or low-concurrency environments
  * **Parallel Collector** - Multi-threaded, non-compacting collector that is suitable for medium to large applications with high throughput
  * **CMS (Concurrent Mark and Sweep) Collector** - Multi-threaded, concurrent collector that is suitable for large applications with low pause time requirements
  * **G1 (Garbage First) Collector** - Multi-threaded, region-based collector that is suitable for large applications with high throughput and low pause time requirements.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://tingreavinash.gitbook.io/the-tech-toolbox/notes/java-fundamentals/jvm-internals.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
