Why doesn't Java support auto heap expansion?

Why doesn't Java expand the heap size until it reaches the memory limit of the process installed by the OS, just like the .NET CLR does?

Is this just a JVM developer policy or is it an advantage of the .NET CLR architecture over the JVM? In other words, if Oracle engineers want to implement automatic heap extensions for the JVM, can they do it?

thanks

EDIT: I really think this is a poor design choice for java. It is not safe to install Xmx as high as possible (for example, 100 GB!). If the user needs to run my code for big data, he can run it on a system with more available RAM. Why should I, as a developer, set the maximum available memory of my program? I do not know what size data!

+6
source share
2 answers

The JVM increases the heap size when required to the maximum heap size that you set. It does not take up all the memory, since it has to pre-install it at startup, and you might want to use some memory for something else, like stream stacks, shared libraries, heap memory, etc.

Why doesn't Java expand the heap size until it reaches the memory limit of the process installed by the OS, just like the .NET CLR does?

If you set the maximum heap size large enough, or use the heap memory, it will. By default, this will not be done. One of the reasons is that the heap memory must be in the main memory and cannot be replaced without losing the performance of your computer (unless you kill your computer). This does not apply to C programs, and the extension is so strong that it cannot expand.

If you have a JVM with a heap size 10% larger than the main memory, and you use so much as soon as you run the GC, which should touch each page more than once, you will probably find the information you need to power the loop .

Linux has a killer process when resources run out and it doesn’t cause you may have enough luck to restart.

Is this just a JVM developer policy or is it an advantage of the .NET CLR architecture over the JVM one

A key feature of the JVM is that it is platform independent, so it has its own control. A JVM running at the limit of your process space will most likely not allow your computer to run (from a heavy replacement). I do not know that .NET is avoiding this.

In other words, if Oracle engineers want to implement automatic heap extensions for the JVM, can they do it?

This is already the case, as I said, it is simply not recommended to allow it to use too much memory.

+6
source

The decision of the developers to decide how much memory heap should be allowed for the java process. it is based on various factors, such as the design of the project, the platform on which it will be launched, etc.

We can set heap size properties

-Xms<size> set initial Java heap size -Xmx<size> set maximum Java heap size -Xss<size> set java thread stack size 

As you can see, we set the initial heap size, and if later the JVM detects that more is needed, it can increase the heap size to the maximum specified limit. Infact resizing when we do GC (not mandate). I posted a question for similar reasons. You can turn to him. Thus, the increase / decrease in heap size is performed by the JVM. All we have to do, as the developers specify a restriction based on our requirements.

+3
source

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


All Articles