Search in sources :

Example 6 with ObjectType

use of org.apache.bcel.generic.ObjectType in project candle-decompiler by bradsdavis.

the class ExceptionEdgeEnhancer method addExceptionHandle.

private void addExceptionHandle(IntermediateEdge ie, CodeExceptionGen ceg) {
    ObjectType ot = ceg.getCatchType();
    Resolved resolved = null;
    if (ot == null) {
        resolved = new Resolved((InstructionHandle) ie.getTarget(), Type.THROWABLE, "e");
    } else {
        resolved = new Resolved((InstructionHandle) ie.getTarget(), ot, ot.toString());
    }
    ie.getAttributes().put(EXCEPTION_STACK_KEY, resolved);
}
Also used : ObjectType(org.apache.bcel.generic.ObjectType) Resolved(org.candle.decompiler.intermediate.expression.Resolved) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 7 with ObjectType

use of org.apache.bcel.generic.ObjectType in project candle-decompiler by bradsdavis.

the class ExpressionEnhancer method visitStatementIntermediate.

@Override
public void visitStatementIntermediate(StatementIntermediate line) {
    Expression exp = line.getExpression();
    //ok, now we can visit the expression...
    exp.visit(new ASTListener() {

        @Override
        public void accept(Expression e) {
            if (e instanceof NewInstance) {
                if (((NewInstance) e).getType() instanceof ObjectType) {
                    ObjectType obj = (ObjectType) ((NewInstance) e).getType();
                    if (StringUtils.equals("java.lang.StringBuilder", obj.getClassName())) {
                        System.out.println(obj.getClassName());
                    }
                }
            }
        }
    });
}
Also used : ObjectType(org.apache.bcel.generic.ObjectType) Expression(org.candle.decompiler.intermediate.expression.Expression) ASTListener(org.candle.decompiler.intermediate.expression.ASTListener) NewInstance(org.candle.decompiler.intermediate.expression.NewInstance)

Example 8 with ObjectType

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

the class FindUsedConstants method find.

private void find(Method method) {
    MethodGen mg = new MethodGen(method, clazz.getClassName(), cpool);
    InstructionList il = mg.getInstructionList();
    InstructionFinder f = new InstructionFinder(il);
    // find instructions that access the constant pool
    // collect all indices to constants in ClassInfo
    String cpInstr = "CPInstruction";
    for (Iterator it = f.search(cpInstr); it.hasNext(); ) {
        InstructionHandle[] match = (InstructionHandle[]) it.next();
        InstructionHandle first = match[0];
        CPInstruction ii = (CPInstruction) first.getInstruction();
        int idx = ii.getIndex();
        Constant co = cpool.getConstant(idx);
        int len = 1;
        switch(co.getTag()) {
            case Constants.CONSTANT_Long:
            case Constants.CONSTANT_Double:
                len = 2;
                break;
        }
        // we don't need the field references in the cpool anymore
        if (co.getTag() != Constants.CONSTANT_Fieldref) {
            getCli().addUsedConst(idx, len);
        }
    // also modify the index!
    //			Constant cnst = cpool.getConstant(ii.getIndex());
    //			int newIndex = addConstant(cnst);
    //System.out.println(ii+" -> "+newIndex);
    //			ii.setIndex(newIndex);			
    }
    il.dispose();
    CodeExceptionGen[] et = mg.getExceptionHandlers();
    for (int i = 0; i < et.length; i++) {
        ObjectType ctype = et[i].getCatchType();
        if (ctype != null) {
            getCli().addUsedConst(cpool.lookupClass(ctype.getClassName()), 1);
        }
    }
}
Also used : InstructionList(org.apache.bcel.generic.InstructionList) Constant(org.apache.bcel.classfile.Constant) InstructionFinder(org.apache.bcel.util.InstructionFinder) MethodGen(org.apache.bcel.generic.MethodGen) InstructionHandle(org.apache.bcel.generic.InstructionHandle) CPInstruction(org.apache.bcel.generic.CPInstruction) ObjectType(org.apache.bcel.generic.ObjectType) Iterator(java.util.Iterator) CodeExceptionGen(org.apache.bcel.generic.CodeExceptionGen)

Example 9 with ObjectType

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

the class MethodCode method getReferencedClassName.

/**
     * Get the classname or array-type name referenced by an invoke- or field instruction in this code.
     *
     * @param instr the instruction to check, using this methods constantpool.
     * @return the referenced classname or array-typename, to be used for a ClassRef or AppInfo getter. 
     */
