Java8 及以上版本,您可以使用以下命令:
jcmdJAVA_PROCESS_IDGC.heap_info
您可以参考输出中的总内存、总内存和已用内存。
Sample Command And Output: jcmd 9758 GC.heap_info
PSYoungGen total 1579520K, used 487543K [0x0000000751d80000, 0x00000007c0000000, 0x00000007c0000000)
eden space 1354240K, 36% used [0x0000000751d80000,0x000000076f99dc40,0x00000007a4800000)
from space 225280K, 0% used [0x00000007b2400000,0x00000007b2400000,0x00000007c0000000)
to space 225280K, 0% used [0x00000007a4800000,0x00000007a4800000,0x00000007b2400000)
ParOldGen total 3610112K, used 0K [0x0000000675800000, 0x0000000751d80000, 0x0000000751d80000)
object space 3610112K, 0% used [0x0000000675800000,0x0000000675800000,0x0000000751d80000)
Metaspace used 16292K, capacity 16582K, committed 16896K, reserved 1064960K
class space used 1823K, capacity 1936K, committed 2048K, reserved 1048576K
更多 jcmd 命令详情,请访问链接here