XX 的默认值:MaxDirectMemorySize

发布于 2024-09-24 05:34:34 字数 38 浏览 1 评论 0原文

XX:MaxDirectMemorySize 的默认值是多少?

What is the default value for XX:MaxDirectMemorySize?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

紫南 2024-10-01 05:34:34

来自 sun.misc.VM,它是Runtime.getRuntime.maxMemory(),这就是用-Xmx配置的。例如如果您没有配置-XX:MaxDirectMemorySize并且配置-Xmx5g,则“默认”>MaxDirectMemorySize 也将为 5 Gb,应用程序的总堆+直接内存使用量可能会增长到 5 + 5 = 10 Gb。

From sun.misc.VM, it's Runtime.getRuntime.maxMemory(), that's what is configured with -Xmx. E. g. if you don't configure -XX:MaxDirectMemorySize and do configure -Xmx5g, the "default" MaxDirectMemorySize will also be 5 Gb, and the total heap+direct memory usage of the app may grow up to 5 + 5 = 10 Gb.

瑶笙 2024-10-01 05:34:34

来自 http://www.docjar.com/html/api/ sun/misc/VM.java.html

我明白了:

 163       // A user-settable upper limit on the maximum amount of allocatable direct
 164       // buffer memory.  This value may be changed during VM initialization if
 165       // "java" is launched with "-XX:MaxDirectMemorySize=<size>".
 166       //
 167       // The initial value of this field is arbitrary; during JRE initialization
 168       // it will be reset to the value specified on the command line, if any,
 169       // otherwise to Runtime.getRuntime.maxDirectMemory().
 170       //
 171       private static long directMemory = 64 * 1024 * 1024;

所以它似乎默认为 64 兆。

From http://www.docjar.com/html/api/sun/misc/VM.java.html

i see:

 163       // A user-settable upper limit on the maximum amount of allocatable direct
 164       // buffer memory.  This value may be changed during VM initialization if
 165       // "java" is launched with "-XX:MaxDirectMemorySize=<size>".
 166       //
 167       // The initial value of this field is arbitrary; during JRE initialization
 168       // it will be reset to the value specified on the command line, if any,
 169       // otherwise to Runtime.getRuntime.maxDirectMemory().
 170       //
 171       private static long directMemory = 64 * 1024 * 1024;

so it appears to default to 64 megs.

强辩 2024-10-01 05:34:34

对于JDK8:

64MB最初是任意设置的,...

(来自:https://github.com/frohoff/jdk8u-dev-jdk/blob/master/src/share/classes/sun/misc/VM.java#L186 )

    // A user-settable upper limit on the maximum amount of allocatable direct
    // buffer memory.  This value may be changed during VM initialization if
    // "java" is launched with "-XX:MaxDirectMemorySize=<size>".
    //
    // The initial value of this field is arbitrary; during JRE initialization
    // it will be reset to the value specified on the command line, if any,
    // otherwise to Runtime.getRuntime().maxMemory().
    //
    private static long directMemory = 64 * 1024 * 1024;

...但是然后 directMemory 设置为 maxMemory() ~= Heapsize (如果未设置 maxDirectMemorySize-Parameter):

(来自: https://github.com/frohoff/jdk8u-dev-jdk/blob/master /src/share/classes/sun/misc/VM.java#L286

  // Set the maximum amount of direct memory.  This value is controlled
  // by the vm option -XX:MaxDirectMemorySize=<size>.
  // The maximum amount of allocatable direct buffer memory (in bytes)
  // from the system property sun.nio.MaxDirectMemorySize set by the VM.
  // The system property will be removed.
  String s = (String)props.remove("sun.nio.MaxDirectMemorySize");
  if (s != null) {
      if (s.equals("-1")) {
         // -XX:MaxDirectMemorySize not given, take default
          directMemory = Runtime.getRuntime().maxMemory();
      } else {
         long l = Long.parseLong(s);
          if (l > -1)
              directMemory = l;
      }
  }

测试似乎支持这种说法,
“test.java.nio.Buffer.LimitDirectMemory.java”:(

来自 https://github.com/frohoff/jdk8u-dev-jdk/blob/da0da73ab82ed714dc5be94acd2f0d00fbdfe2e9/test/java/nio/Buffer/LimitDirectMemory.java#L74)

 if (size.equals("DEFAULT"))
            return (int)Runtime.getRuntime().maxMemory();

For JDK8:

The 64MB are set arbitrarily initially, ...

(From: https://github.com/frohoff/jdk8u-dev-jdk/blob/master/src/share/classes/sun/misc/VM.java#L186 )

    // A user-settable upper limit on the maximum amount of allocatable direct
    // buffer memory.  This value may be changed during VM initialization if
    // "java" is launched with "-XX:MaxDirectMemorySize=<size>".
    //
    // The initial value of this field is arbitrary; during JRE initialization
    // it will be reset to the value specified on the command line, if any,
    // otherwise to Runtime.getRuntime().maxMemory().
    //
    private static long directMemory = 64 * 1024 * 1024;

... but then the directMemory is set to maxMemory() ~= Heapsize here (if the maxDirectMemorySize-Parameter is not set):

(from: https://github.com/frohoff/jdk8u-dev-jdk/blob/master/src/share/classes/sun/misc/VM.java#L286 )

  // Set the maximum amount of direct memory.  This value is controlled
  // by the vm option -XX:MaxDirectMemorySize=<size>.
  // The maximum amount of allocatable direct buffer memory (in bytes)
  // from the system property sun.nio.MaxDirectMemorySize set by the VM.
  // The system property will be removed.
  String s = (String)props.remove("sun.nio.MaxDirectMemorySize");
  if (s != null) {
      if (s.equals("-1")) {
         // -XX:MaxDirectMemorySize not given, take default
          directMemory = Runtime.getRuntime().maxMemory();
      } else {
         long l = Long.parseLong(s);
          if (l > -1)
              directMemory = l;
      }
  }

The test seems to support this claim,
"test.java.nio.Buffer.LimitDirectMemory.java":

(from https://github.com/frohoff/jdk8u-dev-jdk/blob/da0da73ab82ed714dc5be94acd2f0d00fbdfe2e9/test/java/nio/Buffer/LimitDirectMemory.java#L74)

 if (size.equals("DEFAULT"))
            return (int)Runtime.getRuntime().maxMemory();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文