public String getReferencedClassName(FieldOrMethod instr) {
    ConstantPoolGen cpg = getConstantPoolGen();
    ReferenceType refType = instr.getReferenceType(cpg);
    String classname;
    if (refType instanceof ObjectType) {
        classname = ((ObjectType) refType).getClassName();
    } else if (refType instanceof ArrayType) {
        // need to call array.<method>, which class should we use? Let's decide later..
        String msg = "Calling a method of an array: " + refType.getSignature() + "#" + instr.getName(cpg) + " in " + methodInfo;
        logger.debug(msg);
        classname = refType.getSignature();
    } else {
        // Hu??
        throw new JavaClassFormatError("Unknown reference type " + refType);
    }
    return classname;
}
Also used : ArrayType(org.apache.bcel.generic.ArrayType) ConstantPoolGen(org.apache.bcel.generic.ConstantPoolGen) ObjectType(org.apache.bcel.generic.ObjectType) JavaClassFormatError(com.jopdesign.common.misc.JavaClassFormatError) HashedString(com.jopdesign.common.misc.HashedString) CallString(com.jopdesign.common.code.CallString) ReferenceType(org.apache.bcel.generic.ReferenceType)

Example 10 with ObjectType

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

the class AllocationWcetModel method getExecutionTime.

public long getExecutionTime(ExecutionContext context, InstructionHandle ih) {
    int opcode = ih.getInstruction().getOpcode();
    MethodInfo mCtx = context.getMethodInfo();
    if (opcode == Constants.NEW) {
        NEW insn = (NEW) ih.getInstruction();
        ObjectType type = insn.getLoadClassType(mCtx.getConstantPoolGen());
        return computeObjectSize(getFieldSize(getObjectFields(type.getClassName())));
    } else if (opcode == Constants.NEWARRAY || opcode == Constants.ANEWARRAY) {
        int typeSize = 1;
        if (ih.getInstruction() instanceof NEWARRAY) {
            NEWARRAY insn = (NEWARRAY) ih.getInstruction();
            if (insn.getTypecode() == Constants.T_DOUBLE || insn.getTypecode() == Constants.T_LONG) {
                typeSize = 2;
            }
        }
        return computeArraySize(getArrayBound(context, ih, 0) * typeSize);
    } else if (opcode == Constants.MULTIANEWARRAY) {
        MULTIANEWARRAY insn = (MULTIANEWARRAY) ih.getInstruction();
        int dim = insn.getDimensions();
        long count = 1;
        long size = 0;
        for (int i = dim - 1; i >= 0; i--) {
            long bound = getArrayBound(context, ih, i);
            size += count * computeArraySize(bound);
            count *= bound;
        }
        return size;
    } else {
        return 0;
    }
}
Also used : MULTIANEWARRAY(org.apache.bcel.generic.MULTIANEWARRAY) NEWARRAY(org.apache.bcel.generic.NEWARRAY) NEW(org.apache.bcel.generic.NEW) ObjectType(org.apache.bcel.generic.ObjectType) MULTIANEWARRAY(org.apache.bcel.generic.MULTIANEWARRAY) MethodInfo(com.jopdesign.common.MethodInfo)

Aggregations

ObjectType (org.apache.bcel.generic.ObjectType)11 InstructionHandle (org.apache.bcel.generic.InstructionHandle)5 ConstantPoolGen (org.apache.bcel.generic.ConstantPoolGen)4 InstructionList (org.apache.bcel.generic.InstructionList)4 MethodGen (org.apache.bcel.generic.MethodGen)4 Type (org.apache.bcel.generic.Type)4 BranchInstruction (org.apache.bcel.generic.BranchInstruction)3 InstructionFactory (org.apache.bcel.generic.InstructionFactory)3 ReferenceType (org.apache.bcel.generic.ReferenceType)3 CallString (com.jopdesign.common.code.CallString)2 Iterator (java.util.Iterator)2 Random (java.util.Random)2 JavaClass (org.apache.bcel.classfile.JavaClass)2 ArrayType (org.apache.bcel.generic.ArrayType)2 ClassGen (org.apache.bcel.generic.ClassGen)2 INSTANCEOF (org.apache.bcel.generic.INSTANCEOF)2 PUSH (org.apache.bcel.generic.PUSH)2 InstructionFinder (org.apache.bcel.util.InstructionFinder)2 MethodInfo (com.jopdesign.common.MethodInfo)1 HashedString (com.jopdesign.common.misc.HashedString)1