从哪里JVM在64位操作系统中获取内存堆?

问题描述:

我得到104 Gp堆内存使用命令-Xms500m -Xmx139000m从哪里JVM在64位操作系统中获取内存堆?

我usig核心i5处理器64位Windows 7操作系统。 500 Gp硬盘。 4GB RAM只有

  1. 我只想知道从哪里Jvm需要记忆104 GB(堆)?

  2. 在输出中没有显示内存使用情况?

      `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(); 
        } 
        } 
    
          ` 
    

    ,输出是

      `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 
    
          ` 
    
+0

请参阅http://*.com/questions/1463868/java-runtime-maxmemory-incorrect – 2012-08-14 05:52:51

虚拟存储装置的RAM使用情况分配的,而不是在地址空间被保留。如果你真的使用了104GB,操作系统将使用交换(磁盘上的文件或分区)来维持比实际拥有更多内存的错觉。

选项“-Xms500m -Xmx139000m”的意思是“分配一个500Mb的初始堆大小,并让它增长到最大139GB ......如果需要的话”。

您从程序中看到的输出与此完全一致。程序运行的时候,堆没有达到139Gb。它可能从来没有达到该级别。它甚至可能不是以达到该级别...取决于操作系统能够在请求它们时提供给JVM的资源。

如果你真的想强制JVM使用139Gb堆,你应该尝试设置139Gb作为初始堆大小;例如“-Xms139000m -Xmx139000m”。但这可能不是一个好主意,尤其是如果你没有那么多的物理内存。