jdk的server模式修改无效(关于client和server模式)
本机为64位操作系统,64位jdk,win10。
修改C:\Program Files\Java\jre8\lib\amd64\jvm.cfg无效。
我的文件的内容为:
原因参考如下:
http://bluethinking.iteye.com/blog/2166857
http://ryxxlong.iteye.com/blog/1696537
两种模式下的堆大小:
http://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/parallel.html#sthref32
自己的渣渣水平翻译下:
Default Heap Size
Unless the initial and maximum heap sizes are specified on the command line, they are calculated based on the amount of memory on the machine.
默认堆大小是基于机器的内存,除非最小堆内存和最大堆内存容量在命令行被显式指定。
Client JVM Default Initial and Maximum Heap Sizes
The default maximum heap size is half of the physical memory up to a physical memory size of 192 megabytes (MB) and otherwise one fourth of the physical memory up to a physical memory size of 1 gigabyte (GB).
默认的最大堆内存大小是物理内存(最多达192M)的一半;如果内存大于或等于1GB,则取其1/4.
For example, if your computer has 128 MB of physical memory, then the maximum heap size is 64 MB, and greater than or equal to 1 GB of physical memory results in a maximum heap size of 256 MB.
举例,如果你的电脑有128M物理内存,那么最大堆大小是64M;如果物理内存大于等于1G,则最大堆大小是256M.
The maximum heap size is not actually used by the JVM unless your program creates enough objects to require it. A much smaller amount, called the initial heap size, is allocated during JVM initialization. This amount is at least 8 MB and otherwise 1/64th of physical memory up to a physical memory size of 1 GB.
最大堆大小不会被JVM实际使用,除非你的程序创建了足够多的对象去获取对应大小的内存。在JVM初始化时,最小堆内存容量的内存被分配。这个容量最小为8M,或者物理内存(最大1G)的64分之1。
The maximum amount of space allocated to the young generation is one third of the total heap size.
分配给新生代的最大容量为总堆内存的三分之一。
Server JVM Default Initial and Maximum Heap Sizes
The default initial and maximum heap sizes work similarly on the server JVM as it does on the client JVM, except that the default values can go higher. On 32-bit JVMs, the default maximum heap size can be up to 1 GB if there is 4 GB or more of physical memory. On 64-bit JVMs, the default maximum heap size can be up to 32 GB if there is 128 GB or more of physical memory. You can always set a higher or lower initial and maximum heap by specifying those values directly; see the next section.
默认的最小堆内存和最大堆内存容量在server模式的JVM和在client模式下类似,除了默认值更高。在32位的JVM上,如果机器有4GB以上的物理内存,默认的最大堆内存容量能够最大达到1GB。
在64位的JVM上,默认的最大堆大小能够达到32GB,如果有128GB以上的内存的话。
根据以上翻译,server模式下,如果电脑内存大于1GB,那么最大堆内存大小为机器内存的四分之1.
我本机验证了下,16GB内存大小,通过加-XX:+PrintFlagsFinal可以看到MaxHeapSize的值就是4G左右:
以下的语句也能证明这一点:
执行结果如下:max为3621M,和4G差得不算多。
那么,再验证一下最小堆大小容量:
268435456/(1024*1024) = 256M。
如果按照上面译文的算法,我本机16G内存的64分之一,为16G / 64 = 16 * 1024 / 64 M = 256M.