List of usage examples for org.objectweb.asm Opcodes IRETURN
int IRETURN
To view the source code for org.objectweb.asm Opcodes IRETURN.
Click Source Link
From source file:com.thomas15v.packetlib.codegenerator.asm.ASMHelper.java
License:MIT License
/** * Generate a new method "int name()", which returns a constant value. * * @param clazz Class to add method to/* ww w . j a v a2 s. co m*/ * @param name Name of method * @param retval Return value of method */ public static void generateIntegerMethodConst(ClassNode clazz, String name, short retval) { MethodNode method = new MethodNode(Opcodes.ASM5, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, name, "()I", null, null); InsnList code = method.instructions; code.add(ASMHelper.pushIntConstant(retval)); code.add(new InsnNode(Opcodes.IRETURN)); clazz.methods.add(method); }
From source file:com.thomas15v.packetlib.codegenerator.asm.ASMHelper.java
License:MIT License
/** * Populate a forwarding method of the form * "T name() { return Class.forward(this); }". * * @param method Method to generate code for * @param forwardname Name of method to call * @param rettype Return type of method/*from www .java 2 s. c o m*/ * @param thistype Type of object method is being generated on * @param forwardtype Type to forward method to */ public static void populateForwardingToStaticMethod(MethodNode method, String forwardname, Type rettype, Type thistype, Type forwardtype) { InsnList code = method.instructions; code.add(new VarInsnNode(thistype.getOpcode(Opcodes.ILOAD), 0)); code.add(new MethodInsnNode(Opcodes.INVOKESTATIC, forwardtype.getInternalName(), forwardname, Type.getMethodDescriptor(rettype, thistype), false)); code.add(new InsnNode(rettype.getOpcode(Opcodes.IRETURN))); }
From source file:com.thomas15v.packetlib.codegenerator.asm.ASMHelper.java
License:MIT License
/** * Populate a forwarding method of the form * "T name() { return this.forward(); }". This is also valid for methods of * the form "static T name(S object) { return object.forward() }". * * @param method Method to generate code for * @param forwardname Name of method to call * @param rettype Return type of method// w ww. java 2 s . c om * @param thistype Type of object method is being generated on */ public static void populateSelfForwardingMethod(MethodNode method, String forwardname, Type rettype, Type thistype) { InsnList code = method.instructions; code.add(new VarInsnNode(thistype.getOpcode(Opcodes.ILOAD), 0)); code.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, thistype.getInternalName(), forwardname, "()" + rettype.getDescriptor(), false)); code.add(new InsnNode(rettype.getOpcode(Opcodes.IRETURN))); }
From source file:com.thomas15v.packetlib.codegenerator.asm.ASMHelper.java
License:MIT License
/** * Populate a forwarding method of the form * "T name(S object) { return object.forward(); }". * * @param method Method to generate code for * @param forwardname Name of method to call * @param rettype Return type of method/* w w w. ja v a 2s.c o m*/ * @param argtype Type of object to call method on * @param thistype Type of object method is being generated on */ public static void populateForwardingMethod(MethodNode method, String forwardname, Type rettype, Type argtype, Type thistype) { InsnList code = method.instructions; code.add(new VarInsnNode(argtype.getOpcode(Opcodes.ILOAD), 1)); code.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, argtype.getInternalName(), forwardname, "()" + rettype.getDescriptor(), false)); code.add(new InsnNode(rettype.getOpcode(Opcodes.IRETURN))); }
From source file:com.toolazydogs.maiden.agent.asm.IronClassVisitor.java
License:Apache License
public MethodVisitor visitMethod(int access, final String name, final String desc, String signature, String[] exceptions) {//from w w w .j ava2s. co m LOGGER.entering(CLASS_NAME, "visitMethod", new Object[] { access, name, desc, signature, exceptions }); boolean isNative = (access & ACC_NATIVE) != 0; boolean isSynchronized = (access & ACC_SYNCHRONIZED) != 0; boolean isStatic = (access & ACC_STATIC) != 0; MethodVisitor mv; /** * If native method prefix is supported we inject our own wrapper method. */ if (nativeMethodPrefixSupported && isNative) { delegate.visitMethod(access, IronAgent.NATIVE_METHOD_PREFIX + name, desc, signature, exceptions); mv = delegate.visitMethod(access ^ (ACC_NATIVE | ACC_SYNCHRONIZED), name, desc, signature, exceptions); } else { mv = delegate.visitMethod((isSynchronized ? access ^ ACC_SYNCHRONIZED : access), name, desc, signature, exceptions); } mv = new WaitNotifyMethodVisitor(mv); BeginEndMethodVisitor bemv = new BeginEndMethodVisitor(mv, access, name, desc, signature, exceptions); if (isSynchronized) { LOGGER.finest("Method is synchronized"); final Type classType = Type.getType("L" + clazz.replaceAll("\\.", "/") + ";.class"); if (isStatic) { LOGGER.finest("Method is static"); bemv.getListeners().add(new BeginEndMethodListener() { @Override public void begin(MethodVisitor visitor) { push(visitor, line); visitor.visitLdcInsn(classType); visitor.visitMethodInsn(INVOKESTATIC, "com/toolazydogs/maiden/IronMaiden", "lockObject", "(ILjava/lang/Object;)V"); } @Override public void end(MethodVisitor visitor) { push(visitor, line); visitor.visitLdcInsn(classType); visitor.visitMethodInsn(INVOKESTATIC, "com/toolazydogs/maiden/IronMaiden", "unlockObject", "(ILjava/lang/Object;)V"); } }); } else { LOGGER.finest("Method is not static"); bemv.getListeners().add(new BeginEndMethodListener() { @Override public void begin(MethodVisitor visitor) { push(visitor, line); visitor.visitVarInsn(ALOAD, 0); visitor.visitMethodInsn(INVOKESTATIC, "com/toolazydogs/maiden/IronMaiden", "lockObject", "(ILjava/lang/Object;)V"); } @Override public void end(MethodVisitor visitor) { push(visitor, line); visitor.visitVarInsn(ALOAD, 0); visitor.visitMethodInsn(INVOKESTATIC, "com/toolazydogs/maiden/IronMaiden", "unlockObject", "(ILjava/lang/Object;)V"); } }); } } bemv.getListeners().add(new BeginEndMethodListener() { @Override public void begin(MethodVisitor visitor) { visitor.visitLdcInsn(clazz); visitor.visitLdcInsn(name); visitor.visitLdcInsn(desc); visitor.visitMethodInsn(INVOKESTATIC, "com/toolazydogs/maiden/IronMaiden", "push", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); } @Override public void end(MethodVisitor visitor) { push(visitor, line); visitor.visitMethodInsn(INVOKESTATIC, "com/toolazydogs/maiden/IronMaiden", "pop", "(I)V"); } }); MethodVisitor result = new MonitorMethodVisitor(bemv); if (nativeMethodPrefixSupported && isNative) { MethodAdapter adapter = new MethodAdapter(result); adapter.visitCode(); int args = 0; if (!isStatic) adapter.visitVarInsn(ALOAD, args++); for (Type param : Type.getArgumentTypes(desc)) { adapter.visitVarInsn(param.getOpcode(ILOAD), args); args += param.getSize(); } adapter.visitMethodInsn((isStatic ? INVOKESTATIC : INVOKEVIRTUAL), clazz.replaceAll("\\.", "/"), IronAgent.NATIVE_METHOD_PREFIX + name, desc); Type returnType = Type.getReturnType(desc); adapter.visitInsn(returnType.getOpcode(Opcodes.IRETURN)); adapter.visitMaxs(0, 0); adapter.visitEnd(); result = null; } LOGGER.exiting(CLASS_NAME, "visitMethod", result); return result; }
From source file:com.toolazydogs.maiden.agent.asm.NativeClassVisitor.java
License:Apache License
public MethodVisitor visitMethod(int access, final String name, final String desc, String signature, String[] exceptions) {//from w w w . j av a 2 s . co m LOGGER.entering(CLASS_NAME, "visitMethod", new Object[] { access, name, desc, signature, exceptions }); boolean isNative = (access & ACC_NATIVE) != 0; boolean isSynchronized = (access & ACC_SYNCHRONIZED) != 0; boolean isStatic = (access & ACC_STATIC) != 0; MethodVisitor mv; /** * If native method prefix is supported we inject our own wrapper method. */ if (nativeMethodPrefixSupported && isNative) { delegate.visitMethod(access, IronAgent.NATIVE_METHOD_PREFIX + name, desc, signature, exceptions); mv = delegate.visitMethod(access ^ (ACC_NATIVE | ACC_SYNCHRONIZED), name, desc, signature, exceptions); } else { mv = delegate.visitMethod((isSynchronized ? access ^ ACC_SYNCHRONIZED : access), name, desc, signature, exceptions); } mv = new WaitNotifyMethodVisitor(mv); MethodVisitor result = mv; if (nativeMethodPrefixSupported && isNative) { MethodAdapter adapter = new MethodAdapter(result); adapter.visitCode(); int args = 0; if (!isStatic) adapter.visitVarInsn(ALOAD, args++); for (Type param : Type.getArgumentTypes(desc)) { adapter.visitVarInsn(param.getOpcode(ILOAD), args); args += param.getSize(); } adapter.visitMethodInsn((isStatic ? INVOKESTATIC : INVOKEVIRTUAL), clazz.replaceAll("\\.", "/"), IronAgent.NATIVE_METHOD_PREFIX + name, desc); Type returnType = Type.getReturnType(desc); adapter.visitInsn(returnType.getOpcode(Opcodes.IRETURN)); adapter.visitMaxs(0, 0); adapter.visitEnd(); result = null; } LOGGER.exiting(CLASS_NAME, "visitMethod", result); return result; }
From source file:com.triage.bytecodemaster.GroovyShardTransformer.java
protected boolean isReturnOpCode(int opCode) { return opCode == Opcodes.ARETURN || opCode == Opcodes.LRETURN || opCode == Opcodes.IRETURN || opCode == Opcodes.DRETURN || opCode == Opcodes.FRETURN || opCode == Opcodes.RETURN; }
From source file:com.trigersoft.jaque.expression.ExpressionMethodVisitor.java
License:Apache License
@Override public void visitInsn(int opcode) { Expression e;/* w w w. java2 s . c o m*/ Expression first; Expression second; switch (opcode) { case Opcodes.ARRAYLENGTH: e = Expression.arrayLength(_exprStack.pop()); break; case Opcodes.ACONST_NULL: e = Expression.constant(null, Object.class); break; case Opcodes.IALOAD: case Opcodes.LALOAD: case Opcodes.FALOAD: case Opcodes.DALOAD: case Opcodes.AALOAD: case Opcodes.BALOAD: case Opcodes.CALOAD: case Opcodes.SALOAD: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.arrayIndex(second, first); break; case Opcodes.DCONST_0: e = Expression.constant(0d, Double.TYPE); break; case Opcodes.DCONST_1: e = Expression.constant(1d, Double.TYPE); break; case Opcodes.FCMPG: case Opcodes.FCMPL: case Opcodes.DCMPG: case Opcodes.DCMPL: case Opcodes.LCMP: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.subtract(second, first); break; case Opcodes.FCONST_0: e = Expression.constant(0f, Float.TYPE); break; case Opcodes.FCONST_1: e = Expression.constant(1f, Float.TYPE); break; case Opcodes.FCONST_2: e = Expression.constant(2f, Float.TYPE); break; case Opcodes.ICONST_M1: e = Expression.constant(-1, Integer.TYPE); break; case Opcodes.ICONST_0: e = Expression.constant(0, Integer.TYPE); break; case Opcodes.ICONST_1: e = Expression.constant(1, Integer.TYPE); break; case Opcodes.ICONST_2: e = Expression.constant(2, Integer.TYPE); break; case Opcodes.ICONST_3: e = Expression.constant(3, Integer.TYPE); break; case Opcodes.ICONST_4: e = Expression.constant(4, Integer.TYPE); break; case Opcodes.ICONST_5: e = Expression.constant(5, Integer.TYPE); break; case Opcodes.LCONST_0: e = Expression.constant(0l, Long.TYPE); break; case Opcodes.LCONST_1: e = Expression.constant(1l, Long.TYPE); break; case Opcodes.IADD: case Opcodes.LADD: case Opcodes.FADD: case Opcodes.DADD: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.add(second, first); break; case Opcodes.ISUB: case Opcodes.LSUB: case Opcodes.FSUB: case Opcodes.DSUB: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.subtract(second, first); break; case Opcodes.IMUL: case Opcodes.LMUL: case Opcodes.FMUL: case Opcodes.DMUL: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.multiply(second, first); break; case Opcodes.IDIV: case Opcodes.LDIV: case Opcodes.FDIV: case Opcodes.DDIV: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.divide(second, first); break; case Opcodes.IREM: case Opcodes.LREM: case Opcodes.FREM: case Opcodes.DREM: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.modulo(second, first); break; case Opcodes.INEG: case Opcodes.LNEG: case Opcodes.FNEG: case Opcodes.DNEG: first = _exprStack.pop(); e = Expression.negate(first); break; case Opcodes.ISHL: case Opcodes.LSHL: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.leftShift(second, first); break; case Opcodes.ISHR: case Opcodes.LSHR: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.rightShift(second, first); break; case Opcodes.IUSHR: case Opcodes.LUSHR: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.rightShift(second, first); break; case Opcodes.IAND: case Opcodes.LAND: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.bitwiseAnd(second, first); break; case Opcodes.IOR: case Opcodes.LOR: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.bitwiseOr(second, first); break; case Opcodes.IXOR: case Opcodes.LXOR: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.exclusiveOr(second, first); break; case Opcodes.I2B: case Opcodes.I2C: case Opcodes.I2S: first = _exprStack.pop(); e = Expression.convert(first, NumericTypeLookup2[opcode - Opcodes.I2B]); break; case Opcodes.I2L: case Opcodes.I2F: case Opcodes.I2D: first = _exprStack.pop(); e = Expression.convert(first, NumericTypeLookup[opcode - Opcodes.I2L + 1]); break; case Opcodes.L2I: case Opcodes.L2F: case Opcodes.L2D: int l2l = opcode > Opcodes.L2I ? 1 : 0; first = _exprStack.pop(); e = Expression.convert(first, NumericTypeLookup[opcode - Opcodes.L2I + l2l]); break; case Opcodes.F2I: case Opcodes.F2L: case Opcodes.F2D: int f2f = opcode == Opcodes.F2D ? 1 : 0; first = _exprStack.pop(); e = Expression.convert(first, NumericTypeLookup[opcode - Opcodes.F2I + f2f]); break; case Opcodes.D2I: case Opcodes.D2L: case Opcodes.D2F: first = _exprStack.pop(); e = Expression.convert(first, NumericTypeLookup[opcode - Opcodes.D2I]); break; case Opcodes.IRETURN: case Opcodes.LRETURN: case Opcodes.FRETURN: case Opcodes.DRETURN: case Opcodes.ARETURN: go(null); return; case Opcodes.SWAP: first = _exprStack.pop(); second = _exprStack.pop(); _exprStack.push(first); _exprStack.push(second); case Opcodes.DUP: case Opcodes.DUP_X1: case Opcodes.DUP_X2: case Opcodes.DUP2: case Opcodes.DUP2_X1: case Opcodes.DUP2_X2: // our stack is not divided to words int base = (opcode - Opcodes.DUP) % 3; base++; dup(_exprStack, base, base - 1); return; case Opcodes.NOP: return; case Opcodes.RETURN: default: throw notLambda(opcode); } _exprStack.push(e); }
From source file:com.yahoo.yqlplus.engine.internal.bytecode.ASMClassSourceTest.java
@Test public void requireCreateClass() throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException { ASMClassSource source = createASMClassSource(); ToyClass toy = new ToyClass("toy", source); MethodGenerator method = toy.createMethod("compute"); method.setReturnType(BaseTypeAdapter.INT32); method.add(new BytecodeSequence() { @Override/*from w w w.j a v a 2 s . c o m*/ public void generate(CodeEmitter code) { code.emitIntConstant(0); code.getMethodVisitor().visitInsn(Opcodes.IRETURN); } }); source.build(); Class<? extends Computor> clazz = (Class<? extends Computor>) toy.getGeneratedClass(); Computor foo = clazz.newInstance(); Assert.assertEquals(foo.compute(), 0); }
From source file:com.yahoo.yqlplus.engine.internal.bytecode.ASMClassSourceTest.java
@Test public void requireCreateSuperClass() throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException { ASMClassSource source = createASMClassSource(); UnitGenerator toy = new UnitGenerator("base", ComputorBase.class, source) { };//from w w w . j av a 2 s. c o m MethodGenerator method = toy.createMethod("compute"); method.setReturnType(BaseTypeAdapter.INT32); method.add(new BytecodeSequence() { @Override public void generate(CodeEmitter code) { code.emitIntConstant(1); code.getMethodVisitor().visitInsn(Opcodes.IRETURN); } }); source.build(); Class<? extends Computor> clazz = (Class<? extends Computor>) toy.getGeneratedClass(); Computor foo = clazz.newInstance(); Assert.assertEquals(foo.compute(), 1); }