-XX:MaxDirectMemorySize
最大堆外内存大小,此参数的含义是当Direct ByteBuffer分配的堆外内存到达指定大小后就触发Full GC
首先可以在jdk文档中找到:关于MaxDirectMemorySize内存的描述:
Sets the maximum total size (in bytes) of the New I/O (the java.nio package) direct-buffer allocations.

Append the letter k or K to indicate kilobytes, m or M to indicate megabytes, g or G to indicate gigabytes.

By default, the size is set to 0, meaning that the JVM chooses the size for NIO direct-buffer allocations automatically.

The following examples illustrate how to set the NIO size to 1024 KB in different units:
-XX:MaxDirectMemorySize=1m
-XX:MaxDirectMemorySize=1024k
-XX:MaxDirectMemorySize=1048576
参考
关于JDK8中最大堆外内存大小MaxDirectMemorySize

ByteBuffer(字节缓冲区)分类

heap ByteBuffer -> -XX:Xmx
一种是heap ByteBuffer,该类对象分配在JVM的堆内存里面,直接由Java虚拟机负责垃圾回收,
direct ByteBuffer -> -XX:MaxDirectMemorySize
一种是direct ByteBuffer是通过jni在虚拟机外内存中分配的。通过jmap无法查看该快内存的使用情况。只能通过top来看它的内存使用情况。
JVM堆内存大小可以通过-Xmx来设置
direct ByteBuffer可以通过-XX:MaxDirectMemorySize来设置
没有配置MaxDirectMemorySize的,默认MaxDirectMemorySize的大小即等于-Xmx
用JDK8的一定要配置:-Xms -Xmx -XX:MaxDirectMemorySize,【Xmx + MaxDirectMemorySize】的值不能超过docker的最大内存,不然docker内存占满了会被oomkill掉;
参考
JVM参数之MaxDirectMemorySize

启动VM options

-Xmx200m
-Xms50m
-XX:+PrintCommandLineFlags
--add-opens java.base/jdk.internal.misc=ALL-UNNAMED
--add-opens java.base/jdk.internal.access=ALL-UNNAMED

背景了解

// 提供对缓冲区使用情况信息的访问。
public interface BufferPool {String getName();long getCount();long getTotalCapacity();long getMemoryUsed();
}
// The management interface for a buffer pool
public interface BufferPoolMXBean extends PlatformManagedObject {
// The name of this buffer pool
String getName();   // An estimate of the number of buffers in this pool
long getCount();    // An estimate of the total capacity of the buffers in this pool in bytes
long getTotalCapacity(); // An estimate of the memory that the JVM is using for this buffer pool in bytes,
// or -1L if an estimate of the memory usage is not available
long getMemoryUsed();

练习代码

public class MaxDirectMemorySize {public static void main(String[] args) {printJVMRuntime();printDirectMemory();System.out.println("分配25M本地字节缓冲区 " + ByteBuffer.allocateDirect(25 * 1024 * 1024));System.out.println("创建10M对象 " + new byte[10 * 1024 * 1024]);printJVMRuntime();printDirectMemory();System.out.println("分配25M本地字节缓冲区 " + ByteBuffer.allocateDirect(25 * 1024 * 1024));System.out.println("创建10M对象 " + new byte[10 * 1024 * 1024]);printJVMRuntime();printDirectMemory();}private static void printJVMRuntime() {System.out.println("java虚拟机从操纵系统那里挖到的最大的内存   maxMemory " + Runtime.getRuntime().maxMemory() / 1024 / 1024 + "M");System.out.println("java虚拟机已经从操作系统那里挖过来的内存   totalMemory : " + Runtime.getRuntime().totalMemory() / 1024 / 1024 + "M");System.out.println("java虚拟机从操纵系统挖过来还没用上的内存   freeMemory : " + Runtime.getRuntime().freeMemory() / 1024 / 1024 + "M");}private static void printDirectMemory() {System.out.println("the maximum allocatable direct buffer memory: " + VM.maxDirectMemory() / 1024 / 1024 + "M");System.out.println("BufferPoolMXBean.Name: " + getDirectBufferPoolMBean().getName());System.out.println("BufferPoolMXBean.Count: " + getDirectBufferPoolMBean().getCount());System.out.println("BufferPoolMXBean.TotalCapacity: " + getDirectBufferPoolMBean().getTotalCapacity() / 1024 / 1024 + "M");System.out.println("BufferPoolMXBean.MemoryUsed: " + getDirectBufferPoolMBean().getMemoryUsed() / 1024 / 1024 + "M");System.out.println("BufferPool.Name: " + getNioBufferPool().getName());System.out.println("BufferPool.Count: " + getNioBufferPool().getCount());System.out.println("BufferPool.TotalCapacity: " + getNioBufferPool().getTotalCapacity() / 1024 / 1024 + "M");System.out.println("BufferPool.MemoryUsed: " + getNioBufferPool().getMemoryUsed() / 1024 / 1024 + "M");}public static BufferPoolMXBean getDirectBufferPoolMBean() {return ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class).stream().filter(e -> e.getName().equals("direct")).findFirst().orElseThrow();}public static VM.BufferPool getNioBufferPool() {return SharedSecrets.getJavaNioAccess().getDirectBufferPool();}
}

