mirror of
https://github.com/zhwei820/learn.lianglianglee.com.git
synced 2025-11-15 21:53:50 +08:00
u
This commit is contained in:
@@ -25,13 +25,7 @@
|
||||
<meta name="generator" content="Hexo 4.2.0">
|
||||
|
||||
</head>
|
||||
|
||||
|
||||
|
||||
<body>
|
||||
|
||||
|
||||
|
||||
<div class="book-container">
|
||||
|
||||
<div class="book-sidebar">
|
||||
@@ -55,361 +49,184 @@
|
||||
<li><a href="/" class="current-tab">首页</a></li>
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
<ul class="uncollapsible">
|
||||
|
||||
<li><a href="../">上一级</a></li>
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
<ul class="uncollapsible">
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="/专栏/深入浅出 Java 虚拟机-完/00 开篇词:JVM,一块难啃的骨头.md.html">00 开篇词:JVM,一块难啃的骨头.md.html</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="/专栏/深入浅出 Java 虚拟机-完/01 一探究竟:为什么需要 JVM?它处在什么位置?.md.html">01 一探究竟:为什么需要 JVM?它处在什么位置?.md.html</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="/专栏/深入浅出 Java 虚拟机-完/02 大厂面试题:你不得不掌握的 JVM 内存管理.md.html">02 大厂面试题:你不得不掌握的 JVM 内存管理.md.html</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="/专栏/深入浅出 Java 虚拟机-完/03 大厂面试题:从覆盖 JDK 的类开始掌握类的加载机制.md.html">03 大厂面试题:从覆盖 JDK 的类开始掌握类的加载机制.md.html</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="/专栏/深入浅出 Java 虚拟机-完/04 动手实践:从栈帧看字节码是如何在 JVM 中进行流转的.md.html">04 动手实践:从栈帧看字节码是如何在 JVM 中进行流转的.md.html</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="/专栏/深入浅出 Java 虚拟机-完/05 大厂面试题:得心应手应对 OOM 的疑难杂症.md.html">05 大厂面试题:得心应手应对 OOM 的疑难杂症.md.html</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="/专栏/深入浅出 Java 虚拟机-完/06 深入剖析:垃圾回收你真的了解吗?(上).md.html">06 深入剖析:垃圾回收你真的了解吗?(上).md.html</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="/专栏/深入浅出 Java 虚拟机-完/07 深入剖析:垃圾回收你真的了解吗?(下).md.html">07 深入剖析:垃圾回收你真的了解吗?(下).md.html</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="/专栏/深入浅出 Java 虚拟机-完/08 大厂面试题:有了 G1 还需要其他垃圾回收器吗?.md.html">08 大厂面试题:有了 G1 还需要其他垃圾回收器吗?.md.html</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="/专栏/深入浅出 Java 虚拟机-完/09 案例实战:亿级流量高并发下如何进行估算和调优.md.html">09 案例实战:亿级流量高并发下如何进行估算和调优.md.html</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="/专栏/深入浅出 Java 虚拟机-完/10 第09讲:案例实战:面对突如其来的 GC 问题如何下手解决.md.html">10 第09讲:案例实战:面对突如其来的 GC 问题如何下手解决.md.html</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="/专栏/深入浅出 Java 虚拟机-完/11 第10讲:动手实践:自己模拟 JVM 内存溢出场景.md.html">11 第10讲:动手实践:自己模拟 JVM 内存溢出场景.md.html</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="/专栏/深入浅出 Java 虚拟机-完/12 第11讲:动手实践:遇到问题不要慌,轻松搞定内存泄漏.md.html">12 第11讲:动手实践:遇到问题不要慌,轻松搞定内存泄漏.md.html</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="/专栏/深入浅出 Java 虚拟机-完/13 工具进阶:如何利用 MAT 找到问题发生的根本原因.md.html">13 工具进阶:如何利用 MAT 找到问题发生的根本原因.md.html</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
<a class="current-tab" href="/专栏/深入浅出 Java 虚拟机-完/14 动手实践:让面试官刮目相看的堆外内存排查.md.html">14 动手实践:让面试官刮目相看的堆外内存排查.md.html</a>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="/专栏/深入浅出 Java 虚拟机-完/15 预警与解决:深入浅出 GC 监控与调优.md.html">15 预警与解决:深入浅出 GC 监控与调优.md.html</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="/专栏/深入浅出 Java 虚拟机-完/16 案例分析:一个高死亡率的报表系统的优化之路.md.html">16 案例分析:一个高死亡率的报表系统的优化之路.md.html</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="/专栏/深入浅出 Java 虚拟机-完/17 案例分析:分库分表后,我的应用崩溃了.md.html">17 案例分析:分库分表后,我的应用崩溃了.md.html</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="/专栏/深入浅出 Java 虚拟机-完/18 动手实践:从字节码看方法调用的底层实现.md.html">18 动手实践:从字节码看方法调用的底层实现.md.html</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="/专栏/深入浅出 Java 虚拟机-完/19 大厂面试题:不要搞混 JMM 与 JVM.md.html">19 大厂面试题:不要搞混 JMM 与 JVM.md.html</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="/专栏/深入浅出 Java 虚拟机-完/20 动手实践:从字节码看并发编程的底层实现.md.html">20 动手实践:从字节码看并发编程的底层实现.md.html</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="/专栏/深入浅出 Java 虚拟机-完/21 动手实践:不为人熟知的字节码指令.md.html">21 动手实践:不为人熟知的字节码指令.md.html</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="/专栏/深入浅出 Java 虚拟机-完/22 深入剖析:如何使用 Java Agent 技术对字节码进行修改.md.html">22 深入剖析:如何使用 Java Agent 技术对字节码进行修改.md.html</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="/专栏/深入浅出 Java 虚拟机-完/23 动手实践:JIT 参数配置如何影响程序运行?.md.html">23 动手实践:JIT 参数配置如何影响程序运行?.md.html</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="/专栏/深入浅出 Java 虚拟机-完/24 案例分析:大型项目如何进行性能瓶颈调优?.md.html">24 案例分析:大型项目如何进行性能瓶颈调优?.md.html</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="/专栏/深入浅出 Java 虚拟机-完/25 未来:JVM 的历史与展望.md.html">25 未来:JVM 的历史与展望.md.html</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="/专栏/深入浅出 Java 虚拟机-完/26 福利:常见 JVM 面试题补充.md.html">26 福利:常见 JVM 面试题补充.md.html</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="sidebar-toggle" onclick="sidebar_toggle()" onmouseover="add_inner()" onmouseleave="remove_inner()">
|
||||
|
||||
<div class="sidebar-toggle-inner"></div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
function add_inner() {
|
||||
@@ -419,9 +236,6 @@
|
||||
inner.classList.add('show')
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function remove_inner() {
|
||||
|
||||
let inner = document.querySelector('.sidebar-toggle-inner')
|
||||
@@ -429,9 +243,6 @@
|
||||
inner.classList.remove('show')
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function sidebar_toggle() {
|
||||
|
||||
let sidebar_toggle = document.querySelector('.sidebar-toggle')
|
||||
@@ -461,9 +272,6 @@
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function open_sidebar() {
|
||||
|
||||
let sidebar = document.querySelector('.book-sidebar')
|
||||
@@ -487,13 +295,7 @@ function hide_canvas() {
|
||||
overlay.classList.remove('show')
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
<div class="off-canvas-content">
|
||||
|
||||
<div class="columns">
|
||||
@@ -553,19 +355,10 @@ function hide_canvas() {
|
||||
<p>在第 10 课时,介绍了 MaxDirectMemorySize 可以控制直接内存的申请。其实,通过这个参数,仍然限制不住所有堆外内存的使用,它只是限制了使用 DirectByteBuffer 的内存申请。很多时候(比如直接使用了 sun.misc.Unsafe 类),堆外内存会一直增长,直到机器物理内存爆满,被 oom killer。</p>
|
||||
|
||||
<pre><code>import sun.misc.Unsafe;
|
||||
|
||||
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
|
||||
|
||||
public class UnsafeDemo {
|
||||
|
||||
public static final int _1MB = 1024 * 1024;
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
Field field = Unsafe.class.getDeclaredField("theUnsafe");
|
||||
@@ -623,9 +416,6 @@ RSS VSZ 7152568 17485844
|
||||
import com.sun.net.httpserver.HttpContext;
|
||||
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
|
||||
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
@@ -639,9 +429,6 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* @author xjjdog
|
||||
@@ -683,9 +470,6 @@ public class LeakExample {
|
||||
return ret.toString();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static int copy(InputStream input, OutputStream output) throws IOException {
|
||||
|
||||
long count = copyLarge(input, output);
|
||||
@@ -693,17 +477,11 @@ public class LeakExample {
|
||||
return count > 2147483647L ? -1 : (int) count;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static long copyLarge(InputStream input, OutputStream output) throws IOException {
|
||||
|
||||
byte[] buffer = new byte[4096];
|
||||
|
||||
long count = 0L;
|
||||
|
||||
|
||||
|
||||
int n;
|
||||
|
||||
for (; -1 != (n = input.read(buffer)); count += (long) n) {
|
||||
@@ -711,15 +489,9 @@ public class LeakExample {
|
||||
output.write(buffer, 0, n);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return count;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String decompress(byte[] input) throws Exception {
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
@@ -729,17 +501,11 @@ public class LeakExample {
|
||||
return new String(out.toByteArray());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static byte[] compress(String str) throws Exception {
|
||||
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
|
||||
GZIPOutputStream gzip = new GZIPOutputStream(bos);
|
||||
|
||||
|
||||
|
||||
try {
|
||||
|
||||
gzip.write(str.getBytes());
|
||||
@@ -761,17 +527,11 @@ public class LeakExample {
|
||||
}
|
||||
|
||||
private static OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
|
||||
|
||||
|
||||
|
||||
public static int memoryLoad() {
|
||||
|
||||
double totalvirtualMemory = osmxb.getTotalPhysicalMemorySize();
|
||||
|
||||
double freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize();
|
||||
|
||||
|
||||
|
||||
double value = freePhysicalMemorySize / totalvirtualMemory;
|
||||
|
||||
int percentMemoryLoad = (int) ((1 - value) * 100);
|
||||
@@ -781,9 +541,6 @@ public class LeakExample {
|
||||
}
|
||||
|
||||
private static volatile int RADIO = 60;
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
HttpServer server = HttpServer.create(new InetSocketAddress(8888), 0);
|
||||
@@ -865,17 +622,11 @@ public class LeakExample {
|
||||
2154:
|
||||
|
||||
Native Memory Tracking:
|
||||
|
||||
|
||||
|
||||
Total: reserved=2370381KB, committed=1071413KB
|
||||
|
||||
- Java Heap (reserved=1048576KB, committed=1048576KB)
|
||||
|
||||
(mmap: reserved=1048576KB, committed=1048576KB)
|
||||
|
||||
|
||||
|
||||
- Class (reserved=1056899KB, committed=4995KB)
|
||||
|
||||
(classes #432)
|
||||
@@ -883,9 +634,6 @@ Total: reserved=2370381KB, committed=1071413KB
|
||||
(malloc=131KB #328)
|
||||
|
||||
(mmap: reserved=1056768KB, committed=4864KB)
|
||||
|
||||
|
||||
|
||||
- Thread (reserved=10305KB, committed=10305KB)
|
||||
|
||||
(thread #11)
|
||||
@@ -895,57 +643,36 @@ Total: reserved=2370381KB, committed=1071413KB
|
||||
(malloc=34KB #52)
|
||||
|
||||
(arena=12KB #18)
|
||||
|
||||
|
||||
|
||||
- Code (reserved=249744KB, committed=2680KB)
|
||||
|
||||
(malloc=144KB #502)
|
||||
|
||||
(mmap: reserved=249600KB, committed=2536KB)
|
||||
|
||||
|
||||
|
||||
- GC (reserved=2063KB, committed=2063KB)
|
||||
|
||||
(malloc=7KB #80)
|
||||
|
||||
(mmap: reserved=2056KB, committed=2056KB)
|
||||
|
||||
|
||||
|
||||
- Compiler (reserved=138KB, committed=138KB)
|
||||
|
||||
(malloc=8KB #38)
|
||||
|
||||
(arena=131KB #5)
|
||||
|
||||
|
||||
|
||||
- Internal (reserved=789KB, committed=789KB)
|
||||
|
||||
(malloc=757KB #1272)
|
||||
|
||||
(mmap: reserved=32KB, committed=32KB)
|
||||
|
||||
|
||||
|
||||
- Symbol (reserved=1535KB, committed=1535KB)
|
||||
|
||||
(malloc=983KB #114)
|
||||
|
||||
(arena=552KB #1)
|
||||
|
||||
|
||||
|
||||
- Native Memory Tracking (reserved=159KB, committed=159KB)
|
||||
|
||||
(malloc=99KB #1399)
|
||||
|
||||
(tracking overhead=60KB)
|
||||
|
||||
|
||||
|
||||
- Arena Chunk (reserved=174KB, committed=174KB)
|
||||
|
||||
(mall
|
||||
@@ -1089,9 +816,6 @@ total kB 8492740 3511008 3498584
|
||||
<p>是时候查看里面的内容了,使用 strings 命令可以看到内存块里一些可以打印的内容。</p>
|
||||
|
||||
<pre><code># strings -10 a.dump
|
||||
|
||||
|
||||
|
||||
0R4f1Qej1ty5GT8V1R8no6T44564wz499E6Y582q2R9h8CC175GJ3yeJ1Q3P5Vt757Mcf6378kM36hxZ5U8uhg2A26T5l7f68719WQK6vZ2BOdH9lH5C7838qf1
|
||||
|
||||
...
|
||||
@@ -1259,9 +983,6 @@ pprof -text *heap | head -n 200
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@@ -1269,9 +990,6 @@ pprof -text *heap | head -n 200
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<a class="off-canvas-overlay" onclick="hide_canvas()"></a>
|
||||
|
||||
</div>
|
||||
@@ -1287,17 +1005,11 @@ pprof -text *heap | head -n 200
|
||||
<script>
|
||||
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
|
||||
|
||||
|
||||
function gtag() {
|
||||
|
||||
dataLayer.push(arguments);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
gtag('js', new Date());
|
||||
|
||||
gtag('config', 'G-NPSEEVD756');
|
||||
@@ -1323,9 +1035,6 @@ pprof -text *heap | head -n 200
|
||||
setCookie("lastPath", path)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function setCookie(cname, cvalue) {
|
||||
|
||||
var d = new Date();
|
||||
@@ -1337,9 +1046,6 @@ pprof -text *heap | head -n 200
|
||||
document.cookie = cname + "=" + cvalue + "; " + expires + ";path = /";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function getCookie(cname) {
|
||||
|
||||
var name = cname + "=";
|
||||
@@ -1357,12 +1063,6 @@ pprof -text *heap | head -n 200
|
||||
return "";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
</html>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user