use of org.apache.bcel.generic.Instruction in project jop by jop-devel.
the class ObjectCacheAnalysis method getHandleType.
public static String getHandleType(WCETTool project, ControlFlowGraph cfg, InstructionHandle ih) {
ConstantPoolGen constPool = cfg.getMethodInfo().getConstantPoolGen();
Instruction instr = ih.getInstruction();
if (instr instanceof GETFIELD) {
GETFIELD gf = (GETFIELD) instr;
ReferenceType refty = gf.getReferenceType(constPool);
return refty.toString();
}
if (!ALL_HANDLE_ACCESSES)
return null;
if (instr instanceof PUTFIELD) {
PUTFIELD pf = (PUTFIELD) instr;
ReferenceType refty = pf.getReferenceType(constPool);
return refty.toString();
}
if (instr instanceof ArrayInstruction) {
//ArrayInstruction ainstr = (ArrayInstruction) instr;
return "[]";
}
if (instr instanceof ARRAYLENGTH) {
//ARRAYLENGTH ainstr = (ARRAYLENGTH) instr;
return "[]";
}
if (instr instanceof INVOKEINTERFACE || instr instanceof INVOKEVIRTUAL) {
return "$header";
}
return null;
}
use of org.apache.bcel.generic.Instruction in project jop by jop-devel.
the class ObjectCacheAnalysis method getCachedType.
public static Type getCachedType(WCETTool project, ControlFlowGraph cfg, InstructionHandle ih) {
ConstantPoolGen constPool = cfg.getMethodInfo().getConstantPoolGen();
Instruction instr = ih.getInstruction();
if (instr instanceof GETFIELD) {
GETFIELD gf = (GETFIELD) instr;
return gf.getFieldType(constPool);
}
if (!ALL_HANDLE_ACCESSES) {
return null;
} else {
throw new AssertionError("For O$, only getfield is supported right now");
}
}
use of org.apache.bcel.generic.Instruction in project fb-contrib by mebigfatguy.
the class CopiedOverriddenMethod method codeEquals.
/**
* compares two code blocks to see if they are equal with regard to instructions and field accesses
*
* @param child
* the first code block
* @param parent
* the second code block
*
* @return whether the code blocks are the same
*/
private boolean codeEquals(Code child, Code parent) {
if (parent == null) {
return false;
}
byte[] childBytes = child.getCode();
byte[] parentBytes = parent.getCode();
if ((childBytes == null) || (parentBytes == null)) {
return false;
}
if (childBytes.length != parentBytes.length) {
return false;
}
InstructionHandle[] childihs = new InstructionList(childBytes).getInstructionHandles();
InstructionHandle[] parentihs = new InstructionList(parentBytes).getInstructionHandles();
if (childihs.length != parentihs.length) {
return false;
}
for (int i = 0; i < childihs.length; i++) {
InstructionHandle childih = childihs[i];
InstructionHandle parentih = parentihs[i];
Instruction childin = childih.getInstruction();
Instruction parentin = parentih.getInstruction();
if (!childin.getName().equals(parentin.getName())) {
return false;
}
if (childin instanceof FieldInstruction) {
String childFName = ((FieldInstruction) childin).getFieldName(childPoolGen);
String parentFName = ((FieldInstruction) parentin).getFieldName(parentPoolGen);
if (!childFName.equals(parentFName)) {
return false;
}
String childFSig = ((FieldInstruction) childin).getSignature(childPoolGen);
String parentFSig = ((FieldInstruction) parentin).getSignature(parentPoolGen);
if (!childFSig.equals(parentFSig)) {
return false;
}
if (childFSig.startsWith(Values.SIG_QUALIFIED_CLASS_PREFIX) || childFSig.startsWith(Values.SIG_ARRAY_PREFIX)) {
ReferenceType childRefType = ((FieldInstruction) childin).getReferenceType(childPoolGen);
ReferenceType parentRefType = ((FieldInstruction) parentin).getReferenceType(parentPoolGen);
if (!childRefType.getSignature().equals(parentRefType.getSignature())) {
return false;
}
}
} else if (childin instanceof InvokeInstruction) {
String childClassName = ((InvokeInstruction) childin).getClassName(childPoolGen);
String parentClassName = ((InvokeInstruction) parentin).getClassName(parentPoolGen);
if (!childClassName.equals(parentClassName)) {
return false;
}
String childMethodName = ((InvokeInstruction) childin).getMethodName(childPoolGen);
String parentMethodName = ((InvokeInstruction) parentin).getMethodName(parentPoolGen);
if (!childMethodName.equals(parentMethodName)) {
return false;
}
String childSignature = ((InvokeInstruction) childin).getSignature(childPoolGen);
String parentSignature = ((InvokeInstruction) parentin).getSignature(parentPoolGen);
if (!childSignature.equals(parentSignature)) {
return false;
}
} else if (childin instanceof LDC) {
Type childType = ((LDC) childin).getType(childPoolGen);
Type parentType = ((LDC) parentin).getType(parentPoolGen);
if (!childType.equals(parentType)) {
return false;
}
Object childValue = ((LDC) childin).getValue(childPoolGen);
Object parentValue = ((LDC) parentin).getValue(parentPoolGen);
if (childValue instanceof ConstantClass) {
ConstantClass childClass = (ConstantClass) childValue;
ConstantClass parentClass = (ConstantClass) parentValue;
if (!childClass.getBytes(childPoolGen.getConstantPool()).equals(parentClass.getBytes(parentPoolGen.getConstantPool()))) {
return false;
}
} else if (!childValue.equals(parentValue)) {
return false;
}
// TODO: Other Constant types
} else if (childin instanceof LDC2_W) {
Type childType = ((LDC2_W) childin).getType(childPoolGen);
Type parentType = ((LDC2_W) parentin).getType(parentPoolGen);
if (!childType.equals(parentType)) {
return false;
}
Object childValue = ((LDC2_W) childin).getValue(childPoolGen);
Object parentValue = ((LDC2_W) parentin).getValue(parentPoolGen);
if (!childValue.equals(parentValue)) {
return false;
}
} else {
if (!childin.equals(parentin)) {
return false;
}
}
}
return true;
}
use of org.apache.bcel.generic.Instruction in project jop by jop-devel.
the class ControlFlowGraph method addBasicBlock.
/*---------------------------------------------------------------------------*
* CFG modify, compile, dispose
*---------------------------------------------------------------------------*/
/**
* Add a basic block to this graph. The instruction list of the block must not be empty.
*
* @param insertBefore insert the block at this position in the block list.
* @param bb block to add
* @return the new block node, either an InvokeNode, SpecialInvokeNode or BasicBlockNode, depending on the
* contained instructions.
*/
public BasicBlockNode addBasicBlock(int insertBefore, BasicBlock bb) {
BasicBlockNode n;
Instruction lastInstr = bb.getLastInstruction().getInstruction();
InstructionHandle theInvoke = bb.getTheInvokeInstruction();
// This needs to be done before creating the Node, else blocks.indexOf returns -1
blocks.add(insertBefore, bb);
if (theInvoke != null) {
n = new InvokeNode(bb, theInvoke);
} else if (appInfo.getProcessorModel().isImplementedInJava(methodInfo, lastInstr)) {
MethodInfo javaImpl = appInfo.getProcessorModel().getJavaImplementation(appInfo, bb.getMethodInfo(), lastInstr);
n = new SpecialInvokeNode(bb, javaImpl);
} else {
n = new BasicBlockNode(bb);
}
graph.addVertex(n);
return n;
}
use of org.apache.bcel.generic.Instruction in project jop by jop-devel.
the class InstructionInterpreter method getInEdges.
private List<Edge> getInEdges(InstructionList il, InstructionHandle ih) {
List<Edge> edges = new LinkedList<Edge>();
InstructionHandle prev = ih.getPrev();
if (prev != null) {
// check if we can fall through from prev instruction
Instruction instr = prev.getInstruction();
if (!(instr instanceof UnconditionalBranch || instr instanceof Select || instr instanceof ReturnInstruction)) {
if (instr instanceof BranchInstruction) {
edges.add(new Edge(prev, ih, EdgeType.FALSE_EDGE));
} else {
edges.add(new Edge(prev, ih, EdgeType.NORMAL_EDGE));
}
}
}
// flow graph explicitly
for (InstructionHandle targeter = il.getStart(); targeter != null; targeter = targeter.getNext()) {
// for the instruction for the exception handler
if (!(targeter.getInstruction() instanceof BranchInstruction))
continue;
BranchInstruction bi = (BranchInstruction) targeter.getInstruction();
if (bi.containsTarget(ih)) {
edges.add(new Edge(targeter, ih, EdgeType.TRUE_EDGE));
}
}
return edges;
}
Aggregations