JVM memory allocation

Ok, so I have a question regarding JVM memory segments, I know that every JVM would decide to implement this a little differently, but this is a general concept that should remain unchanged in all JVM files

The standard C / C ++ program, which does not use the virtual machine for execution at run time, has four memory segments at run time, Code / Stack / Heap / Data, all these memory segments are automatically allocated by the operating system at run time.

However, when the JVM runs a compiled Java program, it has 5 memory segments at runtime

Method Scope / Heaps / Java Stacks / PC Registers / Native Stacks

My question is, who distributes and manages these memory segments? The operating system does not know about the Java program that works and thinks that this part of the JVM works like a regular computer program, JIT compiles Java stacks, these operations require memory allocation execution time, and that I don’t understand how the JVM divides its memory into these segments of memory. This certainly does not work on the operating system, and these memory segments (like the Java stack) must be continuous in order to work, so if the JVM program just uses commands like TaNos to get the maximum size of the memory heap and split this memory for segments, we have no promises for continuous memory, I would like it if someone helped me get it right in my head, it all got messed up ...

+4
source share
1 answer

When the JVM starts, it has hundreds, if not thousands, of memory areas. For example, there is a stack for each thread, as well as a stream state area. There is a memory mapping for each shared library and jar. Note. The 64-bit version of Java does not use segments, such as a 16-bit application.

which distributes and manages these memory segments?

All mappings / memory regions are allocated to the OS.

The operating system does NOT know about the running java program and thinks that it is part of the JVM, running as a regular program on the computer,

JVM , , . , Java JVM, , .

JIT, Java,

JIT , Java .

,

malloc free map unmap

, , JVM .

. Java. , , , .

, (, java) ,

, , . Linux, , , 32- 64- .

, JVM malloc, ,

, G1, .

, , , , , .

, - , ...

, JVM , , Java- , . , C, JVM - C/++.

+2

Source: https://habr.com/ru/post/1629682/


All Articles