File tree Expand file tree Collapse file tree
JVM/src/com/cpucode/java/instruction/analysis Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .cpucode .java .instruction .analysis ;
2+
3+ /**
4+ * 指令6:操作数栈管理指令
5+ * @author : cpucode
6+ * @Date : 2021/1/27
7+ * @Time : 15:23
8+ * @Github : https://github.com/CPU-Code
9+ * @CSDN : https://blog.csdn.net/qq_44226094
10+ */
11+ public class StackOperateTest {
12+ public void print (){
13+ Object obj = new Object ();
14+
15+ String info = obj .toString ();
16+
17+ obj .toString ();
18+
19+ /**
20+ * 0 1 2
21+ * this obj info
22+ *
23+ * 0 new #3 <java/lang/Object>
24+ * 3 dup 复制
25+ * 4 invokespecial #1 <java/lang/Object.<init>> 调用父类方法
26+ * 7 astore_1
27+ *
28+ * 8 aload_1
29+ * 9 invokevirtual #4 <java/lang/Object.toString> 调用实例方法
30+ * 12 astore_2
31+ *
32+ * 13 aload_1
33+ * 14 invokevirtual #4 <java/lang/Object.toString>
34+ * 17 pop 出栈
35+ * 18 return
36+ * */
37+ }
38+
39+ public void foo (){
40+ bar ();
41+ }
42+
43+ public long bar (){
44+ return 0 ;
45+ }
46+
47+ public long nextIndex (){
48+ return index ++;
49+
50+ /**
51+ * 0 aload_0 将 this 压栈
52+ * 1 dup 复制
53+ * 2 getfield #2 <com/cpucode/java/instruction/analysis/StackOperateTest.index> 根据 栈中this地址 将 index 压栈
54+ * 5 dup2_x1 复制俩个槽 压栈到第二个下面
55+ * 6 lconst_1 压栈 俩个槽 1
56+ * 7 ladd long加法
57+ * 8 putfield #2 <com/cpucode/java/instruction/analysis/StackOperateTest.index> 将 栈中结果 复制到this的index
58+ * 11 lreturn long 返回
59+ * */
60+ }
61+
62+ private long index = 10 ;
63+ }
Original file line number Diff line number Diff line change @@ -729,6 +729,7 @@ java编程基础 面向对象 javaAPI 集合 IO GUI JD8C 多线程 网络编程
729729- [x] [ NewTest__ 分析数组创建] ( JVM/src/com/cpucode/java/instruction/analysis/NewTest.java )
730730- [x] [ MethodInvokeReturnTest__ 调用和返回方法] ( JVM/src/com/cpucode/java/instruction/analysis/MethodInvokeReturnTest.java )
731731- [x] [ InterfaceMethodTest__ 分析接口方法] ( JVM/src/com/cpucode/java/instruction/analysis/InterfaceMethodTest.java )
732+ - [x] [ StackOperateTest__ 分析操作栈] ( JVM/src/com/cpucode/java/instruction/analysis/StackOperateTest.java )
732733
733734- [ 返回目录] ( #文件目录 )
734735
You can’t perform that action at this time.
0 commit comments