List of usage examples for org.objectweb.asm Opcodes ASTORE
int ASTORE
To view the source code for org.objectweb.asm Opcodes ASTORE.
Click Source Link
From source file:org.formulacompiler.compiler.internal.bytecode.ExpressionCompiler.java
License:Open Source License
private void compileIsException(final ExpressionNodeForFunction _node, final boolean _testForErrors, final Type[] _handledTypesReturningTrue, final Type[] _handledTypesReturningFalse) throws CompilerException { /*/*ww w . j a va 2s . c om*/ * Move the handler into its own method because exception handlers clobber the stack. */ final Iterable<LetEntry<Compilable>> closure = closureOf(_node); compileHelpedExpr(new HelperCompiler(sectionInContext(), _node, closure) { @Override protected void compileBody() throws CompilerException { final GeneratorAdapter mv = this.mv(); final ExpressionCompiler ec = expressionCompiler(); final Label handled = mv.newLabel(); final Label beginHandling = mv.mark(); ec.compile(_node.argument(0)); ec.compileExceptionalValueTest(_testForErrors); mv.goTo(handled); final Label endHandling = mv.mark(); for (final Type a_handledTypesReturningTrue : _handledTypesReturningTrue) { mv.catchException(beginHandling, endHandling, a_handledTypesReturningTrue); mv.visitVarInsn(Opcodes.ASTORE, method().newLocal(1)); ec.compileConst(Boolean.TRUE); mv.goTo(handled); } for (final Type a_handledTypesReturningFalse : _handledTypesReturningFalse) { mv.catchException(beginHandling, endHandling, a_handledTypesReturningFalse); mv.visitVarInsn(Opcodes.ASTORE, method().newLocal(1)); ec.compileConst(Boolean.FALSE); mv.goTo(handled); } mv.mark(handled); mv.returnValue(); } }, closure); }
From source file:org.formulacompiler.compiler.internal.bytecode.ExpressionCompiler.java
License:Open Source License
private final void compileRef(ExpressionNodeForParentSectionModel _node) throws CompilerException { final SectionCompiler section = sectionInContext(); final SectionCompiler parent = section.parentSectionCompiler(); final int parentObject = method().newLocal(1); // Object final GeneratorAdapter mv = mv(); method().compileObjectInContext();/*from w w w .ja va 2 s . c o m*/ mv.getField(section.classType(), ByteCodeEngineCompiler.PARENT_MEMBER_NAME, parent.classType()); mv().visitVarInsn(Opcodes.ASTORE, parentObject); compileInContextOfObject(parent, parentObject, _node); }
From source file:org.formulacompiler.compiler.internal.bytecode.ExpressionCompiler.java
License:Open Source License
private void compileScanArray(ForEachElementCompilation _forElement) throws CompilerException { final GeneratorAdapter mv = mv(); final int loc = localsOffset(); incLocalsOffset(4);//from w w w. ja v a2s . c o m // store array mv.visitVarInsn(Opcodes.ASTORE, loc); // store array length mv.visitVarInsn(Opcodes.ALOAD, loc); mv.arrayLength(); mv.visitVarInsn(Opcodes.ISTORE, 1 + loc); // loop index mv.push(0); mv.visitVarInsn(Opcodes.ISTORE, 2 + loc); // loop start final Label l0 = mv.mark(); // check loop condition mv.visitVarInsn(Opcodes.ILOAD, 2 + loc); mv.visitVarInsn(Opcodes.ILOAD, 1 + loc); final Label l1 = new Label(); mv.ifICmp(GeneratorAdapter.GE, l1); // loop body mv.visitVarInsn(Opcodes.ALOAD, loc); mv.visitVarInsn(Opcodes.ILOAD, 2 + loc); mv.visitInsn(Opcodes.AALOAD); mv.visitVarInsn(Opcodes.ASTORE, 3 + loc); _forElement.compile(3 + loc, 2 + loc); // inc loop index mv.visitIincInsn(2 + loc, 1); mv.goTo(l0); mv.visitLabel(l1); }
From source file:org.glassfish.pfl.tf.spi.Util.java
License:Open Source License
public void initLocal(MethodVisitor mv, LocalVariableNode var) { info(2, "Initializing variable " + var); Type type = Type.getType(var.desc); switch (type.getSort()) { case Type.BYTE: case Type.BOOLEAN: case Type.CHAR: case Type.SHORT: case Type.INT: mv.visitInsn(Opcodes.ICONST_0);/*from www . j ava 2 s. co m*/ mv.visitVarInsn(Opcodes.ISTORE, var.index); break; case Type.LONG: mv.visitInsn(Opcodes.LCONST_0); mv.visitVarInsn(Opcodes.LSTORE, var.index); break; case Type.FLOAT: mv.visitInsn(Opcodes.FCONST_0); mv.visitVarInsn(Opcodes.FSTORE, var.index); break; case Type.DOUBLE: mv.visitInsn(Opcodes.DCONST_0); mv.visitVarInsn(Opcodes.DSTORE, var.index); break; default: mv.visitInsn(Opcodes.ACONST_NULL); mv.visitVarInsn(Opcodes.ASTORE, var.index); } }
From source file:org.glassfish.pfl.tf.spi.Util.java
License:Open Source License
public void storeFromXReturn(MethodVisitor mv, int returnOpcode, LocalVariableNode holder) { switch (returnOpcode) { case Opcodes.RETURN: // NOP// w w w .jav a 2s . com break; case Opcodes.ARETURN: mv.visitVarInsn(Opcodes.ASTORE, holder.index); break; case Opcodes.IRETURN: mv.visitVarInsn(Opcodes.ISTORE, holder.index); break; case Opcodes.LRETURN: mv.visitVarInsn(Opcodes.LSTORE, holder.index); break; case Opcodes.FRETURN: mv.visitVarInsn(Opcodes.FSTORE, holder.index); break; case Opcodes.DRETURN: mv.visitVarInsn(Opcodes.DSTORE, holder.index); break; } }
From source file:org.glassfish.pfl.tf.tools.enhancer.StaticInitVisitor.java
License:Open Source License
@Override public void visitCode() { if (SHORT_FORM) { super.visitCode(); mv.visitLdcInsn(Type.getType("L" + ecd.getClassName() + ";")); Type mmrType = Type.getType(MethodMonitorRegistry.class); String mdesc = "(Ljava/lang/Class;)V"; mv.visitMethodInsn(Opcodes.INVOKESTATIC, mmrType.getInternalName(), "registerClass", mdesc); } else {// w w w . j a v a 2 s. c o m int line = 1; util.info(2, "StaticInitVisitor.visitCode"); super.visitCode(); Label start = new Label(); Label end = new Label(); mv.visitLabel(start); LocalVariableNode thisClass = defineLocal(mv, "thisClass", Class.class, start, end); LocalVariableNode mnameList = defineLocal(mv, "mnameList", List.class, start, end); LocalVariableNode holderMap = defineLocal(mv, "holderMap", Map.class, start, end); generateTraceMsg(mv, "initialize the holders", line++); for (String str : ecd.getAnnotationToHolderName().values()) { generateTraceMsg(mv, "Generating to initialize holder " + str, line++); util.info(2, "Generating code to initialize holder " + str); util.newWithSimpleConstructor(mv, SynchronizedHolder.class); mv.visitFieldInsn(Opcodes.PUTSTATIC, ecd.getClassName(), str, Type.getDescriptor(SynchronizedHolder.class)); } generateTraceMsg(mv, "Store the Class of this class", line++); mv.visitLdcInsn(Type.getType("L" + ecd.getClassName() + ";")); mv.visitVarInsn(Opcodes.ASTORE, thisClass.index); generateTraceMsg(mv, "Create list of method names", line++); util.newWithSimpleConstructor(mv, ArrayList.class); mv.visitVarInsn(Opcodes.ASTORE, mnameList.index); for (String str : ecd.getMethodNames()) { util.info(2, "Generating code to add " + str + " to methodNames"); mv.visitVarInsn(Opcodes.ALOAD, mnameList.index); mv.visitLdcInsn(str); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z"); mv.visitInsn(Opcodes.POP); } generateTraceMsg(mv, "create map from MM annotation class to Holder and init", line++); util.newWithSimpleConstructor(mv, HashMap.class); mv.visitVarInsn(Opcodes.ASTORE, holderMap.index); for (Map.Entry<String, String> entry : ecd.getAnnotationToHolderName().entrySet()) { util.info(2, "Generating code to put " + entry.getKey() + "=>" + entry.getValue() + " into holderMap"); mv.visitVarInsn(Opcodes.ALOAD, holderMap.index); Type annoType = Type.getType("L" + entry.getKey() + ";"); mv.visitLdcInsn(annoType); mv.visitFieldInsn(Opcodes.GETSTATIC, ecd.getClassName(), entry.getValue(), Type.getDescriptor(SynchronizedHolder.class)); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitInsn(Opcodes.POP); } generateTraceMsg(mv, "register with MethodMonitorRegistry", line++); util.info(2, "Generating code call MethodMonitorRegistry.registerClass"); mv.visitVarInsn(Opcodes.ALOAD, thisClass.index); mv.visitVarInsn(Opcodes.ALOAD, mnameList.index); mv.visitVarInsn(Opcodes.ALOAD, holderMap.index); Type mmrType = Type.getType(MethodMonitorRegistry.class); String mdesc = "(Ljava/lang/Class;Ljava/util/List;Ljava/util/Map;)V"; mv.visitMethodInsn(Opcodes.INVOKESTATIC, mmrType.getInternalName(), "registerClass", mdesc); mv.visitLabel(end); thisClass.accept(mv); mnameList.accept(mv); holderMap.accept(mv); } }
From source file:org.graalvm.compiler.replacements.test.DeoptimizeOnExceptionTest.java
License:Open Source License
private static byte[] makeClazz() { // Code generated the class below using asm. String clazzName = DeoptimizeOnExceptionTest.class.getName().replace('.', '/'); final ClassWriter w = new ClassWriter(0); w.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, "t/TestJSR", null, "java/lang/Object", new String[] { "java/lang/Runnable" }); MethodVisitor mv = w.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, new String[] {}); mv.visitCode();// ww w . ja v a2 s .c om mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(10, 10); mv.visitEnd(); mv = w.visitMethod(Opcodes.ACC_PUBLIC, "run", "()V", null, null); mv.visitCode(); mv.visitMethodInsn(Opcodes.INVOKESTATIC, clazzName, "getM", "()Ljava/lang/Object;", false); Label l1 = new Label(); mv.visitJumpInsn(Opcodes.JSR, l1); mv.visitInsn(Opcodes.RETURN); mv.visitLabel(l1); mv.visitVarInsn(Opcodes.ASTORE, 1); Label lElse = new Label(); Label lEnd = new Label(); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J", false); mv.visitInsn(Opcodes.POP2); mv.visitMethodInsn(Opcodes.INVOKESTATIC, clazzName, "getM", "()Ljava/lang/Object;", false); mv.visitInsn(Opcodes.DUP); mv.visitJumpInsn(Opcodes.IFNULL, lElse); mv.visitMethodInsn(Opcodes.INVOKESTATIC, clazzName, "methodA", "()V", false); mv.visitJumpInsn(Opcodes.GOTO, lEnd); mv.visitLabel(lElse); mv.visitMethodInsn(Opcodes.INVOKESTATIC, clazzName, "methodB", "()V", false); mv.visitLabel(lEnd); mv.visitVarInsn(Opcodes.RET, 1); mv.visitMaxs(10, 10); mv.visitEnd(); return w.toByteArray(); }
From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java
@Override public void visit(NewIdentifierExpression node) throws ASTVisitorException { if (node.getExpressions() != null) { node.getExpressions().accept(this); }/*from ww w.ja v a 2 s . c om*/ mn.instructions.add(new TypeInsnNode(Opcodes.NEW, node.getIdentifier())); mn.instructions.add(new InsnNode(Opcodes.DUP)); //@TODO: fix calling parameters if (node.getExpressions() != null) { if (node.getExpressions().getExpressions().isEmpty() && Registry.getInstance() .classExists(Type.getType("Lorg/hua/customclasses/" + node.getIdentifier() + ";"))) { System.out.println("222222222222222222222222222222222222222222 " + ASTUtils.getSafeType(node).getInternalName()); mn.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, ASTUtils.getSafeType(node).getInternalName(), "<init>", "()V", false)); } else //get parameter types and then give that as the signature if (Registry.getInstance() .classExists(Type.getType("Lorg/hua/customclasses/" + node.getIdentifier() + ";"))) { SymTable<SymTableEntry> existingClass = Registry.getInstance() .getExistingClass(Type.getType("Lorg/hua/customclasses/" + node.getIdentifier() + ";")); SymTableEntry lookup = existingClass.lookup(node.getIdentifier()); if (lookup != null) { Type[] types = lookup.getParametersTypes(); mn.instructions.add( new MethodInsnNode(Opcodes.INVOKEVIRTUAL, ASTUtils.getSafeType(node).getInternalName(), node.getIdentifier(), Type.getMethodDescriptor(Type.VOID_TYPE, types), false)); } else { ASTUtils.error(node, "Constructor not found"); } } else { ASTUtils.error(node, "Problem with called constructor"); } } LocalIndexPool pool = ASTUtils.getSafeLocalIndexPool(fd); int localIndex = pool.getLocalIndex(); System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ " + localIndex); mn.instructions.add(new VarInsnNode(Opcodes.ASTORE, localIndex)); }
From source file:org.jacoco.core.instr.ResizeInstructionsTest.java
License:Open Source License
/** * Adds code that requires//from ww w. ja va2 s . c om * {@link ClassWriter#getCommonSuperClass(String, String)}. * * <pre> * Object o = this; * while (true) { * o = (Integer) null; * } * </pre> */ private static void addCauseOfGetCommonSuperClass(final MethodVisitor mv) { mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ASTORE, 1); Label label = new Label(); mv.visitLabel(label); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitTypeInsn(Opcodes.CHECKCAST, "java/lang/Integer"); mv.visitVarInsn(Opcodes.ASTORE, 1); mv.visitJumpInsn(Opcodes.GOTO, label); }
From source file:org.jacoco.core.internal.analysis.filter.FinallyFilter.java
License:Open Source License
/** * @return number of instructions inside given "catch-any" handler *//*w w w. j a va 2 s . c o m*/ private static int size(AbstractInsnNode i) { if (Opcodes.ASTORE != i.getOpcode()) { // when always completes abruptly return 0; } final int var = ((VarInsnNode) i).var; int size = -1; do { size++; i = next(i); if (i == null) { // when always completes abruptly return 0; } } while (!(Opcodes.ALOAD == i.getOpcode() && var == ((VarInsnNode) i).var)); i = next(i); if (Opcodes.ATHROW != i.getOpcode()) { return 0; } return size; }