java - 64位操作系统中Jvm从哪里获取堆内存?

标签 java memory memory-management heap-memory

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

我使用的是酷睿 i5 处理器 64 位 Windows 7 操作系统。 500 Gp 硬盘。仅 4GB 内存

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

  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
    
              `
    

最佳答案

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

您从程序中看到的输出与此完全一致。在程序运行时,堆还没有达到 139Gb。它可能永远达到那个水平。它甚至可能无法达到该级别……具体取决于操作系统在 JVM 需要时能够提供的资源。

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

关于java - 64位操作系统中Jvm从哪里获取堆内存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11946339/

相关文章:

PHP - 将字符串递归替换为数字需要很长时间

java - 示例案例的建议锁

java - 使用字符串与字节[]作为值,映射中的内存使用情况

c++ - 在 C++ 中访问数组的负索引处的内存不会返回垃圾

flash - 内存管理 Flash as3 for iphone and ipad dev

c++ - 如何正确实现 C++ 类析构函数

java - boolean containsAll(Collection<?> c) vs boolean addAll(Collection<? extends E> c); 的设计决策在集合框架中

java - 需要写一定的方法

java - Spring Autowiring 类与接口(interface)?

java - 为什么 Java 在我的 Linux 服务器上使用这么多内存?