use of org.objectweb.asm.tree.IntInsnNode in project soot by Sable.
the class AsmMethodSource method convert.
private void convert() {
ArrayDeque<Edge> worklist = new ArrayDeque<Edge>();
for (LabelNode ln : trapHandlers.keySet()) {
if (checkInlineExceptionHandler(ln))
handleInlineExceptionHandler(ln, worklist);
else
worklist.add(new Edge(ln, new ArrayList<Operand>()));
}
worklist.add(new Edge(instructions.getFirst(), new ArrayList<Operand>()));
conversionWorklist = worklist;
edges = HashBasedTable.create(1, 1);
do {
Edge edge = worklist.pollLast();
AbstractInsnNode insn = edge.insn;
stack = edge.stack;
edge.stack = null;
do {
int type = insn.getType();
if (type == FIELD_INSN) {
convertFieldInsn((FieldInsnNode) insn);
} else if (type == IINC_INSN) {
convertIincInsn((IincInsnNode) insn);
} else if (type == INSN) {
convertInsn((InsnNode) insn);
int op = insn.getOpcode();
if ((op >= IRETURN && op <= RETURN) || op == ATHROW) {
break;
}
} else if (type == INT_INSN) {
convertIntInsn((IntInsnNode) insn);
} else if (type == LDC_INSN) {
convertLdcInsn((LdcInsnNode) insn);
} else if (type == JUMP_INSN) {
JumpInsnNode jmp = (JumpInsnNode) insn;
convertJumpInsn(jmp);
int op = jmp.getOpcode();
if (op == JSR)
throw new UnsupportedOperationException("JSR!");
if (op != GOTO) {
/* ifX opcode, i.e. two successors */
AbstractInsnNode next = insn.getNext();
addEdges(insn, next, Collections.singletonList(jmp.label));
} else {
addEdges(insn, jmp.label, null);
}
break;
} else if (type == LOOKUPSWITCH_INSN) {
LookupSwitchInsnNode swtch = (LookupSwitchInsnNode) insn;
convertLookupSwitchInsn(swtch);
LabelNode dflt = swtch.dflt;
addEdges(insn, dflt, swtch.labels);
break;
} else if (type == METHOD_INSN) {
convertMethodInsn((MethodInsnNode) insn);
} else if (type == INVOKE_DYNAMIC_INSN) {
convertInvokeDynamicInsn((InvokeDynamicInsnNode) insn);
} else if (type == MULTIANEWARRAY_INSN) {
convertMultiANewArrayInsn((MultiANewArrayInsnNode) insn);
} else if (type == TABLESWITCH_INSN) {
TableSwitchInsnNode swtch = (TableSwitchInsnNode) insn;
convertTableSwitchInsn(swtch);
LabelNode dflt = swtch.dflt;
addEdges(insn, dflt, swtch.labels);
} else if (type == TYPE_INSN) {
convertTypeInsn((TypeInsnNode) insn);
} else if (type == VAR_INSN) {
if (insn.getOpcode() == RET)
throw new UnsupportedOperationException("RET!");
convertVarInsn((VarInsnNode) insn);
} else if (type == LABEL) {
convertLabel((LabelNode) insn);
} else if (type == LINE) {
convertLine((LineNumberNode) insn);
} else if (type == FRAME) {
// we can ignore it
} else
throw new RuntimeException("Unknown instruction type: " + type);
} while ((insn = insn.getNext()) != null);
} while (!worklist.isEmpty());
conversionWorklist = null;
edges = null;
}
use of org.objectweb.asm.tree.IntInsnNode in project cassandra by apache.
the class MonitorMethodTransformer method writeInnerTryCatchSynchronized.
// alternative approach (with writeOuterUnsynchronized)
@SuppressWarnings("unused")
void writeInnerTryCatchSynchronized() {
access |= Opcodes.ACC_SYNCHRONIZED | Opcodes.ACC_SYNTHETIC;
name = baseName + "$catch";
Label start = new Label();
Label normal = new Label();
Label except = new Label();
Label end = new Label();
reset(start, end);
// must load self or class onto stack, and return value (if any)
maxStack = Math.max(maxLocalParams, returnCode == Opcodes.RETURN ? 1 : 2);
++maxLocals;
tryCatchBlocks.add(new TryCatchBlockNode(getLabelNode(start), getLabelNode(normal), getLabelNode(except), null));
instructions.add(getLabelNode(start));
int invokeCode = loadParamsAndReturnInvokeCode();
instructions.add(new MethodInsnNode(invokeCode, className, baseName + "$unsync", desc));
instructions.add(getLabelNode(normal));
invokePreMonitorExit();
instructions.add(new InsnNode(returnCode()));
instructions.add(getLabelNode(except));
instructions.add(new FrameNode(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" }));
instructions.add(new IntInsnNode(Opcodes.ASTORE, maxLocalParams));
invokePreMonitorExit();
instructions.add(new IntInsnNode(Opcodes.ALOAD, maxLocalParams));
instructions.add(new InsnNode(Opcodes.ATHROW));
instructions.add(getLabelNode(end));
methodWriterSink.writeSyntheticMethod(MONITOR, this);
}
use of org.objectweb.asm.tree.IntInsnNode in project cassandra by apache.
the class MonitorMethodTransformer method loadParamsAndReturnInvokeCode.
// TODO (cleanup): this _should_ be possible to determine purely from the method signature
int loadParamsAndReturnInvokeCode() {
if (isInstanceMethod)
instructions.add(new IntInsnNode(Opcodes.ALOAD, 0));
ListIterator<LocalVariableNode> it = localVariables.listIterator();
while (it.hasNext()) {
LocalVariableNode cur = it.next();
if (cur.index < maxLocalParams) {
if (!isInstanceMethod || cur.index > 0) {
int opcode;
switch(cur.desc.charAt(0)) {
case 'L':
case '[':
opcode = Opcodes.ALOAD;
break;
case 'J':
opcode = Opcodes.LLOAD;
break;
case 'D':
opcode = Opcodes.DLOAD;
break;
case 'F':
opcode = Opcodes.FLOAD;
break;
default:
opcode = Opcodes.ILOAD;
break;
}
instructions.add(new IntInsnNode(opcode, cur.index));
}
}
}
int invokeCode;
if (isInstanceMethod && (access & Opcodes.ACC_PRIVATE) != 0)
invokeCode = Opcodes.INVOKESPECIAL;
else if (isInstanceMethod)
invokeCode = Opcodes.INVOKEVIRTUAL;
else
invokeCode = Opcodes.INVOKESTATIC;
return invokeCode;
}
use of org.objectweb.asm.tree.IntInsnNode in project bytecode-viewer by Konloch.
the class RegexInsnFinder method getInsString.
private static String getInsString(AbstractInsnNode ain) {
String insnString = "";
switch(ain.getType()) {
case AbstractInsnNode.INT_INSN:
final IntInsnNode iin = (IntInsnNode) ain;
insnString += "{" + iin.operand + "}";
break;
case AbstractInsnNode.LDC_INSN:
final LdcInsnNode lin = (LdcInsnNode) ain;
insnString += "{" + lin.cst.toString().replace("}", "\\}") + "}";
break;
case AbstractInsnNode.VAR_INSN:
final VarInsnNode vin = (VarInsnNode) ain;
insnString += "_" + vin.var;
break;
case AbstractInsnNode.IINC_INSN:
final IincInsnNode iiin = (IincInsnNode) ain;
insnString += "{" + iiin.var + "," + iiin.incr + "}";
break;
case AbstractInsnNode.FIELD_INSN:
final FieldInsnNode fin = (FieldInsnNode) ain;
insnString += "{" + fin.desc + "," + fin.owner + "," + fin.name + "}";
break;
case AbstractInsnNode.METHOD_INSN:
final MethodInsnNode min = (MethodInsnNode) ain;
insnString += "{" + min.desc + "," + min.owner + "," + min.name + "}";
break;
case AbstractInsnNode.TYPE_INSN:
final TypeInsnNode tin = (TypeInsnNode) ain;
insnString += "{" + tin.desc + "}";
break;
case AbstractInsnNode.MULTIANEWARRAY_INSN:
final MultiANewArrayInsnNode manain = (MultiANewArrayInsnNode) ain;
insnString += "{" + manain.dims + "," + manain.desc + "}";
break;
}
return insnString;
}
use of org.objectweb.asm.tree.IntInsnNode in project maple-ir by LLVM-but-worse.
the class IntInsnNodeSerializer method deserialize.
@Override
public IntInsnNode deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObject = (JsonObject) json;
int opcode, operand;
opcode = jsonObject.get("opcode").getAsInt();
operand = jsonObject.get("operand").getAsInt();
return new IntInsnNode(opcode, operand);
}
Aggregations