⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vm_instructionset.java~14~

📁 Java源码
💻 JAVA~14~
字号:
package AM.vm_impl.vm_data_structure;

import java.util.Vector;
import java.util.HashMap;
import AM.am_data_structure.InstructionSet;
import AM.vm_impl.util.Tracer;
import AM.am_data_structure.Stream;
import AM.vm_impl.instruction.*;
import AM.vm_impl.util.IllegalByteCodeException;


/**
 * Created by IntelliJ IDEA. User: yellowicq Date: 2004-4-27 Time: 14:00:22
 * To change this template use File | Settings | File Templates.
 */
public class VM_InstructionSet implements InstructionSet {
    private HashMap instMap;
    private HashMap bytecodeMap;

    public VM_InstructionSet() {
        instMap = new HashMap();
        bytecodeMap = new HashMap();
        Init();
    }

    public void Init() {
        instructionMapping();
        bytecodeMapping();
    }

    private void instructionMapping() {
        //push instruction mapping
        instMap.put("iconst_1", ICONST_1.class);
        instMap.put("iconst_2", ICONST_2.class);
        instMap.put("iload_0", ILOAD_0.class);
        instMap.put("iload_1", ILOAD_1.class);
        instMap.put("istore_0", ISTORE_0.class);
        instMap.put("istore_1", ISTORE_1.class);
        instMap.put("iadd", IADD.class);
        instMap.put("isub", ISUB.class);
        instMap.put("new", NEW.class);
        instMap.put("monitor", MONITOR.class);
        instMap.put("stop", STOP.class);
    }

    private void bytecodeMapping() {
        //push bytecode mapping
        bytecodeMap.put("04", "iconst_1");
        bytecodeMap.put("05", "iconst_2");
        bytecodeMap.put("1a", "iload_0");
        bytecodeMap.put("1b", "iload_1");
        bytecodeMap.put("3b", "istore_0");
        bytecodeMap.put("3c", "istore_1");
        bytecodeMap.put("60", "iadd");
        bytecodeMap.put("66", "isub");
        bytecodeMap.put("bb", "new");
        bytecodeMap.put("ff", "monitor");
        bytecodeMap.put("00", "stop");
    }

    public Vector resolve(Stream ins) {
        Vector tmpProgram = new Vector();
        Tracer.debug("Loading codebyte to program...");
        try {
            // read the contents into a byte array
            byte[] bytecode = new byte[2];
            while (ins.read(bytecode) != -1) {
                String mapStr = (String)bytecodeMap.get(new String(bytecode));
                if (mapStr == null) {
                    throw new IllegalByteCodeException();
                }
                if(mapStr.equalsIgnoreCase("new")){

                }
                else{
                  tmpProgram.add(((Class)instMap.get(mapStr)).newInstance());
                }
            };
            ins.close();
            // return the resolved program
            return tmpProgram;
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -