Java中已提交内存的确切状态 [英] Exact state of committed memory in java

查看:466
本文介绍了Java中已提交内存的确切状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇,当从MemoryUsage类中查询值时,已提交"内存的确切含义是什么.该类将其解释为已承诺表示保证Java虚拟机可以使用的内存量(以字节为单位)".这是否意味着该内存正在由jvm进程使用,并且在Java进程释放之前不可供其他进程使用,或者这意味着如果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.

推荐答案

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

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.

如果已提交内存,则肯定可以使用它.另外,JVM无法(在现代OS上)提交更多内存的唯一情况是硬件的虚拟内存不足.

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.

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

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.

两个注意事项:

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

这篇关于Java中已提交内存的确切状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