IrMethod convert0(String owner, MethodNode methodNode) throws AnalyzerException { this.methodNode = methodNode; target = populate(owner, methodNode); if (methodNode.instructions.size() == 0) { return target; BitSet[] exBranch = new BitSet[insnList.size()]; parentCount = new int[insnList.size()]; BitSet handlers = new BitSet(insnList.size()); if (methodNode.tryCatchBlocks != null) { for (TryCatchBlockNode tcb : methodNode.tryCatchBlocks) { target.traps.add(new Trap(getLabel(tcb.start), getLabel(tcb.end), new LabelStmt[]{getLabel(tcb.handler)}, new String[]{tcb.type == null ? null : Type.getObjectType(tcb.type).getDescriptor()})); int handlerIdx = insnList.indexOf(tcb.handler); handlers.set(handlerIdx); BitSet x = exBranch[insnList.indexOf(p)]; if (x == null) { x = exBranch[insnList.indexOf(p)] = new BitSet(insnList.size()); frames = new JvmFrame[insnList.size()]; emitStmts = new ArrayList[insnList.size()]; BitSet access = new BitSet(insnList.size()); for (int i = 0; i < insnList.size(); i++) { AbstractInsnNode p = insnList.get(i); if (access.get(i)) { List<Stmt> es = emitStmts[i];
void writeSysCall(String internalClassName, int INVOKE_TYPE, String method, Class returnClazz, Class... paramClasses) { Type[] args = new Type[paramClasses.length]; if (INVOKE_TYPE == INVOKEVIRTUAL || INVOKE_TYPE == INVOKEINTERFACE) stackPop(); // this for (int i = 0; i < args.length; i++) { args[i] = Type.getType(paramClasses[i]); stackPop(); } code.add(new MethodInsnNode( INVOKE_TYPE, internalClassName, method, Type.getMethodDescriptor(Type.getType(returnClazz), args), false )); if (returnClazz != void.class) { stackPush(null, StackItem.Type.valueOf(returnClazz)); } }
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; }
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; }
private void initParentCount(int[] parentCount) { parentCount[0] = 1; for (AbstractInsnNode p = insnList.getFirst(); p != null; p = p.getNext()) { if (p.getType() == AbstractInsnNode.JUMP_INSN) { JumpInsnNode jump = (JumpInsnNode) p; parentCount[insnList.indexOf(jump.label)]++; int op = p.getOpcode(); if (op == Opcodes.TABLESWITCH || op == Opcodes.LOOKUPSWITCH) { if (op == Opcodes.TABLESWITCH) { TableSwitchInsnNode tsin = (TableSwitchInsnNode) p; for (LabelNode label : tsin.labels) { parentCount[insnList.indexOf(label)]++; parentCount[insnList.indexOf(tsin.dflt)]++; } else { LookupSwitchInsnNode lsin = (LookupSwitchInsnNode) p; for (LabelNode label : lsin.labels) { parentCount[insnList.indexOf(label)]++; parentCount[insnList.indexOf(lsin.dflt)]++; AbstractInsnNode next = p.getNext(); if(next!=null) { parentCount[insnList.indexOf(p.getNext())]++;
public void writePushParameters(Collection<Memory> memories) { writePushSmallInt(memories.size()); code.add(new TypeInsnNode(ANEWARRAY, Type.getInternalName(Memory.class))); stackPop(); stackPush(Memory.Type.REFERENCE); int i = 0; for (Memory param : memories) { writePushDup(); writePushSmallInt(i); writePushMemory(param); writePopBoxing(true, false); code.add(new InsnNode(AASTORE)); stackPop(); stackPop(); stackPop(); i++; } }
private static InsnList newByteString(ByteString value) { InsnList il = new InsnList(); il.add(new LdcInsnNode(value.toRawString())); il.add(new MethodInsnNode(INVOKESTATIC, Type.getInternalName(ByteString.class), "fromRaw", Type.getMethodDescriptor( Type.getType(ByteString.class), Type.getType(String.class)), false)); return il; }
private void insertDoubleComparisonL(AbstractInsnNode position, InsnList list) { MethodInsnNode get = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "doubleSubL", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.DOUBLE_TYPE, Type.DOUBLE_TYPE }), false); list.insert(position, get); list.remove(position); }
public void writePushBooleanAsMemory(boolean value) { if (value) code.add(new FieldInsnNode( GETSTATIC, Type.getInternalName(Memory.class), "TRUE", Type.getDescriptor(Memory.class) )); else code.add(new FieldInsnNode( GETSTATIC, Type.getInternalName(Memory.class), "FALSE", Type.getDescriptor(Memory.class) )); stackPush(Memory.Type.REFERENCE); }
node.instructions.add(new TypeInsnNode(ANEWARRAY, Type.getInternalName(TraceInfo.class))); expressionCompiler.stackPush(Memory.Type.REFERENCE); expressionCompiler.writePushCreateTraceInfo(traceInfo.getStartLine(), traceInfo.getStartPosition()); node.instructions.add(new InsnNode(AASTORE)); expressionCompiler.stackPop(); expressionCompiler.stackPop(); node.instructions.add(new TypeInsnNode(ANEWARRAY, Type.getInternalName(Memory.class))); expressionCompiler.stackPush(Memory.Type.REFERENCE); expressionCompiler.writePopBoxing(true, false); node.instructions.add(new InsnNode(AASTORE)); expressionCompiler.stackPop(); expressionCompiler.stackPop(); node.instructions.add(new TypeInsnNode(ANEWARRAY, Type.getInternalName(Memory[].class))); expressionCompiler.stackPush(Memory.Type.REFERENCE); node.instructions.add(new InsnNode(AASTORE)); expressionCompiler.stackPop(); expressionCompiler.stackPop(); node.instructions.add(new InsnNode(RETURN)); methodCompiler.writeFooter();
code.add(new FieldInsnNode( GETSTATIC, Type.getInternalName(Memory.class), "UNDEFINED", Type.getDescriptor(Memory.class) )); } else if (memory instanceof NullMemory) { code.add(new FieldInsnNode( GETSTATIC, Type.getInternalName(Memory.class), "NULL", Type.getDescriptor(Memory.class) )); } else if (memory instanceof FalseMemory) { return; } else if (memory instanceof ReferenceMemory) { code.add(new TypeInsnNode(NEW, Type.getInternalName(ReferenceMemory.class))); code.add(new InsnNode(DUP)); code.add(new MethodInsnNode(INVOKESPECIAL, Type.getInternalName(ReferenceMemory.class), Constants.INIT_METHOD, "()V", false)); } else if (memory instanceof ArrayMemory) { ArrayMemory array = (ArrayMemory) memory; switch (memory.type) { case INT: { code.add(new LdcInsnNode(memory.toLong())); type = Memory.Type.INT; code.add(new LdcInsnNode(memory.toDouble())); type = Memory.Type.DOUBLE; code.add(new LdcInsnNode(memory.toString())); type = Memory.Type.STRING;
public void process(ParserClassNode classNode, RuleMethod method) throws Exception { checkArgNotNull(classNode, "classNode"); checkArgNotNull(method, "method"); // replace all method code with a simple call to the super method method.instructions.clear(); method.instructions.add(new VarInsnNode(ALOAD, 0)); method.instructions.add(createArgumentLoaders(method.desc)); method.instructions.add(new MethodInsnNode(INVOKESPECIAL, classNode.getParentType().getInternalName(), method.name, method.desc, classNode.isInterface())); method.instructions.add(new InsnNode(ARETURN)); }
public static InsnList getClassConstantReference(Type type, int majorVersion) { InsnList il = new InsnList(); if (majorVersion >= Opcodes.V1_5) { il.add(new LdcInsnNode(type)); } else { String fullyQualifiedName = type.getInternalName().replaceAll("/", "."); il.add(new LdcInsnNode(fullyQualifiedName)); il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Class", "forName", "(Ljava/lang/String;)Ljava/lang/Class;", false)); } return il; }
public void writePutStatic(String name, Class fieldClass) { code.add(new FieldInsnNode( PUTSTATIC, method.clazz.node.name, name, Type.getDescriptor(fieldClass) )); stackPop(); }
private void generateMarkerCall(InsnList instructions, AbstractInsnNode ret, String call) { instructions.insertBefore(ret, new MethodInsnNode(INVOKEINTERFACE, Types.RULE.getInternalName(), call, "()" + Types.RULE.getDescriptor(), true)); }
/** * */ protected void replaceNativeSetter(String iclname, MethodNode mn, String belname) { Type arg = Type.getArgumentTypes(mn.desc)[0]; mn.access = mn.access - Opcodes.ACC_NATIVE; InsnList nl = new InsnList(); nl.add(new VarInsnNode(Opcodes.ALOAD, 0)); nl.add(new FieldInsnNode(Opcodes.GETFIELD, iclname, AGENT_FIELD_NAME, "Ljadex/bridge/IInternalAccess;")); nl.add(new VarInsnNode(Opcodes.ALOAD, 0)); nl.add(new FieldInsnNode(Opcodes.GETFIELD, iclname, GLOBALNAME_FIELD_NAME, "Ljava/lang/String;")); nl.add(new LdcInsnNode(belname)); makeObject(nl, arg); nl.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "jadex/bdiv3/features/impl/BDIAgentFeature", "setAbstractBeliefValue", "(Ljadex/bridge/IInternalAccess;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;)V")); nl.add(new InsnNode(Opcodes.RETURN)); mn.instructions = nl; }
private void addGetMethodInvocation(InsnList il) { il.add(TreeInstructions.getPushInstruction(this.methodArguments.length)); il.add(new TypeInsnNode(Opcodes.ANEWARRAY, "java/lang/Class")); int parameterClassesIndex = getFistAvailablePosition(); il.add(new VarInsnNode(Opcodes.ASTORE, parameterClassesIndex)); this.mn.maxLocals++; for (int i = 0; i < this.methodArguments.length; i++) { il.add(new VarInsnNode(Opcodes.ALOAD, parameterClassesIndex)); il.add(TreeInstructions.getPushInstruction(i)); il.add(TreeInstructions.getClassReferenceInstruction(methodArguments[i], cn.version & 0xFFFF)); il.add(new InsnNode(Opcodes.AASTORE)); } il.add(TreeInstructions.getClassConstantReference(this.classType, cn.version & 0xFFFF)); il.add(new LdcInsnNode(this.mn.name)); il.add(new VarInsnNode(Opcodes.ALOAD, parameterClassesIndex)); il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "org/brutusin/instrumentation/utils/Helper", "getSource", "(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/Object;", false)); }
private static InsnList generateRunViewConstructorInstructions(final MethodInsnNode methodInsn) { final InsnList list = new InsnList(); // stack: this list.add(new InsnNode(DUP)); // stack: this, this list.add(new MethodInsnNode(INVOKEVIRTUAL, methodInsn.owner, VIEW_CONSTRUCTOR_NAME, "()V")); // stack: this return list; }
@Override public void visit(LoadConst.Int node) { if (context.compilerSettings.constCaching()) { il.add(loadCachedConst(node.value())); } else { il.add(ASMUtils.loadLong(node.value())); il.add(BoxedPrimitivesMethods.box(Type.LONG_TYPE, Type.getType(Long.class))); } il.add(new VarInsnNode(ASTORE, slot(node.dest()))); }