1,Stack概念
2.5.2 Java Virtual Machine Stacks(栈) Each Java Virtual Machine thread has a private Java Virtual Machine stack(栈), created at the same time as the thread. A Java Virtual Machine stack(栈) stores frames (§2.6:在章节2.6中,明确存储的描述). A Java Virtual Machine stack(栈) is analogous(类似的) to the stack of a conventional language such as C: it holds local variables(变量) and partial(部分) results, and plays a part (发挥作用)in method invocation and return. Because the Java Virtual Machine stack(栈) is never manipulated(被操纵) directly except to(除…) push and pop frames, frames may be heap(堆) allocated(已分配). The memory for a Java Virtual Machine stack does not need to be contiguous(连续的). In the First Edition of The Java® Virtual Machine Specification(规范), the Java Virtual Machine stack was known as the Java stack. This specification permits Java Virtual Machine stacks either to be of a fixed size or to dynamically expand and contract as required by the computation. If the Java Virtual Machine stacks are of a fixed size, the size of each Java Virtual Machine stack may be chosen independently when that stack is created. A Java Virtual Machine implementation may provide the programmer or the user control over the initial size of Java Virtual Machine stacks, as well as, in the case of dynamically expanding or contracting Java Virtual Machine stacks, control over the maximum(最大) and minimum sizes. The following exceptional(优秀/特) conditions are associated with Java Virtual Machine stacks: • If the computation(预算) in a thread requires a larger Java Virtual Machine stack than is permitted, the Java Virtual Machine throws a StackOverflowError. • If Java Virtual Machine stacks can be dynamically expanded, and expansion is attempted but insufficient (不足)memory can be made available(可用的) to effect the expansion, or if insufficient (不足)memory can be made available to create the initial Java THE STRUCTURE OF THE JAVA VIRTUAL MACHINE Run-Time Data Areas 2.5 13 Virtual Machine stack for a new thread, the Java Virtual Machine throws an OutOfMemoryError.
2,stack感观
3,stack特点
- stack 运行更新快
- Object 存放在堆(Heap),GC垃圾回收处理HEAP
- 存放局部变更/创建线程同是创建Stack(每个线程都有自己的栈内存)
4,结合源码
public class Math{public static final int initData = 666;public static User user = new User();public int compute(){int a = 1;int b = 2;int c = (a+b)*10;return c;}public static void main(String[] args){Math math = new Match();math.compute();}}
5,类JVM模型
6,栈深入描述
7,调优实操工具1
7.1,代码演示
public class HeapTest {byte[] a = new byte[1024 *100];@lombok.SneakyThrowspublic static void main(String[] args) {ArrayList<HeapTest> heapTests = new ArrayList<>();while (true){heapTests.add(new HeapTest());Thread.sleep(10);}}}
7.2,JVM工具
7.3,执行命令
7.4,执行结果
7.5,安装Visual GC



7.6,分析Visual GC
老年代满-> 触发->Full GC, 由于所有引用都是有效引用,最终触发OOM内存溢出
8,调优实操工具2
8.1 工具名称
8.2 工具下载
https://alibaba.github.io/arthas
https://github.com/alibaba/arthas/releases
arthas-boot.jar
>java -jar arthas-boot.jar
>dashboard




9,实时原码反编译
10,实践问题处理
10.1,FULL GC 什么样的一个频率是正常的?
答复:N天,N周,N月 FULL GC是相对较为理想。
10,2,FULL GC是什么原因造成的?
10.3,通常上线JMV基本参数如何设置?
JVM配置命令如下:
-Xms 3G
业务意义:
-Xmx 3G
业务意义:
-Xxx 1M
业务意义:
-XX:MetasapceSize=512M
业务意义:
-XX:MaxMetaspaceSize=512M
业务意义:
10.4,通常上线JMV基本参数如何设置,依据是什么?
a)明确数据类型大小 ,int 4个字节,String8个字节,boolean一个字节
b)自定义对象中包含了多少数据类型,进节加法运算(预计一个对像1KB)
c)关联对象放大20倍
d)以创建订单为例,假设每秒创建 300个订单:1KB(一个订单对象大小)20(订单关联对象 放大20倍)300(订单个数)*10(其它操作放大10倍)=60M(预计每秒生成60M对象 )。


