List of usage examples for org.objectweb.asm Opcodes IFEQ
int IFEQ
To view the source code for org.objectweb.asm Opcodes IFEQ.
Click Source Link
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.AddThreadNotificationAdapter.java
License:Open Source License
@Override public MethodVisitor visitMethod(int access, String methodName, String desc, String signature, String[] exceptions) {//from ww w . ja va 2 s . c om if (INIT.equals(methodName)) { // into each constructor ... final MethodVisitor methodVisitor = cv.visitMethod(access, methodName, desc, null, null); return new AdviceAdapter(this.api, methodVisitor, access, methodName, desc) { @Override public void invokeConstructor(Type type, Method method) { super.invokeConstructor(type, method); // ... that contains a super(..) call (rather than this(..)): if (type.getInternalName().equals(clazz.getInternalSuperClassName())) { // insert: // this._OT$creationThread = Thread.currentThread(); methodVisitor.visitIntInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, ClassNames.THREAD_SLASH, CURRENT_THREAD, CURRENT_THREAD_DESC, false); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, clazz.getInternalName(), CREATION_THREAD, THREAD_DESC); } } }; } else if (RUN.equals(methodName) && RUN_DESC.equals(desc)) { final MethodVisitor methodVisitor = cv.visitMethod(access, methodName, desc, null, null); return new AdviceAdapter(this.api, methodVisitor, access, methodName, desc) { Label start = new Label(); // start of method (scope of new local) Label end = new Label(); // end of method int isThreadStartIdx; // new local: boolean _OT$isThreadStart @Override protected void onMethodEnter() { methodVisitor.visitLabel(start); isThreadStartIdx = newLocal(Type.BOOLEAN_TYPE); methodVisitor.visitLocalVariable("_OT$isThreadStart", "Z", null, start, end, isThreadStartIdx); // TeamThreadManager.newThreadStarted(false, this._OT$creationThread) methodVisitor.visitInsn(Opcodes.ICONST_0); methodVisitor.visitIntInsn(Opcodes.ALOAD, 0); methodVisitor.visitFieldInsn(Opcodes.GETFIELD, clazz.getInternalName(), CREATION_THREAD, THREAD_DESC); methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, ClassNames.TEAM_THREAD_MANAGER_SLASH, NEW_THREAD_STARTED, NEW_THREAD_STARTED_DESC, false); methodVisitor.visitIntInsn(Opcodes.ISTORE, isThreadStartIdx); // this._OT$creationThread = null; // avoid leak methodVisitor.visitIntInsn(Opcodes.ALOAD, 0); methodVisitor.visitInsn(Opcodes.ACONST_NULL); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, clazz.getInternalName(), CREATION_THREAD, THREAD_DESC); } @Override protected void onMethodExit(int opcode) { insertThreadEndedNotification(); } @Override public void endMethod() { methodVisitor.visitLabel(end); // insert another threadEnded notification as a handler for Throwable Label handler = new Label(); methodVisitor.visitLabel(handler); insertThreadEndedNotification(); methodVisitor.visitInsn(Opcodes.ATHROW); // rethrow caught exception methodVisitor.visitTryCatchBlock(start, end, handler, ClassNames.THROWABLE_SLASH); methodVisitor.visitMaxs(0, 0); } void insertThreadEndedNotification() { Label skip = new Label(); // insert: // if (_OT$isThreadStart) TeamThreadManager.threadEnded(); methodVisitor.visitIntInsn(Opcodes.ILOAD, isThreadStartIdx); methodVisitor.visitJumpInsn(Opcodes.IFEQ, skip); methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, ClassNames.TEAM_THREAD_MANAGER_SLASH, THREAD_ENDED, THREAD_ENDED_DESC, false); methodVisitor.visitLabel(skip); } }; } return null; }
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.CreateAddRemoveRoleMethod.java
License:Open Source License
@Override protected boolean transform() { // void _OT$addRemoveRole(Object role, boolean isAdding) { MethodNode method = getMethod(ConstantMembers.addOrRemoveRole); final int ROLE_SLOT = 1, IS_ADDING_SLOT = 2; Label start = new Label(), end = new Label(); method.instructions.clear();//from www. j a v a 2 s . c om method.visitLabel(start); // set = <initialized _OT$roleSet;> final int SET_SLOT = 3; method.visitLocalVariable("set", "Ljava/util/Set;", null, start, end, SET_SLOT); genGetInitializedRoleSet(method.instructions, SET_SLOT); // if (isAdding) { method.instructions.add(new IntInsnNode(Opcodes.ILOAD, IS_ADDING_SLOT)); LabelNode jumpToRemove = new LabelNode(); method.instructions.add(new JumpInsnNode(Opcodes.IFEQ, jumpToRemove)); // set.add(role); method.instructions.add(new IntInsnNode(Opcodes.ALOAD, SET_SLOT)); method.instructions.add(new IntInsnNode(Opcodes.ALOAD, ROLE_SLOT)); method.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, ClassNames.HASH_SET_SLASH, "add", "(Ljava/lang/Object;)Z", false)); method.instructions.add(new InsnNode(Opcodes.POP)); LabelNode jumpToEnd = new LabelNode(); method.instructions.add(new JumpInsnNode(Opcodes.GOTO, jumpToEnd)); // } else { method.instructions.add(jumpToRemove); // set.remove(role); method.instructions.add(new IntInsnNode(Opcodes.ALOAD, SET_SLOT)); method.instructions.add(new IntInsnNode(Opcodes.ALOAD, ROLE_SLOT)); method.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, ClassNames.HASH_SET_SLASH, "remove", "(Ljava/lang/Object;)Z", false)); method.instructions.add(new InsnNode(Opcodes.POP)); method.instructions.add(jumpToEnd); // } method.instructions.add(new InsnNode(Opcodes.RETURN)); method.visitLabel(end); // } // maxs are computed, maxStack from flow, maxLocals from localVariable-slots return true; }
From source file:org.elasticsearch.painless.MethodWriter.java
License:Apache License
public void writeBranch(final Label tru, final Label fals) { if (tru != null) { visitJumpInsn(Opcodes.IFNE, tru); } else if (fals != null) { visitJumpInsn(Opcodes.IFEQ, fals); }/*from w w w .j a v a 2 s .c om*/ }
From source file:org.elasticsearch.painless.node.EBool.java
License:Apache License
@Override void write(MethodWriter writer, Globals globals) { if (operation == Operation.AND) { Label fals = new Label(); Label end = new Label(); left.write(writer, globals);/*from w w w . j a v a 2 s . c o m*/ writer.ifZCmp(Opcodes.IFEQ, fals); right.write(writer, globals); writer.ifZCmp(Opcodes.IFEQ, fals); writer.push(true); writer.goTo(end); writer.mark(fals); writer.push(false); writer.mark(end); } else if (operation == Operation.OR) { Label tru = new Label(); Label fals = new Label(); Label end = new Label(); left.write(writer, globals); writer.ifZCmp(Opcodes.IFNE, tru); right.write(writer, globals); writer.ifZCmp(Opcodes.IFEQ, fals); writer.mark(tru); writer.push(true); writer.goTo(end); writer.mark(fals); writer.push(false); writer.mark(end); } else { throw createError(new IllegalStateException("Illegal tree structure.")); } }
From source file:org.elasticsearch.painless.node.EConditional.java
License:Apache License
@Override void write(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location);// w w w. j av a 2 s. c om Label fals = new Label(); Label end = new Label(); condition.write(writer, globals); writer.ifZCmp(Opcodes.IFEQ, fals); left.write(writer, globals); writer.goTo(end); writer.mark(fals); right.write(writer, globals); writer.mark(end); }
From source file:org.elasticsearch.painless.node.EUnary.java
License:Apache License
@Override void write(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location);//from w w w. ja v a 2 s. c om if (operation == Operation.NOT) { Label fals = new Label(); Label end = new Label(); child.write(writer, globals); writer.ifZCmp(Opcodes.IFEQ, fals); writer.push(false); writer.goTo(end); writer.mark(fals); writer.push(true); writer.mark(end); } else { Sort sort = promote.sort; child.write(writer, globals); // Def calls adopt the wanted return value. If there was a narrowing cast, // we need to flag that so that it's done at runtime. int defFlags = 0; if (originallyExplicit) { defFlags |= DefBootstrap.OPERATOR_EXPLICIT_CAST; } if (operation == Operation.BWNOT) { if (sort == Sort.DEF) { org.objectweb.asm.Type descriptor = org.objectweb.asm.Type.getMethodType(actual.type, child.actual.type); writer.invokeDefCall("not", descriptor, DefBootstrap.UNARY_OPERATOR, defFlags); } else { if (sort == Sort.INT) { writer.push(-1); } else if (sort == Sort.LONG) { writer.push(-1L); } else { throw createError(new IllegalStateException("Illegal tree structure.")); } writer.math(MethodWriter.XOR, actual.type); } } else if (operation == Operation.SUB) { if (sort == Sort.DEF) { org.objectweb.asm.Type descriptor = org.objectweb.asm.Type.getMethodType(actual.type, child.actual.type); writer.invokeDefCall("neg", descriptor, DefBootstrap.UNARY_OPERATOR, defFlags); } else { writer.math(MethodWriter.NEG, actual.type); } } else if (operation == Operation.ADD) { if (sort == Sort.DEF) { org.objectweb.asm.Type descriptor = org.objectweb.asm.Type.getMethodType(actual.type, child.actual.type); writer.invokeDefCall("plus", descriptor, DefBootstrap.UNARY_OPERATOR, defFlags); } } else { throw createError(new IllegalStateException("Illegal tree structure.")); } } }
From source file:org.elasticsearch.painless.node.SDo.java
License:Apache License
@Override void write(MethodWriter writer, Globals globals) { writer.writeStatementOffset(location); Label start = new Label(); Label begin = new Label(); Label end = new Label(); writer.mark(start);// w ww.j a va2 s . c om block.continu = begin; block.brake = end; block.write(writer, globals); writer.mark(begin); if (!continuous) { condition.write(writer, globals); writer.ifZCmp(Opcodes.IFEQ, end); } if (loopCounter != null) { writer.writeLoopCounter(loopCounter.getSlot(), Math.max(1, block.statementCount), location); } writer.goTo(start); writer.mark(end); }
From source file:org.elasticsearch.painless.node.SFor.java
License:Apache License
@Override void write(MethodWriter writer, Globals globals) { writer.writeStatementOffset(location); Label start = new Label(); Label begin = afterthought == null ? start : new Label(); Label end = new Label(); if (initializer instanceof SDeclBlock) { initializer.write(writer, globals); } else if (initializer instanceof AExpression) { AExpression initializer = (AExpression) this.initializer; initializer.write(writer, globals); writer.writePop(initializer.expected.sort.size); }//from w w w .ja v a 2s.c o m writer.mark(start); if (condition != null && !continuous) { condition.write(writer, globals); writer.ifZCmp(Opcodes.IFEQ, end); } boolean allEscape = false; if (block != null) { allEscape = block.allEscape; int statementCount = Math.max(1, block.statementCount); if (afterthought != null) { ++statementCount; } if (loopCounter != null) { writer.writeLoopCounter(loopCounter.getSlot(), statementCount, location); } block.continu = begin; block.brake = end; block.write(writer, globals); } else { if (loopCounter != null) { writer.writeLoopCounter(loopCounter.getSlot(), 1, location); } } if (afterthought != null) { writer.mark(begin); afterthought.write(writer, globals); } if (afterthought != null || !allEscape) { writer.goTo(start); } writer.mark(end); }
From source file:org.elasticsearch.painless.node.SIf.java
License:Apache License
@Override void write(MethodWriter writer, Globals globals) { writer.writeStatementOffset(location); Label fals = new Label(); condition.write(writer, globals);/*from w w w. j a v a 2s .co m*/ writer.ifZCmp(Opcodes.IFEQ, fals); ifblock.continu = continu; ifblock.brake = brake; ifblock.write(writer, globals); writer.mark(fals); }
From source file:org.elasticsearch.painless.node.SIfElse.java
License:Apache License
@Override void write(MethodWriter writer, Globals globals) { writer.writeStatementOffset(location); Label fals = new Label(); Label end = new Label(); condition.write(writer, globals);/*ww w . j a v a 2s . c om*/ writer.ifZCmp(Opcodes.IFEQ, fals); ifblock.continu = continu; ifblock.brake = brake; ifblock.write(writer, globals); if (!ifblock.allEscape) { writer.goTo(end); } writer.mark(fals); elseblock.continu = continu; elseblock.brake = brake; elseblock.write(writer, globals); writer.mark(end); }