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);
}
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());
}
}
}
}
});
}
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);
}
}
}
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;
}
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;
}
}
Aggregations