简体   繁体   English

在 64 位操作系统中,Jvm 从何处获取堆内存?

[英]from where Jvm takes memory for Heap in 64 bit OS?

Am getting 104 Gp heap memory using command -Xms500m -Xmx139000m使用命令 -Xms500m -Xmx139000m 获得 104 Gp 堆内存

Am usig core i5 processor 64 bit Windows 7 Os.我使用了核心 i5 处理器 64 位 Windows 7 操作系统。 500 Gp harddisk. 500 Gp 硬盘。 4GB RAM Only仅 4GB 内存

  1. I Just want to know from where Jvm takes memory of 104 GB(heap) ?我只想知道 JVM 从哪里获取 104 GB(堆)的内存?

  2. In the output no memmory usage is displayed?在输出中没有显示内存使用情况?

     `public class CPUusage { public static void main(String[] args)throws Exception { int mb = 1024*1024; int GB = 1024*1024*1024; /* Total number of processors or cores available to the JVM */ System.out.println("Available processors (cores): " + Runtime.getRuntime().availableProcessors()); /* Total amount of free memory available to the JVM */ System.out.println("Free memory (MB): " + Runtime.getRuntime().freeMemory()/mb); /* This will return Long.MAX_VALUE if there is no preset limit */ long maxMemory = Runtime.getRuntime().maxMemory()/GB; /* Maximum amount of memory the JVM will attempt to use */ System.out.println("Maximum memory (GB): " + maxMemory); /* Total memory currently in use by the JVM */ System.out.println("Total memory (MB): " + Runtime.getRuntime().totalMemory()/mb); /* Get a list of all filesystem roots on this system */ File log=new File("D:\\\\log.txt"); log.createNewFile(); FileWriter fstream = new FileWriter(log); BufferedWriter out = new BufferedWriter(fstream); out.write("--------------------------------------------"+"\\n\\n"); out.write("Available processors (cores): " + Runtime.getRuntime().availableProcessors()); out.newLine(); out.write("Free memory (MB): " + Runtime.getRuntime().freeMemory()/mb); out.newLine(); out.write("Maximum memory (MB): " + (maxMemory == Long.MAX_VALUE ? "no limit" : maxMemory)); out.newLine(); out.write("Total memory (MB): " + Runtime.getRuntime().totalMemory()/mb); out.newLine(); File[] roots = log.listRoots(); /* For each filesystem root, print some info */ for (File root : roots) { System.out.println("-------------------------------------------"); System.out.println("File system root: " + root.getAbsolutePath()); System.out.println("Total space (GB): " + root.getTotalSpace()/GB); System.out.println("Free space (GB): " + root.getFreeSpace()/GB); System.out.println("Usable space (GB): " + root.getUsableSpace()/GB); out.write("-------------------------------------------"); out.newLine(); out.write("File system root: " + root.getAbsolutePath()); out.newLine(); out.write("Total space (GB): " + root.getTotalSpace()/GB); out.newLine(); out.write("Free space (GB): " + root.getFreeSpace()/GB); out.newLine(); out.write("Usable space (GB): " + root.getUsableSpace()/GB); out.newLine(); } out.write("-------------------------------------------"); out.newLine(); out.close(); } } `

    And the output is输出是

     `Available processors (cores): 4 Free memory (MB): 476 Maximum memory (GB): 104 Total memory (MB): 479 ------------------------------------------- File system root: C:\\ Total space (GB): 97 Free space (GB): 70 Usable space (GB): 70 ------------------------------------------- File system root: D:\\ Total space (GB): 368 Free space (GB): 366 Usable space (GB): 366 `

The options "-Xms500m -Xmx139000m" mean "allocate an initial heap size of 500Mb, and let it grow to a maximum of 139GB ... if it needs to".选项“-Xms500m -Xmx139000m”表示“分配500Mb的初始堆大小,并让它增长到最大139GB......如果需要的话”。

The output you are seeing from your program is entirely consistent with that.您从程序中看到的输出与此完全一致。 At the point the program ran, the heap had not reached 139Gb.在程序运行时,堆还没有达到 139Gb。 And it might never reach that level.它可能永远不会达到那个水平。 And it may not even be able to reach that level ... depending on the resources that the operating system is able to give the JVM if / when it asks for them.它甚至可能无法达到那个水平……这取决于操作系统在/当它要求它们时能够为 JVM 提供的资源。

If you really want to force the JVM to use a 139Gb heap, you should try setting 139Gb as the initial heap size too;如果您真的想强制 JVM 使用 139Gb 堆,您也应该尝试将 139Gb 设置为初始堆大小; eg "-Xms139000m -Xmx139000m".例如“-Xms139000m -Xmx139000m”。 But that's probably not a good idea, especially if you don't have that much physical RAM.但这可能不是一个好主意,特别是如果您没有那么多物理 RAM。

Virtual memory means RAM is allocated on usage, not when the address space is reserved.虚拟内存意味着 RAM 是在使用时分配的,而不是在保留地址空间时分配。 If you actually use the 104GB, the OS will use swap (a file or partition on disk) to maintain the illusion of more RAM than you physically have.如果您实际使用 104GB,操作系统将使用交换(磁盘上的文件或分区)来维持 RAM 比您实际拥有的内存多的错觉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM