sudo -u admin /java/bin/jmap -histo:live 37 | head -10 | sort -r -k3
jmap -heap pid
top
@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生效
手动触发full gc,( sudo -u admin /bin/jmap -histo:live 38 |head -10 )之后
dashboard
direct 显示40m
curl -L https://alibaba.github.io/arthas/install.sh | sh
yum install xinetd telnet telnet-server -y
sudo -u admin -EH ./as.sh
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 开启命令行模式
total used free shared buff/cache available
Mem: 15G 8.8G 6.0G 1.0M 700M 6.4G
Swap: 0B 0B 0B
https://www.jianshu.com/p/c76747997ade
https://www.jianshu.com/p/4e96beb37935
quit 退出
shutdown 关闭
/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<String> vmArgs = (List<String>) 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