查看堆外内存


文章目录

    • 一次生产环境高内存
    • 查看堆外内存
    • 阿尔萨斯
        • 安装使用
    • greys
      • 安装使用
      • 其他命令
    • perf-tools
    • 堆外内存

一次生产环境高内存 sudo -u admin /java/bin/jmap -histo:live 37 | head -10 | sort -r -k3
查看堆外内存
文章图片

jmap -heap pid
查看堆外内存
文章图片

top
查看堆外内存
文章图片

查看堆外内存
  1. 推荐java visualVM ,安装Buffer Pools来监测
@Test public void test() throws Exception{ while(true) { ByteBuffer byteBuffer = ByteBuffer.allocateDirect(1024 * 1024 * 1); } }

禁用System.gc,直接OOM
-verbose:gc -XX:+PrintGCDetails -XX:MaxDirectMemorySize=50m -XX:+DisableExplicitGC

查看堆外内存
文章图片

开启-XX:+ExplicitGCInvokesConcurrent,允许System.gc生效
【查看堆外内存】查看堆外内存
文章图片

  1. sa-jdi.jar
    java -classpath .\sa-jdi.jar sun.jvm.hotspot.HSDB 图形界面 windows无法连接pid
阿尔萨斯 jvm
查看堆外内存
文章图片

手动触发full gc,( sudo -u admin /bin/jmap -histo:live 38 |head -10 )之后
查看堆外内存
文章图片

dashboard
direct 显示40m
查看堆外内存
文章图片

thread
finalizer 8
gc 2
查看堆外内存
文章图片

安装使用
curl -L https://alibaba.github.io/arthas/install.sh | sh yum install xinetd telnet telnet-server -y sudo -u admin -EH ./as.sh

greys 安装使用
wget -c http://ompc.oss.aliyuncs.com/greys/release/greys-1.7.6.4-bin.zip
unzip
cd greys
sh ./install-local.sh 安装
开启端口
sudo -u admin ./ga.sh 33
查看堆外内存
文章图片

./greys.sh 开启命令行模式
查看堆外内存
文章图片

输入jvm查看内存情况
查看堆外内存
文章图片

totalusedfreesharedbuff/cacheavailable Mem:15G8.8G6.0G1.0M700M6.4G Swap:0B0B0B

查看堆外内存
文章图片

https://www.jianshu.com/p/c76747997ade
https://www.jianshu.com/p/4e96beb37935
其他命令
quit 退出
shutdown 关闭
perf-tools /home/admin/busuac/gref/lib
export LD_PRELOAD=/home/admin/busuac/gperf/lib/libtcmalloc.so
export HEAPPROFILE=/home/admin/busuac
./configure --prefix=安装目录
/home/admin/busuac/gperf/lib
堆外内存 查看堆外内存
文章图片

画重点
private static long maxDirectMemory0() { long maxDirectMemory = 0; try { // Try to get from sun.misc.VM.maxDirectMemory() which should be most accurate. Class vmClass = Class.forName("sun.misc.VM", true, getSystemClassLoader()); Method m = vmClass.getDeclaredMethod("maxDirectMemory"); maxDirectMemory = ((Number) m.invoke(null)).longValue(); } catch (Throwable ignored) { // Ignore }if (maxDirectMemory > 0) { return maxDirectMemory; }try { // Now try to get the JVM option (-XX:MaxDirectMemorySize) and parse it. // Note that we are using reflection because Android doesn't have these classes. Class mgmtFactoryClass = Class.forName( "java.lang.management.ManagementFactory", true, getSystemClassLoader()); Class runtimeClass = Class.forName( "java.lang.management.RuntimeMXBean", true, getSystemClassLoader()); Object runtime = mgmtFactoryClass.getDeclaredMethod("getRuntimeMXBean").invoke(null); @SuppressWarnings("unchecked") List> vmArgs = (List>) runtimeClass.getDeclaredMethod("getInputArguments").invoke(runtime); for (int i = vmArgs.size() - 1; i >= 0; i --) { Matcher m = MAX_DIRECT_MEMORY_SIZE_ARG_PATTERN.matcher(vmArgs.get(i)); if (!m.matches()) { continue; }maxDirectMemory = Long.parseLong(m.group(1)); switch (m.group(2).charAt(0)) { case 'k': case 'K': maxDirectMemory *= 1024; break; case 'm': case 'M': maxDirectMemory *= 1024 * 1024; break; case 'g': case 'G': maxDirectMemory *= 1024 * 1024 * 1024; break; } break; } } catch (Throwable ignored) { // Ignore }if (maxDirectMemory <= 0) { maxDirectMemory = Runtime.getRuntime().maxMemory(); logger.debug("maxDirectMemory: {} bytes (maybe)", maxDirectMemory); } else { logger.debug("maxDirectMemory: {} bytes", maxDirectMemory); }return maxDirectMemory; }

https://segmentfault.com/a/1190000013688744

    推荐阅读