gpt4 book ai didi

Java堆在jvm内存内部还是外部?

转载 作者:IT老高 更新时间:2023-10-28 20:46:23 28 4
gpt4 key购买 nike

直到今天我才知道 java 有堆,它是由 JVM 创建的。此外,此内存由操作系统分配给 JVM 实例,即堆驻留在 JVM 实例中。

但是今天我看到了一张图片,enter image description here

这表明,JVM 和堆相距甚远。

所以,我现在很困惑,谁能告诉我,我之前是错的还是我无法理解图片?

最佳答案

关于这个问题有很多要讨论的。我一直很喜欢 IBM 的文章,因为它包含了非常好的信息。对于这个特定的问题,这里有一段摘录。

来自 The native and Java heaps article on IBM :

The JVM maintains two memory areas, the Java™ heap, and the native (or system) heap. These two heaps have different purposes and are maintained by different mechanisms.

The Java heap contains the instances of Java objects and is often referred to as 'the heap'. It is the Java heap that is maintained by Garbage Collection, and it is the Java heap that is changed by the command-line heap settings. The Java heap is allocated using mmap, or shmat if large page support is requested. The maximum size of the Java heap is preallocated during JVM startup as one contiguous area, even if the minimum heap size setting is lower. This allocation allows the artificial heap size limit imposed by the minimum heap size setting to move toward the actual heap size limit with heap expansion.

The native, or system heap, is allocated by using the underlying malloc and free mechanisms of the operating system, and is used for the underlying implementation of particular Java objects; for example:

  • Motif objects required by AWT and Swing
  • Buffers for data compression routines, which are the memory space that the Java Class Libraries require to read or write compressed data like .zip or .jar files.
  • Malloc allocations by application JNI code
  • Compiled code generated by the Just In Time (JIT) Compiler
  • Threads to map to Java threads

希望能帮助你理解。

关于Java堆在jvm内存内部还是外部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20093356/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com