Skip to main content

Process Memory

When a program runs, the operating system gives the process its own memory space.

Process Memory Layout

Memory Segments

When a process starts, the operating system sets aside certain memory regions for it.

  1. Code Segment: Contains the executable code of the program.
  2. Data Segment: Contains global and static variables.
  3. Heap: Used for dynamic memory allocation.
  4. Stack: Used for function calls and local variables.
different from JVM memory regions

This heap and stack differ from the JVM heap and stack. Those hold objects and the JVM thread stack. The JVM's own native code gets its heap and stack from the OS.

Threads inside process

When a process starts many threads, they all share the same memory space. Still, each thread gets its own stack segment for function calls and local variables.

It's described in detail in the context switching page.