Refine search
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++; } }
|| getOrCreateKotlinClass().test(node)) { String owner = Type.getReturnType(node.desc).getClassName(); AbstractInsnNode prev = node.getPrevious(); if (prev instanceof FieldInsnNode && ((MethodInsnNode) n).name.equals("toEnum")) { toType = loadType(loader, ((Type) cst).getClassName()); AbstractInsnNode next = node.getNext(); if (next instanceof MethodInsnNode) { String joobyKt = ((MethodInsnNode) next).owner; } else if (n instanceof TypeInsnNode) { TypeInsnNode typeInsn = (TypeInsnNode) n; if (typeInsn.getOpcode() == Opcodes.CHECKCAST) { return loadType(loader, typeInsn.desc);
static String getDescriptionForTypeInsnNode(TypeInsnNode typeInsnNode) { AbstractInsnNode nextInsn = typeInsnNode.getNext(); StringJoiner argsDesc = new StringJoiner(",", "(", ")"); while (nextInsn != null) { if (nextInsn instanceof LdcInsnNode) { argsDesc.add("_"); } else if (nextInsn.getOpcode() == Opcodes.DUP) { //ignore } else { break; } nextInsn = nextInsn.getNext(); } if (typeInsnNode.getOpcode() == Opcodes.NEW) { return "new " + Util.extractSimpleName(typeInsnNode.desc, "/") + argsDesc.toString(); } return ""; } }
LabelNode end = new LabelNode(); il.add(begin); il.add(new VarInsnNode(ALOAD, 2)); il.add(new TypeInsnNode(CHECKCAST, Type.getInternalName(DefaultSavedState.class))); il.add(new VarInsnNode(ASTORE, 3)); il.add(new VarInsnNode(ALOAD, 0)); // this il.add(new MethodInsnNode( il.add(new MethodInsnNode( il.add(new InsnNode(DUP)); il.add(new InsnNode(AALOAD)); if (i == 0 && context.isVararg()) { il.add(new TypeInsnNode(CHECKCAST, ASMUtils.arrayTypeFor(Object.class).getInternalName())); il.add(new InsnNode(SWAP)); il.add(new TypeInsnNode(NEW, Type.getInternalName(NonsuspendableFunctionException.class)));
instructions.add(new TypeInsnNode(Opcodes.ANEWARRAY, "java/lang/Object")); instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, remappedType)); break; case VOID: break; case Type.LONG: instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, Type.getInternalName(Long.class))); instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Long.class), "longValue", Type.getMethodDescriptor(Type.LONG_TYPE), false)); break; case Type.FLOAT: instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, Type.getInternalName(Float.class))); case Type.DOUBLE: instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, Type.getInternalName(Double.class))); case Type.BOOLEAN: instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, Type.getInternalName(Boolean.class))); case Type.INT: instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, Type.getInternalName(Integer.class))); case Type.SHORT: instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, Type.getInternalName(Short.class))); case Type.BYTE: instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, Type.getInternalName(Byte.class)));
@Override protected AbstractInsnNode transformMethodInsnNode(MethodNode mn, MethodInsnNode methodNode) { if (methodNode.owner.equals(Type.getInternalName(BooleanHelper.class))) return methodNode; if (!(methodNode.getPrevious().getOpcode() == Opcodes.ICONST_1 || methodNode.getPrevious().getOpcode() == Opcodes.ICONST_0)) { MethodInsnNode booleanHelperInvoke = new MethodInsnNode( Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), Type.getMethodDescriptor(Type.BOOLEAN_TYPE, new Type[] { Type.INT_TYPE })); mn.instructions.insertBefore(methodNode, booleanHelperInvoke); InsnList insnlist = new InsnList(); insnlist.add(booleanHelperPushParameter); insnlist.add(booleanHelperPopParameter); if (objectNeedCast) { TypeInsnNode tin = new TypeInsnNode( Opcodes.CHECKCAST, types[i].getInternalName());
int tranlocalVar = indexOfTranlocalVariable(methodNode.name, methodNode.desc); InsnList newInstructions = new InsnList(); newInstructions.add(startLabelNode); newInstructions.add(new LineNumberNode(debugInfo.beginLine, startLabelNode)); newInstructions.add(new InsnNode(DUP2_X1)); newInstructions.add(new InsnNode(POP2)); newInstructions.add(new InsnNode(SWAP)); originalFieldInsnNode.owner, originalFieldInsnNode.name); newInstructions.add(new VarInsnNode(ALOAD, tranlocalVar)); newInstructions.add(new VarInsnNode(ALOAD, tranlocalVar)); newInstructions.add(new VarInsnNode(ALOAD, transactionVar)); newInstructions.add(new TypeInsnNode(CHECKCAST, ownerMetadata.getTranlocalName())); newInstructions.add(new MethodInsnNode( newInstructions.add(new TypeInsnNode(CHECKCAST, ownerMetadata.getTranlocalName()));
private static InsnList throwExceptionsList(MethodNode methodNode, ClassNode classNode) { try { String runtimeException = Type.getInternalName(RuntimeException.class); Constructor<RuntimeException> constructor = RuntimeException.class.getConstructor(String.class); InsnList instructions = new InsnList(); instructions.add( new TypeInsnNode(Opcodes.NEW, runtimeException)); instructions.add(new InsnNode(Opcodes.DUP)); String className = classNode.name.replace('/', '.'); instructions.add(new LdcInsnNode("Method " + methodNode.name + " in " + className + " not mocked. " + "See http://g.co/androidstudio/not-mocked for details.")); instructions.add(new MethodInsnNode( Opcodes.INVOKESPECIAL, runtimeException, CONSTRUCTOR, Type.getType(constructor).getDescriptor(), false)); instructions.add(new InsnNode(Opcodes.ATHROW)); return instructions; } catch (NoSuchMethodException e) { throw new RuntimeException(e); } } }
private InsnList fixInstructions(MethodNode originalMethod, CloneMap cloneMap) { InsnList instructions = new InsnList(); for (int k = 0; k < originalMethod.instructions.size(); k++) { AbstractInsnNode originalInsn = originalMethod.instructions.get(k); switch (originalInsn.getOpcode()) { ClassMetadata ownerMetadata = metadataRepository.loadClassMetadata(classLoader, fieldInsn.owner); FieldMetadata fieldMetadata = ownerMetadata.getFieldMetadata(fieldInsn.name); Type originalFieldType = Type.getType(fieldMetadata.getDesc()); instructions.add(new InsnNode(DUP2_X1)); instructions.add(new InsnNode(POP2)); instructions.add(new InsnNode(SWAP)); String referenceName = Type.getType(referenceDesc).getInternalName(); instructions.add(new FieldInsnNode( if (originalFieldType.getSort() == Type.ARRAY || originalFieldType.getSort() == Type.OBJECT) { String objectDesc = Type.getDescriptor(Object.class); MethodInsnNode methodInsn = new MethodInsnNode( INVOKEVIRTUAL, referenceName, if (!originalFieldType.equals(Type.getType(Object.class))) { instructions.add(new TypeInsnNode(CHECKCAST, originalFieldType.getInternalName()));
static void box(final Type type, ListIterator<AbstractInsnNode> instructions) { if (type.getSort() == OBJECT || type.getSort() == ARRAY) { return; } if (Type.VOID_TYPE.equals(type)) { instructions.add(new InsnNode(Opcodes.ACONST_NULL)); } else { Type boxed = getBoxedType(type); instructions.add(new TypeInsnNode(Opcodes.NEW, boxed.getInternalName())); if (type.getSize() == 2) { // Pp -> Ppo -> oPpo -> ooPpo -> ooPp -> o instructions.add(new InsnNode(Opcodes.DUP_X2)); instructions.add(new InsnNode(Opcodes.DUP_X2)); instructions.add(new InsnNode(Opcodes.POP)); } else { // p -> po -> opo -> oop -> o instructions.add(new InsnNode(Opcodes.DUP_X1)); instructions.add(new InsnNode(Opcodes.SWAP)); } instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, boxed.getInternalName(), "<init>", "(" + type.getDescriptor() + ")V", false)); } }
MethodNode methodNode = methodWrapper.methodNode; for (AbstractInsnNode insn : methodNode.instructions.toArray()) { if (insn instanceof MethodInsnNode) { MethodInsnNode methodInsnNode = (MethodInsnNode) insn; if (!"<init>".equals(methodInsnNode.name)) { boolean isStatic = (methodInsnNode.getOpcode() == INVOKESTATIC); String newSig = isStatic ? methodInsnNode.desc : methodInsnNode.desc.replace("(", "(Ljava/lang/Object;"); Type returnType = Type.getReturnType(methodInsnNode.desc); Type[] args = Type.getArgumentTypes(newSig); for (int i = 0; i < args.length; i++) { Type arg = args[i]; if (arg.getSort() == Type.OBJECT) { args[i] = Type.getType("Ljava/lang/Object;"); ); methodNode.instructions.set(insn, indy); if (returnType.getSort() == Type.ARRAY) { methodNode.instructions.insert(indy, new TypeInsnNode(CHECKCAST, returnType.getInternalName()));
result.instructions = new InsnList(); result.instructions.add(startLabelNode); result.instructions.add(new VarInsnNode(ALOAD, 0)); result.instructions.add(new VarInsnNode(ALOAD, transactionVarIndex)); getDescriptor(AlphaTranlocal.class)); result.instructions.add(new MethodInsnNode( INVOKEINTERFACE, getInternalName(AlphaTransaction.class), "openForRead", openForReadDesc)); result.instructions.add(new TypeInsnNode( CHECKCAST, tranlocalName)); MethodInsnNode invokeInsn = new MethodInsnNode( getInvokeOpcode(methodNode), classNode.name, int returnOpCode = Type.getReturnType(methodNode.desc).getOpcode(IRETURN); result.instructions.add(new InsnNode(returnOpCode));
int foundcon = -1; for(int i=0; i<l.size(); i++) AbstractInsnNode n = l.get(i); +SUtil.firstToUpperCase(name), Type.getMethodDescriptor(Type.VOID_TYPE), null, null); mnode.instructions.add(clone); cur = cur.getNext(); init.add(new VarInsnNode(Opcodes.ALOAD, 0)); init.add(new LdcInsnNode(Type.getType("L"+iclname+";"))); init.add(new LdcInsnNode(args.length)); init.add(new TypeInsnNode(Opcodes.ANEWARRAY, "java/lang/Class")); for(int i=0; i<args.length; i++) init.add( new LdcInsnNode(args.length)); init.add(new TypeInsnNode(Opcodes.ANEWARRAY, "java/lang/Object")); for(int i=0; i<args.length; i++) init.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "jadex/bdiv3/features/impl/BDIAgentFeature", "addInitArgs", "(Ljava/lang/Object;Ljava/lang/Class;[Ljava/lang/Class;[Ljava/lang/Object;)V")); l.insertBefore(l.get(foundcon+1), init);
MethodNode methodNode = methodWrapper.methodNode; for (AbstractInsnNode insn : methodNode.instructions.toArray()) { if (insn instanceof MethodInsnNode && insn.getOpcode() != INVOKESPECIAL) { MethodInsnNode methodInsnNode = (MethodInsnNode) insn; boolean isStatic = (methodInsnNode.getOpcode() == Opcodes.INVOKESTATIC); Type returnType = Type.getReturnType(methodInsnNode.desc); int opcode = (isStatic) ? 0 : 1; encrypt(methodInsnNode.name, 2993), encrypt(methodInsnNode.desc, 8372)); methodNode.instructions.set(insn, indy); if (returnType.getSort() == Type.ARRAY) { methodNode.instructions.insert(indy, new TypeInsnNode(CHECKCAST, returnType.getInternalName()));
InsnList extraInstructions = new InsnList(); for (FieldNode fieldNode : (List<FieldNode>) classNode.fields) { FieldMetadata fieldMetadata = classMetadata.getFieldMetadata(fieldNode.name); extraInstructions.add(new VarInsnNode(ALOAD, 0)); String referenceName = Type.getType(referenceDesc).getInternalName(); extraInstructions.add(new TypeInsnNode(NEW, referenceName)); extraInstructions.add(new InsnNode(DUP)); extraInstructions.add( new MethodInsnNode(INVOKESPECIAL, referenceName, "<init>", "()V")); extraInstructions.add(new FieldInsnNode(
node.access = ACC_STATIC; node.name = Constants.STATIC_INIT_METHOD; node.desc = Type.getMethodDescriptor(Type.getType(void.class)); 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();
if (an.desc.equals(PAR_NEST.getDescriptor())) { execMethod.maxLocals++; InsnList preamble = new InsnList(); preamble.add(new TypeInsnNode(NEW, ARRAY_LIST.getInternalName())); preamble.add(new InsnNode(DUP)); preamble.add(new MethodInsnNode(INVOKESPECIAL, ARRAY_LIST.getInternalName(), "<init>", "()V")); preamble.add(new VarInsnNode(ASTORE, listIndex)); Iterator<AbstractInsnNode> execInstIter = execMethod.instructions.iterator(); midterm.add(new VarInsnNode(ASTORE, localVariablesIdx.get(callablesManipulated))); midterm.add(new VarInsnNode(ALOAD, listIndex)); midterm.add(new VarInsnNode(ALOAD, localVariablesIdx.get(callablesManipulated))); midterm.add(new MethodInsnNode(INVOKEVIRTUAL, ARRAY_LIST.getInternalName(), "add", "(Ljava/lang/Object;)Z")); if (methodInstr.getNext().getOpcode() != POP) { midterm.add(new InsnNode(POP)); finish.add(new MethodInsnNode(INVOKEVIRTUAL, cn.name, combinerMethod.name, combinerMethod.desc)); finish.add(new InsnNode(ARETURN));
Type ret = Type.getReturnType(mn.desc); if(ret.getClassName().equals("byte")) nl.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "jadex/bdiv3/features/impl/BDIAgentFeature", "getAbstractBeliefValue", "(Ljadex/bridge/IInternalAccess;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Object;")); nl.add(new TypeInsnNode(Opcodes.CHECKCAST, "java/lang/Number")); nl.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Number", "intValue", "()I")); nl.add(new InsnNode(Opcodes.I2B)); nl.add(new InsnNode(Opcodes.IRETURN)); nl.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "jadex/bdiv3/features/impl/BDIAgentFeature", "getAbstractBeliefValue", "(Ljadex/bridge/IInternalAccess;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Object;")); nl.add(new TypeInsnNode(Opcodes.CHECKCAST, "java/lang/Number")); nl.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Number", "intValue", "()I")); nl.add(new InsnNode(Opcodes.I2S)); nl.add(new TypeInsnNode(Opcodes.CHECKCAST, "java/lang/Number")); nl.add(new TypeInsnNode(Opcodes.CHECKCAST, "java/lang/Character")); nl.add(new TypeInsnNode(Opcodes.CHECKCAST, "java/lang/Boolean")); nl.add(new TypeInsnNode(Opcodes.CHECKCAST, "java/lang/Number")); nl.add(new TypeInsnNode(Opcodes.CHECKCAST, "java/lang/Number")); nl.add(new TypeInsnNode(Opcodes.CHECKCAST, "java/lang/Number")); nl.add(new TypeInsnNode(Opcodes.CHECKCAST, ret.getInternalName()));
if(name.indexOf(Type.getInternalName(IBDIAgent.class))!=-1) MethodNode mnode = new MethodNode(Opcodes.ACC_PUBLIC, m.getName(), Type.getMethodDescriptor(m), null, null); Type ret = Type.getReturnType(mnode.desc); InsnList nl = new InsnList(); nl.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "jadex/bdiv3/features/impl/BDIAgentFeature", "getBDIAgentFeature", "(Ljadex/bridge/IInternalAccess;)Ljadex/bdiv3/features/IBDIAgentFeature;", false)); nl.add(new VarInsnNode(Opcodes.ILOAD, i+cnt)); nl.add(new VarInsnNode(Opcodes.LLOAD, i+cnt++)); nl.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "jadex/bdiv3/features/IBDIAgentFeature", mnode.name, mnode.desc, true)); nl.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "jadex/bridge/IInternalAccess", mnode.name, mnode.desc, true)); nl.add(new InsnNode(Opcodes.IRETURN)); nl.add(new InsnNode(Opcodes.LRETURN)); nl.add(new InsnNode(Opcodes.FRETURN)); String t = ret.toString().length()>1? ret.getInternalName(): ret.toString(); nl.add(new TypeInsnNode(Opcodes.CHECKCAST, t)); nl.add(new InsnNode(Opcodes.ARETURN));
ListIterator<AbstractInsnNode> iter = methodNode.instructions.iterator(); wInstructions.add(ins); if(typeIns.getOpcode() == Opcodes.NEW || typeIns.getOpcode() == Opcodes.NEWARRAY) final Type returnType = Type.getReturnType(methodNode.desc); if(returnType.equals(Type.VOID_TYPE)) final Type[] argTypes = Type.getArgumentTypes(methodNode.desc); for(int i = 0; i < argTypes.length; i++) wInstructions.add(new InsnNode(Opcodes.ACONST_NULL)); wInstructions.add(new VarInsnNode(Opcodes.ASTORE, varReturnValue)); wInstructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); var++; wInstructions.add(new FrameNode(Opcodes.F_SAME1, 0 ,null, 1, new Object[] {"java/lang/Throwable"})); wInstructions.add(new VarInsnNode(Opcodes.ASTORE, --var)); wInstructions.add(new VarInsnNode(Opcodes.ALOAD, var)); wInstructions.add(new InsnNode(Opcodes.ATHROW)); wInstructions.add(new InsnNode(Opcodes.RETURN));