List of usage examples for org.objectweb.asm Opcodes ICONST_1
int ICONST_1
To view the source code for org.objectweb.asm Opcodes ICONST_1.
Click Source Link
From source file:com.geeksaga.light.profiler.util.ASMUtil.java
License:Apache License
public static AbstractInsnNode createPushNode(int value) { if (value == -1) { return new InsnNode(Opcodes.ICONST_M1); } else if (value == 0) { return new InsnNode(Opcodes.ICONST_0); } else if (value == 1) { return new InsnNode(Opcodes.ICONST_1); } else if (value == 2) { return new InsnNode(Opcodes.ICONST_2); } else if (value == 3) { return new InsnNode(Opcodes.ICONST_3); } else if (value == 4) { return new InsnNode(Opcodes.ICONST_4); } else if (value == 5) { return new InsnNode(Opcodes.ICONST_5); } else if ((value >= -128) && (value <= 127)) { return new IntInsnNode(Opcodes.BIPUSH, value); } else if ((value >= -32768) && (value <= 32767)) { return new IntInsnNode(Opcodes.SIPUSH, value); } else {/*from w w w . j a va 2 s .c om*/ return new LdcInsnNode(value); } }
From source file:com.github.anba.es6draft.compiler.assembler.InstructionAssembler.java
License:Open Source License
/** * ∅ value//from www . j a v a 2 s .c om * * @param b * the constant boolean to load on the stack */ public void iconst(boolean b) { methodVisitor.visitInsn(b ? Opcodes.ICONST_1 : Opcodes.ICONST_0); stack.iconst(); }
From source file:com.github.fge.grappa.transform.CodeBlock.java
License:Apache License
public CodeBlock iconst_1() { instructionList.add(new InsnNode(Opcodes.ICONST_1)); return this; }
From source file:com.github.malamut2.low.AllocationMethodAdapter.java
License:Apache License
private void pushProductOfIntArrayOnStack() { Label beginScopeLabel = new Label(); Label endScopeLabel = new Label(); int dimsArrayIndex = newLocal("[I", beginScopeLabel, endScopeLabel); int counterIndex = newLocal("I", beginScopeLabel, endScopeLabel); int productIndex = newLocal("I", beginScopeLabel, endScopeLabel); Label loopLabel = new Label(); Label endLabel = new Label(); super.visitLabel(beginScopeLabel); // stack: ... intArray super.visitVarInsn(Opcodes.ASTORE, dimsArrayIndex); // -> stack: ... // counter = 0 super.visitInsn(Opcodes.ICONST_0); super.visitVarInsn(Opcodes.ISTORE, counterIndex); // product = 1 super.visitInsn(Opcodes.ICONST_1); super.visitVarInsn(Opcodes.ISTORE, productIndex); // loop:/*w w w .j av a 2 s .co m*/ super.visitLabel(loopLabel); // if index >= arraylength goto end: super.visitVarInsn(Opcodes.ILOAD, counterIndex); super.visitVarInsn(Opcodes.ALOAD, dimsArrayIndex); super.visitInsn(Opcodes.ARRAYLENGTH); super.visitJumpInsn(Opcodes.IF_ICMPGE, endLabel); // product = product * max(array[counter],1) super.visitVarInsn(Opcodes.ALOAD, dimsArrayIndex); super.visitVarInsn(Opcodes.ILOAD, counterIndex); super.visitInsn(Opcodes.IALOAD); super.visitInsn(Opcodes.DUP); Label nonZeroDimension = new Label(); super.visitJumpInsn(Opcodes.IFNE, nonZeroDimension); super.visitInsn(Opcodes.POP); super.visitInsn(Opcodes.ICONST_1); super.visitLabel(nonZeroDimension); super.visitVarInsn(Opcodes.ILOAD, productIndex); super.visitInsn(Opcodes.IMUL); // if overflow happens it happens. super.visitVarInsn(Opcodes.ISTORE, productIndex); // iinc counter 1 super.visitIincInsn(counterIndex, 1); // goto loop super.visitJumpInsn(Opcodes.GOTO, loopLabel); // end: super.visitLabel(endLabel); // re-push dimensions array super.visitVarInsn(Opcodes.ALOAD, dimsArrayIndex); // push product super.visitVarInsn(Opcodes.ILOAD, productIndex); super.visitLabel(endScopeLabel); }
From source file:com.google.code.jconts.instrument.gen.ContinuationClassGenerator.java
License:Apache License
private void generateExecute(ClassVisitor cv, boolean execute) { final String name = info.continuationClassName; final Type outerType = Type.getObjectType(info.owner); // Generate invoke(T result); String signature = null;/*from w ww. ja v a2s . c o m*/ if (execute) { SignatureWriter sign = new SignatureWriter(); sign.visitParameterType().visitTypeVariable("T"); sign.visitReturnType().visitBaseType('V'); // void signature = sign.toString(); } MethodVisitor mv = cv.visitMethod(Opcodes.ACC_FINAL | Opcodes.ACC_PUBLIC, execute ? CONTINUATION_INVOKE_NAME : CONTINUATION_SET_EXCEPTION_NAME, execute ? CONTINUATION_INVOKE_DESC : CONTINUATION_SET_EXCEPTION_DESC, signature, null); mv.visitCode(); Label start = new Label(); Label end = new Label(); mv.visitLabel(start); // Load outer this if (!info.isStatic()) { mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, name, "this$0", outerType.getDescriptor()); } // state.result = result or state.exception = throwable mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, name, "state", stateDesc); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitFieldInsn(Opcodes.PUTFIELD, info.stateClassName, execute ? "result" : "exception", execute ? OBJECT_DESC : THROWABLE_DESC); // Load state field mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, name, "state", stateDesc); // Continue from this index or index+1 (for exception) mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, name, "index", "I"); if (!execute) { mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.IADD); } mv.visitMethodInsn(info.isStatic() ? Opcodes.INVOKESTATIC : Opcodes.INVOKEVIRTUAL, info.owner, info.name + "$async", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { info.stateType, Type.INT_TYPE })); mv.visitInsn(Opcodes.RETURN); mv.visitLabel(end); mv.visitLocalVariable("this", 'L' + name + ';', signature, start, end, 0); if (!info.isStatic()) { mv.visitLocalVariable("this$0", outerType.getDescriptor(), null, start, end, 1); } mv.visitLocalVariable("result", OBJECT_DESC, "TT;", start, end, 1 + info.thisOffset); mv.visitMaxs(3 + info.thisOffset + (execute ? 0 : 1), 2 + info.thisOffset); mv.visitEnd(); }
From source file:com.google.devtools.build.android.desugar.BytecodeTypeInference.java
License:Open Source License
@Override public void visitInsn(int opcode) { switch (opcode) { case Opcodes.NOP: case Opcodes.INEG: case Opcodes.LNEG: case Opcodes.FNEG: case Opcodes.DNEG: case Opcodes.I2B: case Opcodes.I2C: case Opcodes.I2S: case Opcodes.RETURN: break;//from www . java2 s . c om case Opcodes.ACONST_NULL: push(InferredType.NULL); break; case Opcodes.ICONST_M1: case Opcodes.ICONST_0: case Opcodes.ICONST_1: case Opcodes.ICONST_2: case Opcodes.ICONST_3: case Opcodes.ICONST_4: case Opcodes.ICONST_5: push(InferredType.INT); break; case Opcodes.LCONST_0: case Opcodes.LCONST_1: push(InferredType.LONG); push(InferredType.TOP); break; case Opcodes.FCONST_0: case Opcodes.FCONST_1: case Opcodes.FCONST_2: push(InferredType.FLOAT); break; case Opcodes.DCONST_0: case Opcodes.DCONST_1: push(InferredType.DOUBLE); push(InferredType.TOP); break; case Opcodes.IALOAD: case Opcodes.BALOAD: case Opcodes.CALOAD: case Opcodes.SALOAD: pop(2); push(InferredType.INT); break; case Opcodes.LALOAD: case Opcodes.D2L: pop(2); push(InferredType.LONG); push(InferredType.TOP); break; case Opcodes.DALOAD: case Opcodes.L2D: pop(2); push(InferredType.DOUBLE); push(InferredType.TOP); break; case Opcodes.AALOAD: InferredType arrayType = pop(2); InferredType elementType = arrayType.getElementTypeIfArrayOrThrow(); push(elementType); break; case Opcodes.IASTORE: case Opcodes.BASTORE: case Opcodes.CASTORE: case Opcodes.SASTORE: case Opcodes.FASTORE: case Opcodes.AASTORE: pop(3); break; case Opcodes.LASTORE: case Opcodes.DASTORE: pop(4); break; case Opcodes.POP: case Opcodes.IRETURN: case Opcodes.FRETURN: case Opcodes.ARETURN: case Opcodes.ATHROW: case Opcodes.MONITORENTER: case Opcodes.MONITOREXIT: pop(); break; case Opcodes.POP2: case Opcodes.LRETURN: case Opcodes.DRETURN: pop(2); break; case Opcodes.DUP: push(top()); break; case Opcodes.DUP_X1: { InferredType top = pop(); InferredType next = pop(); push(top); push(next); push(top); break; } case Opcodes.DUP_X2: { InferredType top = pop(); InferredType next = pop(); InferredType bottom = pop(); push(top); push(bottom); push(next); push(top); break; } case Opcodes.DUP2: { InferredType top = pop(); InferredType next = pop(); push(next); push(top); push(next); push(top); break; } case Opcodes.DUP2_X1: { InferredType top = pop(); InferredType next = pop(); InferredType bottom = pop(); push(next); push(top); push(bottom); push(next); push(top); break; } case Opcodes.DUP2_X2: { InferredType t1 = pop(); InferredType t2 = pop(); InferredType t3 = pop(); InferredType t4 = pop(); push(t2); push(t1); push(t4); push(t3); push(t2); push(t1); break; } case Opcodes.SWAP: { InferredType top = pop(); InferredType next = pop(); push(top); push(next); break; } case Opcodes.IADD: case Opcodes.ISUB: case Opcodes.IMUL: case Opcodes.IDIV: case Opcodes.IREM: case Opcodes.ISHL: case Opcodes.ISHR: case Opcodes.IUSHR: case Opcodes.IAND: case Opcodes.IOR: case Opcodes.IXOR: case Opcodes.L2I: case Opcodes.D2I: case Opcodes.FCMPL: case Opcodes.FCMPG: pop(2); push(InferredType.INT); break; case Opcodes.LADD: case Opcodes.LSUB: case Opcodes.LMUL: case Opcodes.LDIV: case Opcodes.LREM: case Opcodes.LAND: case Opcodes.LOR: case Opcodes.LXOR: pop(4); push(InferredType.LONG); push(InferredType.TOP); break; case Opcodes.LSHL: case Opcodes.LSHR: case Opcodes.LUSHR: pop(3); push(InferredType.LONG); push(InferredType.TOP); break; case Opcodes.I2L: case Opcodes.F2L: pop(); push(InferredType.LONG); push(InferredType.TOP); break; case Opcodes.I2F: pop(); push(InferredType.FLOAT); break; case Opcodes.LCMP: case Opcodes.DCMPG: case Opcodes.DCMPL: pop(4); push(InferredType.INT); break; case Opcodes.I2D: case Opcodes.F2D: pop(); push(InferredType.DOUBLE); push(InferredType.TOP); break; case Opcodes.F2I: case Opcodes.ARRAYLENGTH: pop(); push(InferredType.INT); break; case Opcodes.FALOAD: case Opcodes.FADD: case Opcodes.FSUB: case Opcodes.FMUL: case Opcodes.FDIV: case Opcodes.FREM: case Opcodes.L2F: case Opcodes.D2F: pop(2); push(InferredType.FLOAT); break; case Opcodes.DADD: case Opcodes.DSUB: case Opcodes.DMUL: case Opcodes.DDIV: case Opcodes.DREM: pop(4); push(InferredType.DOUBLE); push(InferredType.TOP); break; default: throw new RuntimeException("Unhandled opcode " + opcode); } super.visitInsn(opcode); }
From source file:com.google.monitoring.runtime.instrumentation.adapters.AllocationMethodAdapter.java
License:Apache License
private void pushProductOfIntArrayOnStack() { final Label beginScopeLabel = new Label(); final Label endScopeLabel = new Label(); final int dimsArrayIndex = newLocal("[I", beginScopeLabel, endScopeLabel); final int counterIndex = newLocal("I", beginScopeLabel, endScopeLabel); final int productIndex = newLocal("I", beginScopeLabel, endScopeLabel); final Label loopLabel = new Label(); final Label endLabel = new Label(); super.visitLabel(beginScopeLabel); // stack: ... intArray super.visitVarInsn(Opcodes.ASTORE, dimsArrayIndex); // -> stack: ... // counter = 0 super.visitInsn(Opcodes.ICONST_0); super.visitVarInsn(Opcodes.ISTORE, counterIndex); // product = 1 super.visitInsn(Opcodes.ICONST_1); super.visitVarInsn(Opcodes.ISTORE, productIndex); // loop://from w ww . j a va 2s .c om super.visitLabel(loopLabel); // if index >= arraylength goto end: super.visitVarInsn(Opcodes.ILOAD, counterIndex); super.visitVarInsn(Opcodes.ALOAD, dimsArrayIndex); super.visitInsn(Opcodes.ARRAYLENGTH); super.visitJumpInsn(Opcodes.IF_ICMPGE, endLabel); // product = product * max(array[counter],1) super.visitVarInsn(Opcodes.ALOAD, dimsArrayIndex); super.visitVarInsn(Opcodes.ILOAD, counterIndex); super.visitInsn(Opcodes.IALOAD); super.visitInsn(Opcodes.DUP); final Label nonZeroDimension = new Label(); super.visitJumpInsn(Opcodes.IFNE, nonZeroDimension); super.visitInsn(Opcodes.POP); super.visitInsn(Opcodes.ICONST_1); super.visitLabel(nonZeroDimension); super.visitVarInsn(Opcodes.ILOAD, productIndex); super.visitInsn(Opcodes.IMUL); // if overflow happens it happens. super.visitVarInsn(Opcodes.ISTORE, productIndex); // iinc counter 1 super.visitIincInsn(counterIndex, 1); // goto loop super.visitJumpInsn(Opcodes.GOTO, loopLabel); // end: super.visitLabel(endLabel); // re-push dimensions array super.visitVarInsn(Opcodes.ALOAD, dimsArrayIndex); // push product super.visitVarInsn(Opcodes.ILOAD, productIndex); super.visitLabel(endScopeLabel); }
From source file:com.google.test.metric.asm.MethodVisitorBuilder.java
License:Apache License
public void visitInsn(final int opcode) { switch (opcode) { case Opcodes.ACONST_NULL: recorder.add(new Runnable() { public void run() { block.addOp(new Load(lineNumber, new Constant(null, JavaType.OBJECT))); }/*from w ww. j av a 2s.co m*/ }); break; case Opcodes.ICONST_M1: case Opcodes.ICONST_0: case Opcodes.ICONST_1: case Opcodes.ICONST_2: case Opcodes.ICONST_3: case Opcodes.ICONST_4: case Opcodes.ICONST_5: loadConstant(opcode - Opcodes.ICONST_M1 - 1, JavaType.INT); break; case Opcodes.LCONST_0: case Opcodes.LCONST_1: loadConstant(opcode - Opcodes.LCONST_0, JavaType.LONG); break; case Opcodes.FCONST_0: case Opcodes.FCONST_1: case Opcodes.FCONST_2: loadConstant(opcode - Opcodes.FCONST_0, JavaType.FLOAT); break; case Opcodes.DCONST_0: case Opcodes.DCONST_1: loadConstant(opcode - Opcodes.DCONST_0, JavaType.DOUBLE); break; case Opcodes.IALOAD: recordArrayLoad(JavaType.INT); break; case Opcodes.LALOAD: recordArrayLoad(JavaType.LONG); break; case Opcodes.FALOAD: recordArrayLoad(JavaType.FLOAT); break; case Opcodes.DALOAD: recordArrayLoad(JavaType.DOUBLE); break; case Opcodes.AALOAD: recordArrayLoad(JavaType.OBJECT); break; case Opcodes.BALOAD: recordArrayLoad(JavaType.BYTE); break; case Opcodes.CALOAD: recordArrayLoad(JavaType.CHAR); break; case Opcodes.SALOAD: recordArrayLoad(JavaType.SHORT); break; case Opcodes.IASTORE: recordArrayStore(JavaType.INT); break; case Opcodes.LASTORE: recordArrayStore(JavaType.LONG); break; case Opcodes.FASTORE: recordArrayStore(JavaType.FLOAT); break; case Opcodes.DASTORE: recordArrayStore(JavaType.DOUBLE); break; case Opcodes.AASTORE: recordArrayStore(JavaType.OBJECT); break; case Opcodes.BASTORE: recordArrayStore(JavaType.BYTE); break; case Opcodes.CASTORE: recordArrayStore(JavaType.CHAR); break; case Opcodes.SASTORE: recordArrayStore(JavaType.SHORT); break; case Opcodes.POP: case Opcodes.POP2: recorder.add(new Runnable() { public void run() { block.addOp(new Pop(lineNumber, opcode - Opcodes.POP + 1)); } }); break; case Opcodes.DUP: case Opcodes.DUP_X1: case Opcodes.DUP_X2: recorder.add(new Runnable() { public void run() { int offset = opcode - Opcodes.DUP; block.addOp(new Duplicate(lineNumber, offset)); } }); break; case Opcodes.DUP2: case Opcodes.DUP2_X1: case Opcodes.DUP2_X2: recorder.add(new Runnable() { public void run() { block.addOp(new Duplicate2(lineNumber, opcode - Opcodes.DUP2)); } }); break; case Opcodes.SWAP: recorder.add(new Runnable() { public void run() { block.addOp(new Swap(lineNumber)); } }); break; case Opcodes.IRETURN: _return(JavaType.INT); break; case Opcodes.FRETURN: _return(JavaType.FLOAT); break; case Opcodes.ARETURN: _return(JavaType.OBJECT); break; case Opcodes.LRETURN: _return(JavaType.LONG); break; case Opcodes.DRETURN: _return(JavaType.DOUBLE); break; case Opcodes.ATHROW: recorder.add(new Runnable() { public void run() { block.addOp(new Throw(lineNumber)); } }); break; case Opcodes.RETURN: _return(JavaType.VOID); break; case Opcodes.LCMP: operation("cmp", JavaType.LONG, JavaType.LONG, JavaType.INT); break; case Opcodes.FCMPL: operation("cmpl", JavaType.FLOAT, JavaType.FLOAT, JavaType.INT); break; case Opcodes.FCMPG: operation("cmpg", JavaType.FLOAT, JavaType.FLOAT, JavaType.INT); break; case Opcodes.DCMPL: operation("cmpl", JavaType.DOUBLE, JavaType.DOUBLE, JavaType.INT); break; case Opcodes.DCMPG: operation("cmpg", JavaType.DOUBLE, JavaType.DOUBLE, JavaType.INT); break; case Opcodes.LSHL: operation("shl", JavaType.LONG, JavaType.INT, JavaType.LONG); break; case Opcodes.LSHR: operation("shr", JavaType.LONG, JavaType.INT, JavaType.LONG); break; case Opcodes.LUSHR: operation("ushr", JavaType.LONG, JavaType.INT, JavaType.LONG); break; case Opcodes.LADD: operation("add", JavaType.LONG, JavaType.LONG, JavaType.LONG); break; case Opcodes.LSUB: operation("sub", JavaType.LONG, JavaType.LONG, JavaType.LONG); break; case Opcodes.LDIV: operation("div", JavaType.LONG, JavaType.LONG, JavaType.LONG); break; case Opcodes.LREM: operation("rem", JavaType.LONG, JavaType.LONG, JavaType.LONG); break; case Opcodes.LAND: operation("and", JavaType.LONG, JavaType.LONG, JavaType.LONG); break; case Opcodes.LOR: operation("or", JavaType.LONG, JavaType.LONG, JavaType.LONG); break; case Opcodes.LXOR: operation("xor", JavaType.LONG, JavaType.LONG, JavaType.LONG); break; case Opcodes.LMUL: operation("mul", JavaType.LONG, JavaType.LONG, JavaType.LONG); break; case Opcodes.FADD: operation("add", JavaType.FLOAT, JavaType.FLOAT, JavaType.FLOAT); break; case Opcodes.FSUB: operation("sub", JavaType.FLOAT, JavaType.FLOAT, JavaType.FLOAT); break; case Opcodes.FMUL: operation("mul", JavaType.FLOAT, JavaType.FLOAT, JavaType.FLOAT); break; case Opcodes.FREM: operation("rem", JavaType.FLOAT, JavaType.FLOAT, JavaType.FLOAT); break; case Opcodes.FDIV: operation("div", JavaType.FLOAT, JavaType.FLOAT, JavaType.FLOAT); break; case Opcodes.ISHL: operation("shl", JavaType.INT, JavaType.INT, JavaType.INT); break; case Opcodes.ISHR: operation("shr", JavaType.INT, JavaType.INT, JavaType.INT); break; case Opcodes.IUSHR: operation("ushr", JavaType.INT, JavaType.INT, JavaType.INT); break; case Opcodes.IADD: operation("add", JavaType.INT, JavaType.INT, JavaType.INT); break; case Opcodes.ISUB: operation("sub", JavaType.INT, JavaType.INT, JavaType.INT); break; case Opcodes.IMUL: operation("mul", JavaType.INT, JavaType.INT, JavaType.INT); break; case Opcodes.IDIV: operation("div", JavaType.INT, JavaType.INT, JavaType.INT); break; case Opcodes.IREM: operation("rem", JavaType.INT, JavaType.INT, JavaType.INT); break; case Opcodes.IAND: operation("and", JavaType.INT, JavaType.INT, JavaType.INT); break; case Opcodes.IOR: operation("or", JavaType.INT, JavaType.INT, JavaType.INT); break; case Opcodes.IXOR: operation("xor", JavaType.INT, JavaType.INT, JavaType.INT); break; case Opcodes.DSUB: operation("sub", JavaType.DOUBLE, JavaType.DOUBLE, JavaType.DOUBLE); break; case Opcodes.DADD: operation("add", JavaType.DOUBLE, JavaType.DOUBLE, JavaType.DOUBLE); break; case Opcodes.DMUL: operation("mul", JavaType.DOUBLE, JavaType.DOUBLE, JavaType.DOUBLE); break; case Opcodes.DDIV: operation("div", JavaType.DOUBLE, JavaType.DOUBLE, JavaType.DOUBLE); break; case Opcodes.DREM: operation("rem", JavaType.DOUBLE, JavaType.DOUBLE, JavaType.DOUBLE); break; case Opcodes.L2I: convert(JavaType.LONG, JavaType.INT); break; case Opcodes.L2F: convert(JavaType.LONG, JavaType.FLOAT); break; case Opcodes.L2D: convert(JavaType.LONG, JavaType.DOUBLE); break; case Opcodes.LNEG: operation("neg", JavaType.LONG, null, JavaType.LONG); break; case Opcodes.F2I: convert(JavaType.FLOAT, JavaType.INT); break; case Opcodes.F2L: convert(JavaType.FLOAT, JavaType.LONG); break; case Opcodes.FNEG: operation("neg", JavaType.FLOAT, null, JavaType.FLOAT); break; case Opcodes.F2D: convert(JavaType.FLOAT, JavaType.DOUBLE); break; case Opcodes.D2I: convert(JavaType.DOUBLE, JavaType.INT); break; case Opcodes.D2L: convert(JavaType.DOUBLE, JavaType.LONG); break; case Opcodes.D2F: convert(JavaType.DOUBLE, JavaType.FLOAT); break; case Opcodes.DNEG: operation("neg", JavaType.DOUBLE, null, JavaType.DOUBLE); break; case Opcodes.I2L: convert(JavaType.INT, JavaType.LONG); break; case Opcodes.I2F: convert(JavaType.INT, JavaType.FLOAT); break; case Opcodes.I2D: convert(JavaType.INT, JavaType.DOUBLE); break; case Opcodes.I2B: convert(JavaType.INT, JavaType.BYTE); break; case Opcodes.I2C: convert(JavaType.INT, JavaType.CHAR); break; case Opcodes.I2S: convert(JavaType.INT, JavaType.SHORT); break; case Opcodes.INEG: operation("neg", JavaType.INT, null, JavaType.INT); break; case Opcodes.ARRAYLENGTH: operation("arraylength", JavaType.OBJECT.toArray(), null, JavaType.INT); break; case Opcodes.MONITORENTER: recorder.add(new Runnable() { public void run() { block.addOp(new MonitorEnter(lineNumber)); } }); break; case Opcodes.MONITOREXIT: recorder.add(new Runnable() { public void run() { block.addOp(new MonitorExit(lineNumber)); } }); break; case Opcodes.NOP: recorder.add(new Runnable() { public void run() { block.addOp(new Transform(lineNumber, "NOP", null, null, null)); } }); } }
From source file:com.liferay.alloy.mvc.jsonwebservice.AlloyControllerInvokerManager.java
License:Open Source License
protected byte[] generateAlloyControllerInvokerClassData(Class<?> controllerClass, String alloyControllerInvokerClassName) throws NoClassNecessaryException { boolean jsonWebServiceMethodsPresent = false; ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES); String alloyControllerInvokerClassBinaryName = getClassBinaryName(alloyControllerInvokerClassName); String baseAlloyControllerInvokerClassBinaryName = getClassBinaryName( BaseAlloyControllerInvokerImpl.class.getName()); classWriter.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, alloyControllerInvokerClassBinaryName, null, baseAlloyControllerInvokerClassBinaryName, null); MethodVisitor methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); methodVisitor.visitCode();//from ww w . j a v a 2 s . c om methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, baseAlloyControllerInvokerClassBinaryName, "<init>", "()V"); methodVisitor.visitInsn(Opcodes.RETURN); methodVisitor.visitMaxs(1, 1); methodVisitor.visitEnd(); Method[] methods = controllerClass.getDeclaredMethods(); for (Method method : methods) { if (!Modifier.isPublic(method.getModifiers())) { continue; } JSONWebServiceMethod jsonWebServiceMethod = method.getAnnotation(JSONWebServiceMethod.class); if (jsonWebServiceMethod == null) { continue; } jsonWebServiceMethodsPresent = true; Class<?>[] parameterTypes = jsonWebServiceMethod.parameterTypes(); StringBundler sb = new StringBundler(parameterTypes.length + 3); sb.append(StringPool.OPEN_PARENTHESIS); for (Class<?> parameterType : parameterTypes) { sb.append(Type.getDescriptor(parameterType)); } sb.append(StringPool.CLOSE_PARENTHESIS); sb.append(Type.getDescriptor(JSONSerializable.class)); String methodDescriptor = sb.toString(); methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, method.getName(), methodDescriptor, null, new String[] { getClassBinaryName(Exception.class.getName()) }); methodVisitor.visitCode(); for (int i = 0; i < parameterTypes.length; i++) { String parameterName = jsonWebServiceMethod.parameterNames()[i]; Class<?> parameterType = parameterTypes[i]; methodVisitor.visitLocalVariable(parameterName, Type.getDescriptor(parameterType), null, new Label(), new Label(), i + 1); } methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitLdcInsn(jsonWebServiceMethod.lifecycle()); methodVisitor.visitIntInsn(Opcodes.BIPUSH, parameterTypes.length * 2 + 2); methodVisitor.visitTypeInsn(Opcodes.ANEWARRAY, getClassBinaryName(Object.class.getName())); methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitInsn(Opcodes.ICONST_0); methodVisitor.visitLdcInsn("action"); methodVisitor.visitInsn(Opcodes.AASTORE); methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitInsn(Opcodes.ICONST_1); methodVisitor.visitLdcInsn(method.getName()); methodVisitor.visitInsn(Opcodes.AASTORE); for (int i = 0; i < parameterTypes.length; i++) { String parameterName = jsonWebServiceMethod.parameterNames()[i]; methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitIntInsn(Opcodes.BIPUSH, (i + 1) * 2); methodVisitor.visitLdcInsn(parameterName); methodVisitor.visitInsn(Opcodes.AASTORE); methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitIntInsn(Opcodes.BIPUSH, (i + 1) * 2 + 1); methodVisitor.visitVarInsn(Opcodes.ALOAD, i + 1); methodVisitor.visitInsn(Opcodes.AASTORE); } sb = new StringBundler(5); sb.append(StringPool.OPEN_PARENTHESIS); sb.append(Type.getDescriptor(String.class)); sb.append(Type.getDescriptor(Object[].class)); sb.append(StringPool.CLOSE_PARENTHESIS); sb.append(Type.getDescriptor(JSONSerializable.class)); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, alloyControllerInvokerClassBinaryName, "invokeAlloyController", sb.toString()); methodVisitor.visitInsn(Opcodes.ARETURN); methodVisitor.visitMaxs(-1, -1); methodVisitor.visitEnd(); } classWriter.visitEnd(); if (!jsonWebServiceMethodsPresent) { throw new NoClassNecessaryException(); } return classWriter.toByteArray(); }
From source file:com.liferay.portal.upgrade.test.BaseBuildAutoUpgradeTestCase.java
License:Open Source License
private void _initTableColumns(MethodVisitor methodVisitor, Object[][] tableColumns) { methodVisitor.visitCode();// w w w . java2s. co m methodVisitor.visitInsn(Opcodes.ICONST_0 + tableColumns.length); methodVisitor.visitTypeInsn(Opcodes.ANEWARRAY, Type.getDescriptor(Object[].class)); methodVisitor.visitInsn(Opcodes.DUP); for (int i = 0; i < tableColumns.length; i++) { Object[] tableColumn = tableColumns[i]; methodVisitor.visitInsn(Opcodes.ICONST_0 + i); methodVisitor.visitInsn(Opcodes.ICONST_2); methodVisitor.visitTypeInsn(Opcodes.ANEWARRAY, Type.getInternalName(Object.class)); methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitInsn(Opcodes.ICONST_0); methodVisitor.visitLdcInsn(tableColumn[0]); methodVisitor.visitInsn(Opcodes.AASTORE); methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitInsn(Opcodes.ICONST_1); methodVisitor.visitIntInsn(Opcodes.BIPUSH, (Integer) tableColumn[1]); methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Integer.class), "valueOf", Type.getMethodDescriptor(Type.getType(Integer.class), Type.INT_TYPE), false); methodVisitor.visitInsn(Opcodes.AASTORE); methodVisitor.visitInsn(Opcodes.AASTORE); if (i < (tableColumns.length - 1)) { methodVisitor.visitInsn(Opcodes.DUP); } } methodVisitor.visitFieldInsn(Opcodes.PUTSTATIC, Type.getInternalName(BuildAutoUpgradeTestEntityModelImpl.class), "TABLE_COLUMNS", Type.getDescriptor(Object[][].class)); methodVisitor.visitInsn(Opcodes.RETURN); methodVisitor.visitMaxs(0, 0); methodVisitor.visitEnd(); }