本文整理汇总了Java中org.apache.bcel.generic.InstructionList.getInstructionHandles方法的典型用法代码示例。如果您正苦于以下问题:Java InstructionList.getInstructionHandles方法的具体用法?Java InstructionList.getInstructionHandles怎么用?Java InstructionList.getInstructionHandles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.bcel.generic.InstructionList
的用法示例。
在下文中一共展示了InstructionList.getInstructionHandles方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fillSpawnTable
import org.apache.bcel.generic.InstructionList; //导入方法依赖的package包/类
private void fillSpawnTable(MethodTableEntry me) {
InstructionList il = me.mg.getInstructionList();
InstructionHandle[] ins = il.getInstructionHandles();
il.setPositions();
int spawnId = 0;
for (int k = 0; k < ins.length; k++) {
if (ins[k].getInstruction() instanceof INVOKEVIRTUAL) {
Method target = self.findMethod((INVOKEVIRTUAL) (ins[k]
.getInstruction()));
JavaClass cl = self.findMethodClass((INVOKEVIRTUAL) (ins[k]
.getInstruction()));
if (isSpawnable(target, cl)) {
// we have a spawn!
analyzeSpawn(me, ins[k], spawnId);
spawnId++;
}
}
}
}
示例2: calcNrSpawns
import org.apache.bcel.generic.InstructionList; //导入方法依赖的package包/类
private int calcNrSpawns(MethodGen mg) {
InstructionList il = mg.getInstructionList();
if (il == null) {
return 0;
}
InstructionHandle[] ins = il.getInstructionHandles();
int count = 0;
for (int i = 0; i < ins.length; i++) {
if (ins[i].getInstruction() instanceof INVOKEVIRTUAL) {
Method target = self.findMethod((INVOKEVIRTUAL) (ins[i]
.getInstruction()));
JavaClass cl = self.findMethodClass((INVOKEVIRTUAL) (ins[i]
.getInstruction()));
if (isSpawnable(target, cl)) {
count++;
}
}
}
return count;
}
示例3: containsSpawnedCall
import org.apache.bcel.generic.InstructionList; //导入方法依赖的package包/类
boolean containsSpawnedCall(MethodGen m) {
InstructionList code = m.getInstructionList();
if (code == null) {
return false;
}
InstructionHandle ih[] = code.getInstructionHandles();
for (int i = 0; i < ih.length; i++) {
Instruction ins = ih[i].getInstruction();
if (ins instanceof INVOKEVIRTUAL) {
Method target = self.findMethod((INVOKEVIRTUAL) (ins));
JavaClass cl = self.findMethodClass((INVOKEVIRTUAL) (ins));
if (isSpawnable(target, cl)) {
return true;
}
}
}
return false;
}
示例4: removeUnusedLocals
import org.apache.bcel.generic.InstructionList; //导入方法依赖的package包/类
void removeUnusedLocals(Method mOrig, MethodGen m) {
InstructionList il = m.getInstructionList();
InstructionHandle[] ins = il.getInstructionHandles();
for (int i = 0; i < ins.length; i++) {
Instruction in = ins[i].getInstruction();
if (in instanceof LocalVariableInstruction) {
LocalVariableInstruction curr = (LocalVariableInstruction) in;
if (mtab.getLocal(m, curr, ins[i].getPosition()) != null
&& curr.getIndex() < m.getMaxLocals() - 5
&& !mtab.isLocalUsedInInlet(mOrig, curr.getIndex())) {
if (curr instanceof IINC) {
ins[i].setInstruction(new NOP());
} else if (curr instanceof LSTORE || curr instanceof DSTORE) {
ins[i].setInstruction(new POP2());
} else if (curr instanceof StoreInstruction) {
ins[i].setInstruction(new POP());
} else if (curr instanceof ALOAD) {
ins[i].setInstruction(new ACONST_NULL());
} else if (curr instanceof FLOAD) {
ins[i].setInstruction(new FCONST((float) 0.0));
} else if (curr instanceof ILOAD) {
ins[i].setInstruction(new ICONST(0));
} else if (curr instanceof DLOAD) {
ins[i].setInstruction(new DCONST(0.0));
} else if (curr instanceof LLOAD) {
ins[i].setInstruction(new LCONST(0L));
} else {
System.out.println("unhandled ins in "
+ "removeUnusedLocals: " + curr);
System.exit(1);
}
}
}
}
}
示例5: shiftLocals
import org.apache.bcel.generic.InstructionList; //导入方法依赖的package包/类
void shiftLocals(InstructionList il, int shift) {
InstructionHandle[] ih = il.getInstructionHandles();
for (int i = 0; i < ih.length; i++) {
Instruction ins = ih[i].getInstruction();
if (ins instanceof LocalVariableInstruction) {
LocalVariableInstruction l = (LocalVariableInstruction) ins;
l.setIndex(l.getIndex() + shift);
}
}
}
示例6: showMethod
import org.apache.bcel.generic.InstructionList; //导入方法依赖的package包/类
void showMethod(PrintStream out, MethodGen methodGen, ConstantPool cp) {
InstructionList il = methodGen.getInstructionList();
InstructionHandle[] instructionHandles = il.getInstructionHandles();
ConstantPoolGen cpg = new ConstantPoolGen(cp);
int balanceOnStack = 0;
for (InstructionHandle ih : instructionHandles) {
int produced = ih.getInstruction().produceStack(cpg);
int consumed = ih.getInstruction().consumeStack(cpg);
balanceOnStack = balanceOnStack + produced - consumed;
out.printf("%d:\t(c: %d, p: %d, t: %d)\t%s\n",
ih.getPosition(), consumed, produced, balanceOnStack,
ih.getInstruction().toString(cp));
}
}
示例7: getContexts
import org.apache.bcel.generic.InstructionList; //导入方法依赖的package包/类
private InstructionContext[] getContexts(MethodGen methodGen,
ControlFlowGraph graph) {
InstructionList il = methodGen.getInstructionList();
InstructionHandle[] instructionHandles = il.getInstructionHandles();
return graph.contextsOf(instructionHandles);
}
示例8: instrument_reflection
import org.apache.bcel.generic.InstructionList; //导入方法依赖的package包/类
private static Method instrument_reflection(InstructionFactory inf, MethodGen mgen, ConstantPoolGen cpgen) {
Method ret = mgen.getMethod();
InstructionList ilist = mgen.getInstructionList();
if (ilist == null || ilist.size() == 0)
return ret;
InstructionHandle[] ihdls = ilist.getInstructionHandles();
for (InstructionHandle ihdl : ihdls) {
Instruction instr = ihdl.getInstruction();
// go through all instructions and look for invokes
if (instr instanceof InvokeInstruction) {
InvokeInstruction invoke = (InvokeInstruction) instr;
ReferenceType rtype = invoke.getReferenceType(cpgen);
if (rtype instanceof ObjectType) {
String cname = ((ObjectType) rtype).getClassName();
String mname = invoke.getName(cpgen);
// we look for exact match
if (cname.equals("java.lang.reflect.Method") && mname.equals("invoke")) {
// Util.log(rtype.toString());
Type[] arg_types = { new ObjectType(java.lang.reflect.Method.class.getCanonicalName()), Type.OBJECT, new ArrayType(Type.OBJECT, 1) };
ihdl.setInstruction(inf.createInvoke(SIFAStub.class.getCanonicalName(), "invoke", Type.OBJECT, arg_types, Constants.INVOKESTATIC));
}
} else {
// reference type can be ArrayType or UninitializedObjectType
}
}
}
ilist.setPositions();
mgen.setInstructionList(ilist);
mgen.removeLineNumbers();
mgen.setMaxStack();
mgen.setMaxLocals();
ret = mgen.getMethod();
return ret;
}
示例9: visitCode
import org.apache.bcel.generic.InstructionList; //导入方法依赖的package包/类
public void visitCode(Code code) {
MethodGen mg = new MethodGen(_method, clazzname, cp);
InstructionList il = mg.getInstructionList();
InstructionHandle[] ihs = il.getInstructionHandles();
LocalVariableGen[] lvs = mg.getLocalVariables();
CodeExceptionGen[] ehs = mg.getExceptionHandlers();
for (int i = 0; i < lvs.length; i++) {
LocalVariableGen l = lvs[i];
out.println(" // local variable " + l.getIndex() + " is \"" + l.getName()
+ "\" " + l.getType() + " from "
+ l.getStart().getPosition() + " to "
+ l.getEnd().getPosition());
}
out.print("\n");
for (int i = 0; i < ihs.length; i++) {
InstructionHandle ih = ihs[i];
Instruction inst = ih.getInstruction();
out.print(" " + ih.getPosition());
if (inst instanceof BranchInstruction) {
if (inst instanceof Select) { // Special cases LOOKUPSWITCH and
// TABLESWITCH
Select s = (Select) inst;
int[] matchs = s.getMatchs();
InstructionHandle[] targets = s.getTargets();
if (s instanceof TABLESWITCH) {
out.println(" tableswitch " + matchs[0] + " "
+ matchs[matchs.length - 1]);
for (int j = 0; j < targets.length; j++)
out.println(" " + targets[j].getPosition());
} else { // LOOKUPSWITCH
out.println(" lookupswitch ");
for (int j = 0; j < targets.length; j++)
out.println(" " + matchs[j] + " : "
+ targets[j].getPosition());
}
out.println(" default: " + s.getTarget()); // Applies
// for
// both
} else {
BranchInstruction bi = (BranchInstruction) inst;
ih = bi.getTarget();
//str = get(ih);
out.println(" " + Constants.OPCODE_NAMES[bi.getOpcode()]
+ " " + ih);
}
} else
out.println(" " + inst.toString(cp.getConstantPool()));
}
out.print("\n");
for (int i = 0; i < ehs.length; i++) {
CodeExceptionGen c = ehs[i];
ObjectType caught = c.getCatchType();
String class_name = (caught == null) ? // catch any exception, used
// when compiling finally
"all" : caught.getClassName().replace('.', '/');
out.println(" catch " + class_name + " from "
+ c.getStartPC().getPosition() + " to "
+ c.getEndPC().getPosition() + " using "
+ c.getHandlerPC().getPosition());
}
}