本文整理汇总了Java中org.apache.bcel.generic.InstructionList类的典型用法代码示例。如果您正苦于以下问题:Java InstructionList类的具体用法?Java InstructionList怎么用?Java InstructionList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InstructionList类属于org.apache.bcel.generic包,在下文中一共展示了InstructionList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitCode
import org.apache.bcel.generic.InstructionList; //导入依赖的package包/类
/**
* @see org.apache.bcel.classfile.Visitor#visitCode
*/
public void visitCode(Code aCode)
{
for (Iterator iter = mVisitors.iterator(); iter.hasNext();) {
IDeepVisitor visitor = (IDeepVisitor) iter.next();
Visitor v = visitor.getClassFileVisitor();
aCode.accept(v);
}
// perform a deep visit
final byte[] code = aCode.getCode();
final InstructionList list = new InstructionList(code);
final Iterator it = list.iterator();
for (Iterator iter = list.iterator(); iter.hasNext();) {
InstructionHandle instruction = (InstructionHandle) iter.next();
visitInstructionHandle(instruction);
}
}
示例2: 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++;
}
}
}
}
示例3: 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;
}
示例4: 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;
}
示例5: insertDeleteSpawncounter
import org.apache.bcel.generic.InstructionList; //导入依赖的package包/类
InstructionHandle insertDeleteSpawncounter(InstructionList il,
InstructionHandle i, int maxLocals) {
// In this case, jumps to the return must in fact jump to
// the new instruction sequence! So, we change the instruction
// at the handle.
// First, save the return instruction.
Instruction r = i.getInstruction();
i.setInstruction(new ALOAD(maxLocals));
i = il
.append(i, ins_f.createInvoke(
"ibis.cashmere.impl.spawnSync.SpawnCounter", "deleteSpawnCounter",
Type.VOID, new Type[] { spawnCounterType },
Constants.INVOKESTATIC));
i = il.append(i, r);
return i;
}
示例6: deleteIns
import org.apache.bcel.generic.InstructionList; //导入依赖的package包/类
static private void deleteIns(InstructionList il, InstructionHandle ih,
InstructionHandle new_target) {
// System.out.println("deleteIns: instructionList = " + il);
// System.out.println(" handle = " + ih);
try {
il.delete(ih);
} catch (TargetLostException e) {
InstructionHandle[] targets = e.getTargets();
for (int i = 0; i < targets.length; i++) {
InstructionTargeter[] targeters = targets[i].getTargeters();
for (int j = 0; j < targeters.length; j++) {
targeters[j].updateTarget(targets[i], new_target);
}
}
}
}
示例7: pushParams
import org.apache.bcel.generic.InstructionList; //导入依赖的package包/类
InstructionHandle pushParams(InstructionList il, Method m) {
Type[] params = mtab.typesOfParams(m);
InstructionHandle pos = il.getStart();
for (int i = 0, param = 0; i < params.length; i++, param++) {
if (params[i].equals(Type.BOOLEAN) || params[i].equals(Type.BYTE)
|| params[i].equals(Type.SHORT) || params[i].equals(Type.CHAR)
|| params[i].equals(Type.INT)) {
il.insert(pos, new ILOAD(param));
} else if (params[i].equals(Type.FLOAT)) {
il.insert(pos, new FLOAD(param));
} else if (params[i].equals(Type.LONG)) {
il.insert(pos, new LLOAD(param));
param++;
} else if (params[i].equals(Type.DOUBLE)) {
il.insert(pos, new DLOAD(param));
param++;
} else {
il.insert(pos, new ALOAD(param));
}
}
return pos;
}
示例8: rewriteStore
import org.apache.bcel.generic.InstructionList; //导入依赖的package包/类
InstructionHandle rewriteStore(MethodGen m, InstructionList il,
InstructionHandle i, int maxLocals, String localClassName) {
LocalVariableInstruction curr = (LocalVariableInstruction) (i
.getInstruction());
Type type = mtab.getLocalType(m, curr, i.getPosition());
if (type == null) {
return i;
}
String name = mtab.getLocalName(m, curr, i.getPosition());
String fieldName = MethodTable.generatedLocalName(type, name);
i.setInstruction(new ALOAD(maxLocals));
i = i.getNext();
if (type.equals(Type.LONG) || type.equals(Type.DOUBLE)) {
il.insert(i, new DUP_X2());
il.insert(i, new POP());
} else {
il.insert(i, new SWAP());
}
i = il.insert(i, ins_f.createFieldAccess(localClassName, fieldName,
type, Constants.PUTFIELD));
return i;
}
示例9: rewriteLoad
import org.apache.bcel.generic.InstructionList; //导入依赖的package包/类
InstructionHandle rewriteLoad(MethodGen m, InstructionList il,
InstructionHandle i, int maxLocals, String localClassName) {
LocalVariableInstruction curr = (LocalVariableInstruction) (i
.getInstruction());
Type type = mtab.getLocalType(m, curr, i.getPosition());
if (type == null) {
return i;
}
String name = mtab.getLocalName(m, curr, i.getPosition());
String fieldName = MethodTable.generatedLocalName(type, name);
i.setInstruction(new ALOAD(maxLocals));
i = i.getNext();
i = il.insert(i, ins_f.createFieldAccess(localClassName, fieldName,
type, Constants.GETFIELD));
return i;
}
示例10: insertSync
import org.apache.bcel.generic.InstructionList; //导入依赖的package包/类
private void insertSync(Analyzer analyzer) throws MethodRewriteFailure {
d.log(1, "trying to insert sync statement(s)\n");
InstructionHandle[] ihs =
analyzer.proposeSyncInsertion(this, new Debug(d.turnedOn(), d.getStartLevel() + 2));
InstructionList instructionList = getInstructionList();
for (InstructionHandle ih : ihs) {
InstructionHandle syncInvoke =
instructionList.insert(ih,
new INVOKEVIRTUAL(indexSync));
InstructionHandle newTarget = instructionList.insert(syncInvoke,
spawnableCalls.get(0).getObjectReference().getInstruction());
// the same objectReference for every sync insertion
instructionList.redirectBranches(ih, newTarget);
d.log(2, "inserted sync()\n");
}
d.log(1, "inserted sync statement(s)\n");
}
示例11: callsSync
import org.apache.bcel.generic.InstructionList; //导入依赖的package包/类
private boolean callsSync() {
ConstantPoolGen cpg = getConstantPool();
InstructionList instructionList = getInstructionList();
InstructionHandle handle = instructionList.getStart();
while (handle != null) {
Instruction ins = handle.getInstruction();
if (ins instanceof INVOKEVIRTUAL) {
INVOKEVIRTUAL inv = (INVOKEVIRTUAL) ins;
if (inv.getMethodName(cpg).equals("sync") &&
inv.getSignature(cpg).equals("()V")) {
JavaClass cl = findMethodClass(inv, cpg);
if (cl != null && cl.getClassName().equals("ibis.cashmere.CashmereObject")) {
return true;
}
}
}
handle = handle.getNext();
}
return false;
}
示例12: getLoadInstruction
import org.apache.bcel.generic.InstructionList; //导入依赖的package包/类
private InstructionHandle getLoadInstruction(InstructionList il,
SpawnableCall spawnableCall) throws SyncInsertionProposalFailure {
InstructionHandle ih = spawnableCall.getInvokeInstruction();
while ((ih = ih.getNext()) != null) {
try {
LoadInstruction loadInstruction =
(LoadInstruction) (ih.getInstruction());
if (spawnableCall.storesIn(loadInstruction.getIndex(), ih)) {
return ih;
}
}
catch (ClassCastException e) {
}
}
throw new SyncInsertionProposalFailure();
}
示例13: createHelperMethodForDotClassCalls
import org.apache.bcel.generic.InstructionList; //导入依赖的package包/类
/**
* Creates a method class$(String) which is used
* during SomeClass.class instruction
*
* @param generatedClassName the instance class name
*/
protected void createHelperMethodForDotClassCalls(String generatedClassName) {
InstructionList il = new InstructionList();
MethodGen method = new MethodGen(Constants.ACC_STATIC, new ObjectType("java.lang.Class"), new Type[]{Type.STRING}, new String[]{"arg0"}, "class$", generatedClassName, il, constantsPool);
InstructionHandle ih0 = il.append(InstructionFactory.createLoad(Type.OBJECT, 0));
il.append(factory.createInvoke("java.lang.Class", "forName", new ObjectType("java.lang.Class"), new Type[]{Type.STRING}, Constants.INVOKESTATIC));
InstructionHandle ih4 = il.append(InstructionFactory.createReturn(Type.OBJECT));
InstructionHandle ih5 = il.append(InstructionFactory.createStore(Type.OBJECT, 1));
il.append(factory.createNew("java.lang.NoClassDefFoundError"));
il.append(InstructionConstants.DUP);
il.append(InstructionFactory.createLoad(Type.OBJECT, 1));
il.append(factory.createInvoke("java.lang.Throwable", "getMessage", Type.STRING, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
il.append(factory.createInvoke("java.lang.NoClassDefFoundError", "<init>", Type.VOID, new Type[]{Type.STRING}, Constants.INVOKESPECIAL));
il.append(InstructionConstants.ATHROW);
method.addExceptionHandler(ih0, ih4, ih5, new ObjectType("java.lang.ClassNotFoundException"));
method.setMaxStack();
method.setMaxLocals();
classGen.addMethod(method.getMethod());
il.dispose();
}
示例14: generateEqualsMethod
import org.apache.bcel.generic.InstructionList; //导入依赖的package包/类
private void generateEqualsMethod(String generatedClassName) {
/* public boolean equals(Object o) {
* return stubHelper.isEquals(this,o);
* }
*/
InstructionList il = new InstructionList();
MethodGen method = new MethodGen(Constants.ACC_PUBLIC, Type.BOOLEAN, new Type[]{Type.OBJECT}, new String[]{"arg0"}, "equals", generatedClassName, il, constantsPool);
il.append(InstructionFactory.createLoad(Type.OBJECT, 0));
il.append(factory.createFieldAccess(generatedClassName, "stubHelper", new ObjectType("org.codehaus.jremoting.client.StubHelper"), Constants.GETFIELD));
il.append(InstructionFactory.createLoad(Type.OBJECT, 0));
il.append(InstructionFactory.createLoad(Type.OBJECT, 1));
il.append(factory.createInvoke("org.codehaus.jremoting.client.StubHelper", "isEquals", Type.BOOLEAN, new Type[]{Type.OBJECT, Type.OBJECT}, Constants.INVOKEINTERFACE));
il.append(InstructionFactory.createReturn(Type.INT));
method.setMaxStack();
method.setMaxLocals();
classGen.addMethod(method.getMethod());
il.dispose();
}
示例15: handleCodeFragment
import org.apache.bcel.generic.InstructionList; //导入依赖的package包/类
/** Handles a single code fragment. */
private void handleCodeFragment(List<String> resultList,
ConstantPoolGen cpg, Code code) {
for (Instruction i : new InstructionList(code.getCode())
.getInstructions()) {
if (i instanceof NEW) {
NEW newInstruction = (NEW) i;
ObjectType ot = newInstruction.getLoadClassType(cpg);
if (ot == null) { // ot is primitive type
continue;
}
String newClassName = ot.getClassName();
if (!resultList.contains(newClassName)
&& !isBlacklisted(newClassName)) {
resultList.add(newClassName);
}
}
}
}