程序猿小碼農 2021-09-18 06:24:55 阅读数:24
JvmStack.java
package org.itstack.demo.jvm.rtda; /** * http://www.itstack.org * create by fuzhengwei on 2019/4/26 * 虛擬機棧 */ public class JvmStack { private int maxSize; private int size; private Frame _top; public JvmStack(int maxSize) { this.maxSize = maxSize; } public void push(Frame frame) { if (this.size > this.maxSize) { throw new StackOverflowError(); } if (this._top != null) { frame.lower = this._top; } this._top = frame; this.size++; } public Frame pop() { if (this._top == null) { throw new RuntimeException("jvm stack is empty!"); } Frame top = this._top; this._top = top.lower; top.lower = null; this.size--; return top; } public Frame top(){ if (this._top == null){ throw new RuntimeException("jvm stack is empty!"); } return this._top; } }
LocalVars.java
package org.itstack.demo.jvm.rtda; /** * http://www.itstack.org * create by fuzhengwei on 2019/4/26 * 局部變量錶 */ public class LocalVars { private Slot[] slots; public LocalVars(int maxLocals) { if (maxLocals > 0) { slots = new Slot[maxLocals]; for (int i = 0; i < maxLocals; i++) { slots[i] = new Slot(); } } } public void setInt(int idx, int val) { this.slots[idx].num = val; } public int getInt(int idx) { return slots[idx].num; } public void setFloat(int idx, float val) { this.slots[idx].num = (Float.valueOf(val)).intValue(); } public Float getFloat(int idx) { int num = this.slots[idx].num; return (float) num; } public void setLong(int idx, long val) { this.slots[idx].num = (int) val; this.slots[idx + 1].num = (int) (val >> 32); } public Long getLong(int idx) { int low = this.slots[idx].num; int high = this.slots[idx + 1].num; return ((long) high << 32) | (long) low; } public void setDouble(int idx, double val) { setLong(idx, (long) val); } public Double getDouble(int idx) { return Double.valueOf(getLong(idx)); } public void setRef(int idx, Object ref) { slots[idx].ref = ref; } public Object getRef(int idx) { return slots[idx].ref; } }
OperandStack.java
package org.itstack.demo.jvm.rtda; /** * http://www.itstack.org * create by fuzhengwei on 2019/4/26 * 操作數棧 */ public class OperandStack { private int size = 0; private Slot[] slots; public OperandStack(int maxStack) { if (maxStack > 0) { slots = new Slot[maxStack]; for (int i = 0; i < maxStack; i++) { slots[i] = new Slot(); } } } public void pushInt(int val) { slots[size].num = val; size++; } public int popInt(){ size --; return slots[size].num; } public void pushRef(Object ref){ slots[size].ref = ref; size++; } public Object popRef(){ size --; Object ref = slots[size].ref; slots[size].ref = null; return ref; } }
Slot.java
package org.itstack.demo.jvm.rtda; /** # 資料分享 > **[CodeChina開源項目:【一線大廠Java面試題解析+核心總結學習筆記+最新講解視頻】](https://ali1024.coding.net/public/P7/Java/git)** **1、算法大廠——字節跳動面試題**  **2、2000頁互聯網Java面試題大全**  **3、高階必備,算法學習** 
版权声明:本文为[程序猿小碼農]所创,转载请带上原文链接,感谢。 https://gsmany.com/2021/09/20210918062454882e.html
《 100天的默契
愛奇藝開源的組件化跨進程通信解决方案,不服不行 》