java中提交内存的确切状态

发布于 2024-07-07 13:06:31 字数 202 浏览 9 评论 0原文

我很好奇当从 MemoryUsage 类查询该值时,“提交”内存的确切含义是什么。 该类将其解释为“已提交代表保证可供 Java 虚拟机使用的内存量(以字节为单位)”。 这是否意味着该内存正在被 jvm 进程使用,并且在被 java 进程释放之前不可用于其他进程,或者是否意味着如果 java 进程尝试分配最多该内存量,它就会成功? 我意识到这可能是特定于实现的,但我只对热点感兴趣。

Im curious what the exact meaning of "committed" memory is when the value is queried from the MemoryUsage class. That class explains it as "committed represents the amount of memory (in bytes) that is guaranteed to be available for use by the Java virtual machine." Does this mean that the memory is in use by the jvm process and NOT available to other processes until it is released by the java process, or does it mean that the java process will be successful if it tries to allocate up to that amount of memory? I realize this might be implementation specific but i am only interested in hotspot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

江湖彼岸 2024-07-14 13:06:31

提交的大小是实际分配的内存,使用的大小是用于存储实际数据的大小(当使用〜=提交时,是主要GC的时间,并且可能会增加堆)。 最大大小是堆可以增长的硬限制 - 如果不够,JVM 会抛出 OutOfMemoryError。

如果内存被提交,那么它肯定可以被使用。 此外,JVM 无法提交更多内存(在现代操作系统上)的唯一情况是硬件虚拟内存不足。

所有这些大小仅告诉您堆区域的大小。 JVM 还有其他内存区域(线程堆栈、JIT 缓存等)。堆区域通常是最大的,这大致对应于进程占用空间。

两个注意事项:

  • 如果提交的大小不适合物理内存,则部分大小将被交换到页面文件。 这会导致 GC 期间速度大幅减慢,在这种情况下,您可以通过减小堆大小来提高应用程序性能。
  • 某些操作系统允许双重预订内存 - 只要您不尝试使用它,您就可以分配任意数量的内存(忘记了它是哪个操作系统 - 有人填写我)

The committed size is the actually allocated memory, the used size is the size used for storing actual data (when used ~= committed it's time for major GC and possibly growing the heap). The Max size is the hard limit to which the heap can grow - if it's not enough the JVM throws OutOfMemoryError.

If a memory is committed then it definitely can be used. Also, the only occasion when JVM would not be able to commit more memory (on a modern OS) is if the hardware is out of virtual memory.

All these sizes only tell you the size of the heap region. The JVM has other memory regions as well (thread stacks, JIT cache, etc.) The heap region is usually largest, this roughly corresponds to the process footprint.

Two notes:

  • if the committed size does not fit in the physical memory, parts of it will be swapped to the page file. This leads to big slowdown during GC and in such cases you will improve the app performance by reducing the heap size.
  • some operating systems allow double booking of memory - you can allocate as much as you want as long as you don't try to use it (forgot which OS it was - somebody fill me in)
凌乱心跳 2024-07-14 13:06:31

“这是否意味着内存正在被 jvm 进程使用,并且不可用于其他进程”是正确的。 因此它小于(或等于)操作系统认为 JVM 进程占用的内存量。

http://java.sun.com/j2se/ 1.5.0/docs/guide/management/jconsole.html(抱歉没有可链接的锚点)。

"Does this mean that the memory is in use by the jvm process and NOT available to other processes" would be the correct one. So its less then (or equal to) the amount of memory the OS sees as taken by the JVM process.

http://java.sun.com/j2se/1.5.0/docs/guide/management/jconsole.html (sorry no anchors to link to).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文