结果分析

-XX:ConcGCThreads=3 -XX:G1ConcRefinementThreads=13 -XX:GCDrainStackTargetSize=64 -XX:InitialHeapSize=52428800 -XX:MarkStackSize=4194304 -XX:MaxHeapSize=209715200 -XX:MinHeapSize=52428800 -XX:+PrintCommandLineFlags -XX:ReservedCodeCacheSize=251658240 -XX:+SegmentedCodeCache -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseG1GC -XX:-UseLargePagesIndividualAllocation
java虚拟机从操纵系统那里挖到的最大的内存   maxMemory 200M
java虚拟机已经从操作系统那里挖过来的内存   totalMemory : 50M
java虚拟机从操纵系统挖过来还没用上的内存   freeMemory : 45Mthe maximum allocatable direct buffer memory: 200MBufferPoolMXBean.Name: direct
BufferPoolMXBean.Count: 1
BufferPoolMXBean.TotalCapacity: 0M
BufferPoolMXBean.MemoryUsed: 0MBufferPool.Name: direct
BufferPool.Count: 1
BufferPool.TotalCapacity: 0M
BufferPool.MemoryUsed: 0M分配25M本地字节缓冲区 java.nio.DirectByteBuffer[pos=0 lim=26214400 cap=26214400]
创建10M对象 [B@5f4da5c3java虚拟机从操纵系统那里挖到的最大的内存   maxMemory 200M
java虚拟机已经从操作系统那里挖过来的内存   totalMemory : 50M
java虚拟机从操纵系统挖过来还没用上的内存   freeMemory : 33Mthe maximum allocatable direct buffer memory: 200MBufferPoolMXBean.Name: direct
BufferPoolMXBean.Count: 2
BufferPoolMXBean.TotalCapacity: 25M
BufferPoolMXBean.MemoryUsed: 25MBufferPool.Name: direct
BufferPool.Count: 2
BufferPool.TotalCapacity: 25M
BufferPool.MemoryUsed: 25M分配25M本地字节缓冲区 java.nio.DirectByteBuffer[pos=0 lim=26214400 cap=26214400]
创建10M对象 [B@443b7951java虚拟机从操纵系统那里挖到的最大的内存   maxMemory 200M
java虚拟机已经从操作系统那里挖过来的内存   totalMemory : 50M
java虚拟机从操纵系统挖过来还没用上的内存   freeMemory : 22Mthe maximum allocatable direct buffer memory: 200MBufferPoolMXBean.Name: direct
BufferPoolMXBean.Count: 3
BufferPoolMXBean.TotalCapacity: 50M
BufferPoolMXBean.MemoryUsed: 50MBufferPool.Name: direct
BufferPool.Count: 3
BufferPool.TotalCapacity: 50M
BufferPool.MemoryUsed: 50M

-XX:MaxDirectMemorySize相关推荐

  1. 聊聊jvm的-XX:MaxDirectMemorySize

    序 本文主要研究一下jvm的-XX:MaxDirectMemorySize -XX:MaxDirectMemorySize -XX:MaxDirectMemorySize=size用于设置New I/ ...

  2. -XX:MaxDirectMemorySize直接内存无效问题

    直接内存 直接内存并不是虚拟机运行时数据区的一部分,也不是Java虚拟机规范中定义的内存区域,但是这部分内存也被频繁地使用,而且也可能导致OutOfMemoryError异常出现. 在JDK 1.4中 ...

  3. JVM -XX:MaxDirectMemorySize

    -XX:MaxDirectMemorySize 该参数指定了DirectByteBuffer能分配的空间的限额,如果没有显示指定这个参数启动jvm,默认值是xmx对应的值. DirectByteBuf ...

  4. [JVM]了断局: 堆外内存无法 [ -XX:MaxDirectMemorySize ] 限制

    一. 前言 今天看到一句话 , 有点懵, 所以验证一下. 使用sun.misc.Unsafe的allocateMemory方法分配堆外内存.不受-XX:MaxDirectMemorySize这个JVM ...

  5. JVM参数-XX:+HeapDumpOnOutOfMemoryError使用方法

    1.配置方法 在JAVA_OPTIONS变量中增加 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${目录}. 例如:export JAVA_OPT ...

  6. Warning: Failed to parse host xx.xx.com

    报错:Warning: Failed to parse host xx.xx.com 分析:Android Studio设置了代理,但是无法连接导致报错 解决: 1.File-->Setting ...

  7. Nexus3.x安装

    Nexus3.x安装 1.为什么使用Nexus 如果没有私服,我们所需要的所有构建都需要通过maven的中央仓库和第三方的Maven仓库下载到本地,而一个团队中的所有人都从夫的从maven仓库下载构建 ...

  8. jvm 堆外内存_NIO效率高的原理之零拷贝与直接内存映射

    更多内容,欢迎关注微信公众号:全菜工程师小辉~ 前言 在笔者上一篇博客,详解了NIO,并总结NIO相比BIO的效率要高的三个原因,彻底搞懂NIO效率高的原理. 这篇博客将针对第三个原因,进行更详细的讲 ...

  9. 从内存溢出看Java 环境中的内存结构

    作为有个java程序员,我想大家对下面出现的这几个场景并不陌生,倍感亲切,深恶痛绝,抓心挠肝,一定会回过头来问为什么为什么为什么会这样,嘿嘿,让我们看一下我们日常在开发过程中接触内存溢出的异常: Ex ...

最新文章

  1. 清空表中数据 id从1开始
  2. python 怎么在一行获取多个数字
  3. TF实战:(Mask R-CNN原理介绍与代码实现)-Chapter-8
  4. 树莓派安装vnc server并设置自启动
  5. 计算机算法在生物信息学中的应用,计算机算法在生物信息学中的应用综述.doc...
  6. 拼接的option会多出空行_Word空格,空行,页眉横线等问题,我只花一分钟就全解决了...
  7. Yii 2.0 GII 访问404错误
  8. mysql5.6.4m7 linux安装_mysql-5.6.4-m7installinlinux
  9. 储存profiles是什么意思_Powershell Profiles配置文件的存放位置介绍
  10. css 类别选择器 并集,CSS常用选择器
  11. 小学教育专业有计算机课程吗,小学计算机课程教学工作总结
  12. Pro Tools系统优化- Windows篇
  13. 个性推荐①——系统总结个性化推荐系统
  14. 写出linux命令的功能,练习一LINUX命令测试题1
  15. BlenderGIS插件 城市建筑3D模型自动生成 教程
  16. python语法报错_1、Python语法及报错总结 - 随笔分类 - 走路带风的帅界扛把子 - 博客园...
  17. [Android1.5]标签TabHost图片文字覆盖的问题
  18. 使用MultipartFile+ElementUi(el-upload)实现前端向后端传图片
  19. 飞飞php影视系统漏洞,飞飞影视系统PHP版 v1.9 injection exploit漏洞预警 -电脑资料...
  20. STM32F103芯片FSMC使用外扩SRAM芯片

热门文章

  1. 青少年计算机表演赛27,第27届中国青少年计算机表演赛颁奖仪式在京举行
  2. php5的魔术方法,php5中魔术方法学习笔记
  3. vs2017配置opencv详细教程
  4. 防夹天窗/ 车窗控制单元
  5. 国家天地图API 循环添加点 参数传递问题
  6. 微信小程序 |从零实现酷炫纸质翻页效果
  7. 小程序wx.chooseImage和wx.chooseVideo 上传多张图片和视频
  8. Java面试题集锦 (一)
  9. 常见文件对应的MIMEType类型
  10. php镜像同步,php – 我可以使用我自己的Composer Satis安装来同步或者从packagist.org镜像依赖关系吗?...