最近在调整程序的堆大小设置,就顺便看了开发环境中如何设置的。发现开发环境没有主动设置大小,那就应该是根据机器配置和操作系统以及JDK版本等信息使用了默认配置。

查询 PrintFlagsFinal

关于查询命令,请参考官方文档:
-XX:+PrintFlagsFinal which outputs the values of all of the jvm configuration parameters and/or values

个人笔记本上:Windows10 ,JDK 64-Bit Server VM (build 25.191-b12) 物理内存16G

C:\Users\Lenovo>java -XX:+PrintFlagsFinal -version |findstr /i "HeapSize  PerSize ThreadStackSize"intx CompilerThreadStackSize                   = 0                                   {pd product}uintx ErgoHeapSizeLimit                         = 0                                   {product}uintx HeapSizePerGCThread                       = 87241520                            {product}uintx InitialHeapSize                          := 266338304                           {product}uintx LargePageHeapSizeThreshold                = 134217728                           {product}uintx MaxHeapSize                              := 4253024256                          {product}intx ThreadStackSize                           = 0                                   {pd product}
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)intx VMThreadStackSize                         = 0                                   {pd product}

也就是在我的笔记本上默认的MaxHeapSize 是4253024256/1024/1024/1024=3.96G., 初始堆大小是InitialHeapSize 266338304 /1024/1024=254M.

使用-XX:+PrintCommandLineFlags

关于PringCommandLineFlags的解释,请参考https://docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html#BABHDABI

-XX:+PrintCommandLineFlagsEnables printing of ergonomically selected JVM flags that appeared on the command line. It can be useful to know the ergonomic values set by the JVM, such as the heap space size and the selected garbage collector. By default, this option is disabled and flags are not printed.

执行结果如下:

C:\Users\Lenovo>java -XX:+PrintCommandLineFlags -version
-XX:InitialHeapSize=265755648 -XX:MaxHeapSize=4252090368 -XX:+PrintCommandLineFlags -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)

可以看出-XX:+PrintCommandLineFlags与-XX:+PrintFlagsFinal结果一样MaxHeapSize=4253024256基本一致(暂未找到差异觉具体解释)

使用java -XshowSettings:all

可以发现>java -XshowSettings:all现实的最大内存与PrintFlagsFinal现实的有所差异。(暂未找到具体解释)

C:\Users\Lenovo>java -XshowSettings:all
VM settings:Max. Heap Size (Estimated): 3.52GErgonomics Machine Class: clientUsing VM: Java HotSpot(TM) 64-Bit Server VMProperty settings:awt.toolkit = sun.awt.windows.WToolkitfile.encoding = GBK。。。

Unix上执行
java -XX:+PrintFlagsFinal -version | grep -iE ‘HeapSize|PermSize|ThreadStackSize’

官方文档

https://docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html

截图其中的

-Xmssize  (设置堆的初始大小)Sets the initial size (in bytes) of the heap. This value must be a multiple of 1024 and greater than 1 MB. Append the letter k or K to indicate kilobytes, m or M to indicate megabytes, g or G to indicate gigabytes.The following examples show how to set the size of allocated memory to 6 MB using various units:-Xms6291456-Xms6144k-Xms6mIf you do not set this option, then the initial size will be set as the sum of the sizes allocated for the old generation and the young generation. The initial size of the heap for the young generation can be set using the -Xmn option or the -XX:NewSize option.
-Xmxsize  (设置堆的最大大小)Specifies the maximum size (in bytes) of the memory allocation pool in bytes. This value must be a multiple of 1024 and greater than 2 MB. Append the letter k or K to indicate kilobytes, m or M to indicate megabytes, g or G to indicate gigabytes. The default value is chosen at runtime based on system configuration. **For server deployments, -Xms and -Xmx are often set to the same value**(对于服务部署,通常-Xms和-Xmx设置的大小一样). See the section "Ergonomics" in Java SE HotSpot Virtual Machine Garbage Collection Tuning Guide at http://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/index.html.The following examples show how to set the maximum allowed size of allocated memory to 80 MB using various units:-Xmx83886080-Xmx81920k-Xmx80mThe -Xmx option is equivalent to -XX:MaxHeapSizeInitial Heap Size and Maximum Heap Size Changed for Parallel Garbage Collector
On server-class machines running either VM (client or server) with the parallel garbage collector (-XX:+UseParallelGC) the initial heap size and maximum heap size have changed as follows.initial heap size(默认初始大小, 物理内存的64分之一,或者合理的最小值。 我的机器物理内存是16G, 因此默认就是0.25G, 也就是256M)
Larger of 1/64th of the machine's physical memory on the machine or some reasonable minimum. Before Java SE 5.0, the default initial heap size was a reasonable minimum, which varies by platform. You can override this default using the -Xms command-line option.maximum heap size(默认最大堆, 物理内存的四分之一,或者1G。 我机器物理内存16G, 默认最大值就是4G)
Smaller of 1/4th of the physical memory or 1GB. Before Java SE 5.0, the default maximum heap size was 64MB. You can override this default using the -Xmx command-line option.Note: The boundaries and fractions given for the heap size are correct for Java SE 5.0. They are likely to be different in subsequent releases as computers get more powerful.

官方文档连接 https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gc-ergonomics.html

Java 堆默认大小相关推荐

  1. 从Java代码到Java堆理解和优化您的应用程序的内存使用

    从Java代码到Java堆理解和优化您的应用程序的内存使用 简介: 本文将为您提供 Java? 代码内存使用情况的深入见解,包括将 int 值置入一个Integer 对象的内存开销.对象委托的成本和不 ...

  2. Java堆和栈的基本理解

    Java 堆和栈的区别 参考背景: 堆内存:用来存放由new创建的对象和数组: 栈内存:存放基本类型的变量,对象的引用变量: 堆存放的原因:由于在堆中创建对象(或数组)后,可在栈中定义一个特殊变量,让 ...

  3. Java堆内存分配与回收策略

    java主要在堆上分配内存,而Java堆又分为新生代(YoungGen)和老年代(OldGen)两个部分,新生代又再分为Eden区和Survivor区两部分,本文根据java堆的划分,描述hotspo ...

  4. sample java_从sample来学习Java堆(转)

    1)Java堆 所有对象的实例分配都在Java堆上分配内存,堆大小由-Xmx和-Xms来调节,sample如下所示: public class HeapOOM { static class OOMOb ...

  5. java堆算法,Java 基本功04-JVM-Java堆详解和GC算法

    JVM GC 机制 1. 在此之前需要了解相关概念: 1.1 Java 堆内存: 在 HotSpot JVM 实现中 Heap 内存被"分代"管理. JVM 的内存首先被分割成两部 ...

  6. 稀有名词解释——Java 堆污染(犄角旮旯问题)

    稀有名词解释--Java 堆污染(犄角旮旯问题) 有些面试官喜欢问一些稀有名词,彰显其渊博的知识背景. 所谓堆污染,简单的说就是当一个泛型类型变量赋值给不是泛型类型变量,这种错误在编译期间能被编译器警 ...

  7. Java 技术篇-用java自带的内存检测工具排查内存泄漏问题,查看java垃圾回收情况,监控java堆内存变化

    在 java 的 bin 文件夹下有个 jvisualvm.exe 工具,使用它可以检测到 java堆内存 的变化情况,借此可以来检测使用 java 的程序是否存在内存泄漏问题. 我们左边选择程序对应 ...

  8. Java堆内存是线程共享的!面试官:你确定吗?

    作者 l Hollis 来源 l Hollis(ID:hollischuang) Java作为一种面向对象的,跨平台语言,其对象.内存等一直是比较难的知识点,所以,即使是一个Java的初学者,也一定或 ...

  9. 哪个更快:Java 堆还是本地内存

    使用Java的一个好处就是你可以不用亲自来管理内存的分配和释放.当你用new关键字来实例化一个对象时,它所需的内存会自动的在Java堆中分配.堆会被垃圾回收器进行管理,并且它会在对象超出作用域时进行内 ...

最新文章

  1. 灰度图像--图像分割 Scharr算子
  2. 初探JavaScript(一)——也谈元素节点、属性节点、文本节点
  3. Go语言基础:method
  4. Centos网络驱动
  5. java web 文件上传工具类_JavaWeb中实现文件上传的方式有哪些?
  6. 疑似谷歌Pixel 4真机谍照曝光:边框宽到没朋友
  7. anguar4 共享服务在多个组件中数据通信
  8. 寻找指定型别的父控件
  9. win7便签的cheat sheet
  10. IDEA2020版本下载、安装
  11. 如何把密度函数化为标准正态二维分布_数理统计第四讲(次序统计量续,伽马分布)...
  12. 计算机考试用户没有注册类,电脑中出现没有注册类别的错误提示怎么解决
  13. a标签href的几种写法
  14. 基于vue3+ts+scss的后台管理系统(二)----excel的导入导出
  15. 网上订鲜花怎么配送?鲜花配送为何首选顺丰同城急送?
  16. asp.net 获取汉字字符串的拼音首字母,含多音字
  17. 汽车功能安全ISO 26262介绍
  18. java外加IJ-idea的初次学习
  19. 【深度学习】1-权重参数全相同值初始化,导致无法训练-python
  20. Rollup【ESM打包工具】

热门文章

  1. Centos7 Yum安装MYSQL8.0详细安装步骤
  2. dBm与W换算)手机信号放大器功率单位
  3. 接口练习(台灯案例)
  4. 微信小程序调用指纹验证
  5. CodeWarrior相关概述
  6. MySQL数据库表结构的设计
  7. Pandas中to_excel实现数据追加或者覆盖到Excel工作表
  8. CentOS版本的Linux的安装
  9. MySQL的几种join方法
  10. Linux下的文件管理(初学者必看)