本文整理了Java中org.objectweb.asm.tree.InsnList.get()
方法的一些代码示例,展示了InsnList.get()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。InsnList.get()
方法的具体详情如下:
包路径:org.objectweb.asm.tree.InsnList
类名称:InsnList
方法名:get
[英]Returns the instruction whose index is given. This method builds a cache of the instructions in this list to avoid scanning the whole list each time it is called. Once the cache is built, this method run in constant time. This cache is invalidated by all the methods that modify the list.
[中]返回给定索引的指令。此方法构建此列表中指令的缓存,以避免每次调用时扫描整个列表。构建缓存后,此方法将以恒定时间运行。所有修改列表的方法都会使此缓存无效。
代码示例来源:origin: kilim/kilim
public AbstractInsnNode getInstruction(int pos) {
return (AbstractInsnNode) flow.instructions.get(pos);
}
代码示例来源:origin: pxb1988/dex2jar
for (int i = ex.nextSetBit(0); i >= 0; i = ex.nextSetBit(i + 1)) {
mergeEx(frame, i);
stack.push(insnList.get(i));
代码示例来源:origin: org.ow2.asm/asm-tree
InsnListIterator(final int index) {
if (index == size()) {
nextInsn = null;
previousInsn = getLast();
} else {
nextInsn = get(index);
previousInsn = nextInsn.previousInsn;
}
}
代码示例来源:origin: jooby-project/jooby
@SuppressWarnings({"rawtypes", "unchecked"})
public void forEach() {
for (int i = 0; i < instructions.size(); i++) {
AbstractInsnNode it = instructions.get(i);
for (Entry<Predicate, Consumer> consumer : consumers.entrySet()) {
if (consumer.getKey().test(it)) {
consumer.getValue().accept(new Insn<>(method, it));
}
}
}
}
代码示例来源:origin: Meituan-Dianping/Robust
public byte[] transformCode(byte[] b1, String className) throws IOException {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
ClassReader cr = new ClassReader(b1);
ClassNode classNode = new ClassNode();
Map<String, Boolean> methodInstructionTypeMap = new HashMap<>();
cr.accept(classNode, 0);
final List<MethodNode> methods = classNode.methods;
for (MethodNode m : methods) {
InsnList inList = m.instructions;
boolean isMethodInvoke = false;
for (int i = 0; i < inList.size(); i++) {
if (inList.get(i).getType() == AbstractInsnNode.METHOD_INSN) {
isMethodInvoke = true;
}
}
methodInstructionTypeMap.put(m.name + m.desc, isMethodInvoke);
}
InsertMethodBodyAdapter insertMethodBodyAdapter = new InsertMethodBodyAdapter(cw, className, methodInstructionTypeMap);
cr.accept(insertMethodBodyAdapter, ClassReader.EXPAND_FRAMES);
return cw.toByteArray();
}
代码示例来源:origin: linkedin/parseq
private int findMethodCall(InsnList insns, LabelNode label) {
boolean foundLabel = false;
for (int i = 0; i < insns.size(); i++) {
AbstractInsnNode n = insns.get(i);
if (!foundLabel && n == label) {
foundLabel = true;
} else if (foundLabel && n.getOpcode() == Opcodes.INVOKEDYNAMIC) {
return i;
}
}
return -1;
}
代码示例来源:origin: kilim/kilim
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc,boolean itf) {
super.visitMethodInsn(opcode, owner, name, desc, itf);
// The only reason for adding to pausableMethods is to create a BB for pausable
// method call sites. If the class is already woven, we don't need this
// functionality.
if (!classFlow.isWoven) {
int methodStatus = detector.getPausableStatus(owner, name, desc);
if (methodStatus == Detector.PAUSABLE_METHOD_FOUND) {
MethodInsnNode min = (MethodInsnNode)instructions.get(instructions.size()-1);
pausableMethods.add(min);
}
}
}
代码示例来源:origin: pxb1988/dex2jar
String format = "%05d %-" + (method.maxStack + method.maxLocals + 6) + "s|%s";
for (int j = 0; j < method.instructions.size(); ++j) {
method.instructions.get(j).accept(mv);
代码示例来源:origin: konsoletyper/teavm
private void prepare(MethodNode method) {
InsnList instructions = method.instructions;
minLocal = 0;
if ((method.access & Opcodes.ACC_STATIC) != 0) {
minLocal = 1;
}
labelIndexes = new HashMap<>();
lineNumbers = new HashMap<>();
for (int i = 0; i < instructions.size(); ++i) {
AbstractInsnNode node = instructions.get(i);
if (node instanceof LabelNode) {
labelIndexes.put(((LabelNode) node).getLabel(), i);
}
if (node instanceof LineNumberNode) {
LineNumberNode lineNumberNode = (LineNumberNode) node;
lineNumbers.put(lineNumberNode.start.getLabel(), lineNumberNode.line);
}
}
for (LocalVariableNode localVar : method.localVariables) {
int location = labelIndexes.get(localVar.start.getLabel());
localVariableMap.computeIfAbsent(location, k -> new ArrayList<>()).add(localVar);
}
targetInstructions = new ArrayList<>(instructions.size());
targetInstructions.addAll(Collections.nCopies(instructions.size(), null));
basicBlocks.addAll(Collections.nCopies(instructions.size(), null));
stackBefore = new StackFrame[instructions.size()];
stackAfter = new StackFrame[instructions.size()];
}
代码示例来源:origin: konsoletyper/teavm
AbstractInsnNode insnNode = methodNode.instructions.get(i);
if (insnNode instanceof LabelNode) {
Label label = ((LabelNode) insnNode).getLabel();
代码示例来源:origin: pxb1988/dex2jar
AbstractInsnNode in = mn.instructions.get(j);
if (in.getType() != AbstractInsnNode.LINE && in.getType() != AbstractInsnNode.FRAME) {
if(in.getType()==AbstractInsnNode.LABEL){
代码示例来源:origin: apache/groovy
Object insn = method.instructions.get(j);
if (insn instanceof AbstractInsnNode) {
((AbstractInsnNode) insn).accept(mv);
代码示例来源:origin: kilim/kilim
flow.setLabel(newPos, l);
extraInsns.add(instructions.get(i).clone(labelCopyMap));
代码示例来源:origin: pxb1988/dex2jar
static void printAnalyzerResult(MethodNode method, Analyzer a, final PrintWriter pw)
throws IllegalArgumentException, IllegalAccessException {
Frame[] frames = a.getFrames();
Textifier t = new Textifier();
TraceMethodVisitor mv = new TraceMethodVisitor(t);
String format = "%05d %-" + (method.maxStack + method.maxLocals + 6) + "s|%s";
for (int j = 0; j < method.instructions.size(); ++j) {
method.instructions.get(j).accept(mv);
StringBuffer s = new StringBuffer();
Frame f = frames[j];
if (f == null) {
s.append('?');
} else {
for (int k = 0; k < f.getLocals(); ++k) {
s.append(getShortName(f.getLocal(k).toString()));
}
s.append(" : ");
for (int k = 0; k < f.getStackSize(); ++k) {
s.append(getShortName(f.getStack(k).toString()));
}
}
pw.printf(format, j, s, buf.get(t)); // mv.text.get(j));
}
for (int j = 0; j < method.tryCatchBlocks.size(); ++j) {
((TryCatchBlockNode) method.tryCatchBlocks.get(j)).accept(mv);
pw.print(" " + buf.get(t));
}
pw.println();
pw.flush();
}
代码示例来源:origin: pxb1988/dex2jar
stmts.addAll(preEmit);
for (int i = 0; i < insnList.size(); i++) {
AbstractInsnNode p = insnList.get(i);
if (access.get(i)) {
List<Stmt> es = emitStmts[i];
JvmFrame frame = frames[i];
if (parentCount[i] > 1 && frame != null && access.get(i)) {
AbstractInsnNode p = insnList.get(i);
LabelStmt labelStmt = getLabel((LabelNode) p);
List<AssignStmt> phis = new ArrayList<>();
代码示例来源:origin: kilim/kilim
public void restoreNonInstructionNodes() {
InsnList newinsns = new InsnList();
int sz = instructions.size();
for (int i = 0; i < sz; i++) {
LabelNode l = getLabelAt(i);
if (l != null) {
newinsns.add(l);
}
LineNumberNode ln = lineNumberNodes.get(i);
if (ln != null) {
newinsns.add(ln);
}
AbstractInsnNode ain = instructions.get(i);
newinsns.add(ain);
}
LabelNode l = getLabelAt(sz);
if (l != null) {
newinsns.add(l);
}
LineNumberNode ln = lineNumberNodes.get(sz);
if (ln != null) {
newinsns.add(ln);
}
super.instructions = newinsns;
}
代码示例来源:origin: konsoletyper/teavm
instructions.get(index).accept(methodVisitor);
stackAfter[index] = stack;
flushInstructions();
代码示例来源:origin: linkedin/parseq
int count = 0;
for (int i = 0; i < insns.size(); i++) {
AbstractInsnNode n = insns.get(i);
代码示例来源:origin: org.parboiled/parboiled-java
public void newControlFlowEdge(int instructionIndex, int successorIndex) {
AbstractInsnNode fromInsn = method.instructions.get(instructionIndex);
AbstractInsnNode toInsn = method.instructions.get(successorIndex);
if (fromInsn.getType() == AbstractInsnNode.LABEL || fromInsn.getType() == AbstractInsnNode.JUMP_INSN ||
toInsn.getType() == AbstractInsnNode.LABEL || toInsn.getType() == AbstractInsnNode.JUMP_INSN) {
additionalEdges.add(new Edge(fromInsn, toInsn));
}
}
代码示例来源:origin: com.android.tools.lint/lint-api
/**
* Finds the line number closest to the given method declaration
*
* @param node the method node to get a line number for
* @return the closest line number, or -1 if not known
*/
public static int findLineNumber(@NonNull MethodNode node) {
if (node.instructions != null && node.instructions.size() > 0) {
return findLineNumber(node.instructions.get(0));
}
return -1;
}
内容来源于网络,如有侵权,请联系作者删除!