Search in sources :

Example 1 with ILOAD

use of org.apache.bcel.generic.ILOAD in project jop by jop-devel.

the class ReplaceIinc method replace.

private void replace(MethodInfo method) {
    MethodCode mc = method.getCode();
    InstructionList il = mc.getInstructionList();
    InstructionFinder f = new InstructionFinder(il);
    for (Iterator i = f.search("IINC"); i.hasNext(); ) {
        InstructionHandle[] match = (InstructionHandle[]) i.next();
        InstructionHandle ih = match[0];
        IINC ii = (IINC) ih.getInstruction();
        int idx = ii.getIndex();
        int inc = ii.getIncrement();
        //  	    IINC rep = new IINC(idx, inc);
        ih.setInstruction(new ILOAD(idx));
        if (inc >= -1 && inc <= 5) {
            ih = il.append(ih, new ICONST(inc));
        } else if (inc >= -128 && inc < 127) {
            ih = il.append(ih, new BIPUSH((byte) inc));
        } else if (inc >= -32768 && inc < 32767) {
            ih = il.append(ih, new SIPUSH((short) inc));
        } else {
            System.out.println("IINC constant too big");
            System.exit(-1);
        }
        ih = il.append(ih, new IADD());
        ih = il.append(ih, new ISTORE(idx));
    }
    method.compile();
}
Also used : InstructionList(org.apache.bcel.generic.InstructionList) ILOAD(org.apache.bcel.generic.ILOAD) InstructionFinder(org.apache.bcel.util.InstructionFinder) BIPUSH(org.apache.bcel.generic.BIPUSH) InstructionHandle(org.apache.bcel.generic.InstructionHandle) ISTORE(org.apache.bcel.generic.ISTORE) IINC(org.apache.bcel.generic.IINC) Iterator(java.util.Iterator) IADD(org.apache.bcel.generic.IADD) MethodCode(com.jopdesign.common.MethodCode) SIPUSH(org.apache.bcel.generic.SIPUSH) ICONST(org.apache.bcel.generic.ICONST)

Example 2 with ILOAD

use of org.apache.bcel.generic.ILOAD in project jop by jop-devel.

the class HashTest method main.

public static void main(String[] args) {
    TestFramework test = new TestFramework();
    AppSetup setup = test.setupAppSetup();
    AppInfo appInfo = test.setupAppInfo("common.code.HashTest", false);
    ClassInfo testClass = appInfo.loadClass("common.TestFramework");
    MethodInfo mainMethod = appInfo.getMainMethod();
    MethodCode code = mainMethod.getCode();
    InstructionHandle[] ih = code.getInstructionList().getInstructionHandles();
    InvokeSite i1 = code.getInvokeSite(ih[1]);
    InvokeSite i2 = code.getInvokeSite(ih[2]);
    InvokeSite i3 = code.getInvokeSite(ih[3]);
    InvokeSite i11 = code.getInvokeSite(ih[1]);
    check(i1 == i11);
    CallString c1 = new CallString(i1);
    CallString c2 = new CallString(i2);
    CallString c11 = new CallString(i1);
    check(c1.equals(c11));
    check(!c1.equals(c2));
    ExecutionContext e1 = new ExecutionContext(mainMethod, c1);
    ExecutionContext e2 = new ExecutionContext(mainMethod, c2);
    ExecutionContext e11 = new ExecutionContext(mainMethod, c11);
    check(e1.equals(e11));
    check(!e1.equals(e2));
    // TODO put stuff into maps, check contains() and get()
    // modify instruction list, check if everything still works
    InstructionList il = code.getInstructionList();
    il.insert(new ILOAD(0));
    il.insert(ih[2], new ILOAD(1));
    ih = il.getInstructionHandles();
    InvokeSite i12 = code.getInvokeSite(ih[2]);
    InvokeSite i22 = code.getInvokeSite(ih[4]);
    check(i12 == i1);
    check(i22 == i2);
    check(e1.equals(e11));
    check(!e1.equals(e2));
    il.setPositions();
    check(c1.equals(c11));
    check(!c1.equals(c2));
    check(e1.equals(e11));
    check(!e1.equals(e2));
}
Also used : InstructionList(org.apache.bcel.generic.InstructionList) ILOAD(org.apache.bcel.generic.ILOAD) InstructionHandle(org.apache.bcel.generic.InstructionHandle) AppInfo(com.jopdesign.common.AppInfo) TestFramework(com.jopdesign.common.TestFramework) AppSetup(com.jopdesign.common.AppSetup) MethodInfo(com.jopdesign.common.MethodInfo) MethodCode(com.jopdesign.common.MethodCode) ClassInfo(com.jopdesign.common.ClassInfo)

Aggregations

MethodCode (com.jopdesign.common.MethodCode)2 ILOAD (org.apache.bcel.generic.ILOAD)2 InstructionHandle (org.apache.bcel.generic.InstructionHandle)2 InstructionList (org.apache.bcel.generic.InstructionList)2 AppInfo (com.jopdesign.common.AppInfo)1 AppSetup (com.jopdesign.common.AppSetup)1 ClassInfo (com.jopdesign.common.ClassInfo)1 MethodInfo (com.jopdesign.common.MethodInfo)1 TestFramework (com.jopdesign.common.TestFramework)1 Iterator (java.util.Iterator)1 BIPUSH (org.apache.bcel.generic.BIPUSH)1 IADD (org.apache.bcel.generic.IADD)1 ICONST (org.apache.bcel.generic.ICONST)1 IINC (org.apache.bcel.generic.IINC)1 ISTORE (org.apache.bcel.generic.ISTORE)1 SIPUSH (org.apache.bcel.generic.SIPUSH)1 InstructionFinder (org.apache.bcel.util.InstructionFinder)1