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

Java Jvm从何处获取64位操作系统中堆的内存?,java,memory,memory-management,heap,Java,Memory,Memory Management,Heap,使用命令-Xms500m-Xmx139000m获取104 Gp堆内存 Am使用core i5处理器64位Windows 7操作系统。500 Gp硬盘。仅4GB内存 我只是想知道Jvm从哪里获取104 GB的内存(堆) 在输出中未显示内存使用情况 `public class CPUusage { public static void main(String[] args)throws Exception { int mb = 1024*1024; int GB

使用命令-Xms500m-Xmx139000m获取104 Gp堆内存

Am使用core i5处理器64位Windows 7操作系统。500 Gp硬盘。仅4GB内存

  • 我只是想知道Jvm从哪里获取104 GB的内存(堆)

  • 在输出中未显示内存使用情况

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

  • 虚拟内存意味着RAM是根据使用情况分配的,而不是在保留地址空间时分配的。如果您实际使用104GB,操作系统将使用交换(磁盘上的一个文件或分区)来保持内存比实际内存多的假象。

    虚拟内存意味着在使用时分配内存,而不是在保留地址空间时。如果您实际使用104GB,操作系统将使用交换(磁盘上的一个文件或分区)来保持内存比您实际拥有的内存更多的假象。

    选项“-Xms500m-Xmx139000m”意味着“分配500Mb的初始堆大小,并让它增长到最大139GB…如果需要的话”

    您从程序中看到的输出与此完全一致。在程序运行时,堆还没有达到139Gb。而且可能永远也达不到这个水平。它甚至可能无法达到那个水平。。。取决于操作系统在JVM请求时能够提供的资源

    如果您真的想强制JVM使用139Gb堆,那么您也应该尝试将139Gb设置为初始堆大小;e、 g.“-Xms139000m-Xmx139000m”。但这可能不是一个好主意,尤其是在没有那么多物理RAM的情况下。

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

    您从程序中看到的输出与此完全一致。在程序运行时,堆还没有达到139Gb。而且可能永远也达不到这个水平。它甚至可能无法达到那个水平。。。取决于操作系统在JVM请求时能够提供的资源

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

    请参阅