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++; } }
return null; return loadType(loader, ((Type) cst).getClassName()); switch (insn.getOpcode()) { case Opcodes.ICONST_0: return 0;
instructions.add(new InsnNode(Opcodes.DUP_X1)); // A B [] C [] instructions.add(new InsnNode(Opcodes.SWAP)); // A B [] [] C instructions.add(new LdcInsnNode(i)); // A B [] [] C 2 instructions.add(new InsnNode(Opcodes.SWAP)); // A B [] [] 2 C instructions.add(new InsnNode(Opcodes.AASTORE)); // A B [(C)] } else if (argWidth == 2) { // A B _C_ [] instructions.add(new InsnNode(Opcodes.DUP_X2)); // A B [] _C_ [] instructions.add(new InsnNode(Opcodes.DUP_X2)); // A B [] [] _C_ [] instructions.add(new InsnNode(Opcodes.POP)); // A B [] [] _C_ instructions.add(new LdcInsnNode(i)); // A B [] [] (C) 2 instructions.add(new InsnNode(Opcodes.SWAP)); // A B [] [] 2 (C) instructions.add(new InsnNode(Opcodes.AASTORE)); // A B [(C)] instructions.add(new InsnNode(Opcodes.ACONST_NULL)); // [] null instructions.add(new InsnNode(Opcodes.SWAP)); // null [] instructions.add(new InsnNode(Opcodes.DUP_X2)); // signature instance [] signature instructions.add(new InsnNode(Opcodes.POP)); // signature instance [] instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, remappedType)); break; case VOID: instructions.add(new InsnNode(Opcodes.POP)); 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));
argumentTypes[i++] = Type.getType(type); constructor.desc = Type.getMethodDescriptor( Type.getType(void.class), argumentTypes ); constructor.instructions.add(new MethodInsnNode( INVOKESPECIAL, node.superName, constructor.instructions.add(new InsnNode(RETURN)); node.methods.add(constructor);
result.instructions = new InsnList(); result.instructions.add(startLabelNode); result.instructions.add(new VarInsnNode(ALOAD, 0)); for (Type argType : getArgumentTypes(methodNode.desc)) { VarInsnNode loadInsn = new VarInsnNode(argType.getOpcode(ILOAD), loadIndex); result.instructions.add(loadInsn); loadIndex += argType.getSize(); result.instructions.add(new VarInsnNode(ALOAD, transactionVarIndex)); getDescriptor(AlphaTranlocal.class)); MethodInsnNode invokeInsn = new MethodInsnNode( getInvokeOpcode(methodNode), classNode.name, int returnOpCode = Type.getReturnType(methodNode.desc).getOpcode(IRETURN); result.instructions.add(new InsnNode(returnOpCode));
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)); } }
protected InsnList resumptionHandler(LabelNode label) { InsnList il = new InsnList(); il.add(label); il.add(ASMUtils.frameSame1(UnresolvedControlThrowable.class)); il.add(createSnapshot()); // register snapshot with the control exception il.add(new MethodInsnNode( INVOKEVIRTUAL, Type.getInternalName(UnresolvedControlThrowable.class), "resolve", Type.getMethodType( Type.getType(ResolvedControlThrowable.class), Type.getType(Resumable.class), Type.getType(Object.class)).getDescriptor(), false)); // rethrow il.add(new InsnNode(ATHROW)); return il; }
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(
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; }
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 InsnNode(AASTORE)); expressionCompiler.stackPop(); expressionCompiler.stackPop(); expressionCompiler.writePutStatic("$CALL_CLASS_CACHE", ClassCallCache.class); node.instructions.add(new InsnNode(RETURN)); methodCompiler.writeFooter();
InsnList initTranlocal = new InsnList(); initTranlocal.add(new VarInsnNode(ALOAD, transactionVar)); initTranlocal.add(new VarInsnNode(ALOAD, 0)); getDescriptor(AlphaTransactionalObject.class), getDescriptor(AlphaTranlocal.class)); initTranlocal.add(new MethodInsnNode( INVOKEINTERFACE, getInternalName(AlphaTransaction.class), "openForConstruction", openForConstructionDesc)); initTranlocal.add(new InsnNode(POP)); result.instructions.insertBefore(result.instructions.get(indexOfFirst), initTranlocal);
Type[] args = Type.getArgumentTypes(mn.desc); InsnList nl = new InsnList(); nl.add(new VarInsnNode(Opcodes.ALOAD, 0)); // loads the object nl.add(new FieldInsnNode(Opcodes.GETFIELD, iclname, AGENT_FIELD_NAME, Type.getDescriptor(IInternalAccess.class))); nl.add(new LdcInsnNode(belname)); nl.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "jadex/bdiv3/features/impl/BDIAgentFeature", "unobserveValue", nl.add(new InsnNode(Opcodes.ACONST_NULL)); nl.add(new InsnNode(Opcodes.ACONST_NULL)); // oldvalue ? nl.add(new InsnNode(Opcodes.ACONST_NULL)); // no index/key nl.add(new VarInsnNode(Opcodes.ALOAD, 0)); // loads the agent object nl.add(new FieldInsnNode(Opcodes.GETFIELD, iclname, AGENT_FIELD_NAME, Type.getDescriptor(IInternalAccess.class))); nl.add(new LdcInsnNode(belname)); nl.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "jadex/bdiv3/features/impl/BDIAgentFeature", "createChangeEvent",
private InsnList instantiationInsns() { InsnList il = new InsnList(); ClassNameTranslator tr = context.classNameTranslator; Type fnType = ASMUtils.typeForClassName(id.toClassName(tr)); il.add(new TypeInsnNode(NEW, fnType.getInternalName())); il.add(new InsnNode(DUP)); for (AbstractVar var : upvals) { if (var instanceof UpVar) { il.add(loadUpvalueRef((UpVar) var)); } else { Var v = (Var) var; assert (context.types.isReified(v)); il.add(new VarInsnNode(ALOAD, slot(v))); il.add(new TypeInsnNode(CHECKCAST, Type.getInternalName(Variable.class))); } } Type[] ctorArgTypes = new Type[upvals.size()]; Arrays.fill(ctorArgTypes, Type.getType(Variable.class)); il.add(ASMUtils.ctor(fnType, ctorArgTypes)); return il; }
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;
ACC_PUBLIC, "<init>", methodType().getDescriptor(), null, null); LabelNode end = new LabelNode(); node.localVariables.add(new LocalVariableNode("this", context.thisClassType().getDescriptor(), null, begin, end, 0)); il.add(begin); String name = context.getUpvalueFieldName(uv); il.add(new VarInsnNode(ALOAD, 0)); // this il.add(new VarInsnNode(ALOAD, 1 + idx)); // upvalue #i il.add(new FieldInsnNode(PUTFIELD, context.thisClassType().getInternalName(), il.add(new InsnNode(RETURN)); il.add(end);
@Override protected AbstractInsnNode transformInsnNode(MethodNode mn, InsnNode insnNode) { //String desc = DescriptorMapping.getInstance().getMethodDesc(className, mn.name, mn.desc); Type returnType = Type.getReturnType(mn.desc); if (!returnType.equals(Type.BOOLEAN_TYPE)) { return insnNode; } if (insnNode.getOpcode() == Opcodes.IRETURN) { BooleanTestabilityTransformation.logger.debug("Inserting conversion before IRETURN of " + this.booleanTestabilityTransformation.className + "." + mn.name); // If this function cannot be transformed, add a call to convert the value to a proper Boolean MethodInsnNode n = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "intToBoolean", Type.getMethodDescriptor(Type.BOOLEAN_TYPE, new Type[] { Type.INT_TYPE })); mn.instructions.insertBefore(insnNode, n); } return insnNode; } }
@SuppressWarnings({"unchecked"}) private void createConstuctor(ParserClassNode classNode, MethodNode constructor) { MethodNode newConstructor = new MethodNode(ACC_PUBLIC, constructor.name, constructor.desc, constructor.signature, (String[]) constructor.exceptions.toArray(new String[constructor.exceptions.size()])); InsnList instructions = newConstructor.instructions; instructions.add(new VarInsnNode(ALOAD, 0)); instructions.add(createArgumentLoaders(constructor.desc)); instructions.add(new MethodInsnNode(INVOKESPECIAL, classNode.getParentType().getInternalName(), "<init>", constructor.desc, classNode.isInterface())); instructions.add(new InsnNode(RETURN)); classNode.methods.add(newConstructor); }
private static MethodNode generateStaticCallableCreation(ClassNode classNode, String className, String callableClass, MethodNode mn) { MethodNode staticMethod = new MethodNode(V1_6, mn.access | ACC_STATIC, mn.name + "$static$callable$creator", "(L" + className + ";" + mn.desc.substring(1, mn.desc.indexOf(')') + 1) + "L" + callableClass + ";", mn.signature, new String[0]); InsnList content = new InsnList(); content.add(new TypeInsnNode(NEW, callableClass)); content.add(new InsnNode(DUP)); int pos = 0; // Push the instance of the class being modified (first argument of this // synthetized method) content.add(new VarInsnNode(ALOAD, pos++)); // Push arguments of original method on the stack for callable creation for (Type t : Type.getArgumentTypes(mn.desc)) { content.add(new VarInsnNode(t.getOpcode(ILOAD), pos)); pos += t.getSize(); } // Instantiate the callable content.add(new MethodInsnNode(INVOKESPECIAL, callableClass, "<init>", getCallableCtorDesc(className, mn))); // Return it from the static method content.add(new InsnNode(ARETURN)); staticMethod.instructions.add(content); return staticMethod; }
/** * */ 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 createVarFieldArray(RuleMethod method, InsnList instructions, AbstractInsnNode ret) { int count = method.getLocalVarVariables().size(); // stack: instructions.insertBefore(ret, new IntInsnNode(BIPUSH, count)); // stack: <length> instructions.insertBefore(ret, new TypeInsnNode(ANEWARRAY, VAR.getInternalName())); // stack: <array> for (int i = 0; i < count; i++) { LocalVariableNode var = method.getLocalVarVariables().get(i); // stack: <array> instructions.insertBefore(ret, new InsnNode(DUP)); // stack: <array> :: <array> instructions.insertBefore(ret, new IntInsnNode(BIPUSH, i)); // stack: <array> :: <array> :: <index> instructions.insertBefore(ret, new VarInsnNode(ALOAD, var.index)); // stack: <array> :: <array> :: <index> :: <var> instructions.insertBefore(ret, new InsnNode(DUP)); // stack: <array> :: <array> :: <index> :: <var> :: <var> instructions.insertBefore(ret, new LdcInsnNode(method.name + ':' + var.name)); // stack: <array> :: <array> :: <index> :: <var> :: <var> :: <varName> instructions.insertBefore(ret, new MethodInsnNode(INVOKEVIRTUAL, VAR.getInternalName(), "setName", "(Ljava/lang/String;)V", false)); // stack: <array> :: <array> :: <index> :: <var> instructions.insertBefore(ret, new InsnNode(AASTORE)); // stack: <array> } // stack: <array> }