List of usage examples for org.objectweb.asm Opcodes DUP
int DUP
To view the source code for org.objectweb.asm Opcodes DUP.
Click Source Link
From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.rndfuncRule.java
License:Open Source License
@Override public boolean execute(GenerationContext generationContext) throws Exception { try {// w ww.j a v a 2 s. c o m /* * get the operands */ Dispatcher.dispatchChildren(generationContext); /* * declare the local var Random */ generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitTypeInsn(Opcodes.NEW, "java/util/Random"); generationContext.getMethodVisitor().visitInsn(Opcodes.DUP); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/Random", "<init>", "()V"); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/khubla/jvmbasic/jvmbasicrt/Value", "getInteger", "()Ljava/lang/Integer;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Integer", "intValue", "()I"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/Random", "nextInt", "(I)I"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/Integer;)V"); return true; } catch (final Exception e) { throw new Exception("Exception in execute", e); } }
From source file:com.khubla.jvmbasic.jvmbasicc.JVMBasicCompiler.java
License:Open Source License
/** * generate init.//from w w w .jav a 2 s . com * <p> * This inits the class members and assigns class members, such as the ExecutionContext. * </p> * <p> * <code> * public ExecutionContext executionContext = new ExecutionContext(); * </code> * </p> */ protected void generateInit(String className, ClassWriter classWriter) throws Exception { try { final MethodVisitor methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); methodVisitor.visitCode(); /* * call init() */ final Label l0 = new Label(); methodVisitor.visitLabel(l0); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); /* * create a new execution context and assign it */ final Label l1 = new Label(); methodVisitor.visitLabel(l1); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitTypeInsn(Opcodes.NEW, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT); methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "<init>", "()V"); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, className, RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); /* * return */ final Label l2 = new Label(); methodVisitor.visitLabel(l2); methodVisitor.visitLineNumber(8, l2); methodVisitor.visitInsn(Opcodes.RETURN); /* * declare variables */ final Label l3 = new Label(); methodVisitor.visitLabel(l3); methodVisitor.visitLocalVariable("this", "L" + className + ";", null, l0, l3, 0); methodVisitor.visitMaxs(3, 1); methodVisitor.visitEnd(); } catch (final Exception e) { throw new Exception("Exception in generateInit", e); } }
From source file:com.khubla.jvmbasic.jvmbasicc.JVMBasicCompiler.java
License:Open Source License
/** * generate void main(String[])/*from w w w. j a v a 2s . c o m*/ * <p> * <code> * public static void main(String[] args) { * ExampleProgram exampleProgram = new ExampleProgram(); * try { * exampleProgram.inputStream = System.in; * exampleProgram.outputStream = System.out; * exampleProgram.program(); * } catch (Exception e) { * e.printStackTrace(); * } * } * </code> * </p> */ protected void generateMain(String classname, ClassWriter classWriter) throws Exception { try { /* * make method */ final MethodVisitor methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null); methodVisitor.visitCode(); final Label l0 = new Label(); final Label l1 = new Label(); final Label l2 = new Label(); methodVisitor.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception"); final Label l3 = new Label(); methodVisitor.visitLabel(l3); /* * declare a local instance of the class in the void() main, store as variable 1. */ methodVisitor.visitTypeInsn(Opcodes.NEW, classname); methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, classname, "<init>", "()V"); methodVisitor.visitVarInsn(Opcodes.ASTORE, 1); /* * assign the input stream */ methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "in", "Ljava/io/InputStream;"); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, classname, "inputStream", "Ljava/io/InputStream;"); /* * assign the output stream */ methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, classname, "outputStream", "Ljava/io/PrintStream;"); /* * load the class instance from variable 1 and call "program" */ methodVisitor.visitLabel(l0); methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, classname, "program", "()V"); methodVisitor.visitLabel(l1); final Label l4 = new Label(); methodVisitor.visitJumpInsn(Opcodes.GOTO, l4); methodVisitor.visitLabel(l2); methodVisitor.visitFrame(Opcodes.F_FULL, 2, new Object[] { "[Ljava/lang/String;", classname }, 1, new Object[] { "java/lang/Exception" }); methodVisitor.visitVarInsn(Opcodes.ASTORE, 2); final Label l5 = new Label(); methodVisitor.visitLabel(l5); methodVisitor.visitLineNumber(21, l5); methodVisitor.visitVarInsn(Opcodes.ALOAD, 2); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Exception", "printStackTrace", "()V"); /* * return */ methodVisitor.visitLabel(l4); methodVisitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null); methodVisitor.visitInsn(Opcodes.RETURN); /* * declare the parameters */ final Label l6 = new Label(); methodVisitor.visitLabel(l6); methodVisitor.visitLocalVariable("args", "[Ljava/lang/String;", null, l3, l6, 0); methodVisitor.visitLocalVariable("exampleProgram", "L" + classname + ";", null, l0, l6, 1); methodVisitor.visitLocalVariable("e", "Ljava/lang/Exception;", null, l5, l4, 2); /* * done */ methodVisitor.visitMaxs(2, 3); methodVisitor.visitEnd(); } catch (final Exception e) { throw new Exception("Exception in generateMain", e); } }
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();/* w w w .jav a 2s . c o m*/ 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.nio.intraband.proxy.IntrabandProxyUtilTest.java
License:Open Source License
@Test public void testRewriteGetProxyMethodSignaturesMethodNode() { class TestClass { @SuppressWarnings("unused") public final String[] PROXY_METHOD_SIGNATURES = _getProxyMethodSignatures(); private String[] _getProxyMethodSignatures() { return new String[0]; }//from www . j ava2 s.com } ClassNode classNode = _loadClass(TestClass.class); String[] proxyMethodSignatures = { "testSignature1", "testSignature2", "testSignature3" }; IntrabandProxyUtil.rewriteGetProxyMethodSignaturesMethodNode(classNode, proxyMethodSignatures); MethodNode methodNode = ASMUtil.findMethodNode(classNode.methods, "_getProxyMethodSignatures", Type.getType(String[].class)); InsnList insnList = methodNode.instructions; Iterator<AbstractInsnNode> iterator = insnList.iterator(); _assertInsnNode(iterator.next(), Opcodes.ICONST_3); _assertTypeInsnNode(iterator.next(), Opcodes.ANEWARRAY, String.class); for (int i = 0; i < proxyMethodSignatures.length; i++) { _assertInsnNode(iterator.next(), Opcodes.DUP); _assertInsnNode(iterator.next(), Opcodes.ICONST_0 + i); _assertLdcInsnNode(iterator.next(), Opcodes.LDC, proxyMethodSignatures[i]); _assertInsnNode(iterator.next(), Opcodes.AASTORE); } _assertInsnNode(iterator.next(), Opcodes.ARETURN); Assert.assertFalse(iterator.hasNext()); }
From source file:com.liferay.portal.nio.intraband.proxy.IntrabandProxyUtilTest.java
License:Open Source License
private void _doTestCreateProxyMethodNode(Method method, int index, String skeletonId, String stubInternalName) { MethodNode proxyMethodNode = IntrabandProxyUtil.createProxyMethodNode(method, index, skeletonId, Type.getType(stubInternalName)); _assertMethodNodeSignature(proxyMethodNode, method.getModifiers() & ~Modifier.ABSTRACT, method.getName(), Type.getMethodDescriptor(method), method.getExceptionTypes()); InsnList insnList = proxyMethodNode.instructions; Iterator<AbstractInsnNode> iterator = insnList.iterator(); // NEW com/liferay/portal/kernel/io/Serializer _assertTypeInsnNode(iterator.next(), Opcodes.NEW, Serializer.class); // DUP/*from w ww .j ava2s. c om*/ _assertInsnNode(iterator.next(), Opcodes.DUP); // INVOKESPECIAL com/liferay/portal/kernel/io/Serializer <init> ()V _assertMethodInsnNode(iterator.next(), Opcodes.INVOKESPECIAL, Type.getInternalName(Serializer.class), "<init>", Type.VOID_TYPE); // ASTORE argumentsSize Type methodType = Type.getType(method); int argumentsAndReturnSizes = methodType.getArgumentsAndReturnSizes(); int argumentsSize = argumentsAndReturnSizes >> 2; _assertVarInsnNode(iterator.next(), Opcodes.ASTORE, argumentsSize); // ALOAD argumentsSize _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, argumentsSize); // LDC skeletonId _assertLdcInsnNode(iterator.next(), Opcodes.LDC, skeletonId); // INVOKEVIRTUAL com/liferay/portal/kernel/io/Serializer writeString // (Ljava/lang/String;)V _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Serializer.class), "writeString", Type.VOID_TYPE, Type.getType(String.class)); // ALOAD argumentsSize _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, argumentsSize); // ALOAD 0 _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, 0); // GETFIELD stubInternalName _id Ljava/lang/String; _assertFieldInsnNode(iterator.next(), Opcodes.GETFIELD, stubInternalName, "_id", String.class); // INVOKEVIRTUAL com/liferay/portal/kernel/io/Serializer writeString // (Ljava/lang/String;)V _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Serializer.class), "writeString", Type.VOID_TYPE, Type.getType(String.class)); // ALOAD argumentsSize _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, argumentsSize); if (index <= 5) { // ICONST_index _assertInsnNode(iterator.next(), Opcodes.ICONST_0 + index); } else { // BIPUSH index _assertIntInsnNode(iterator.next(), Opcodes.BIPUSH, index); } // INVOKEVIRTUAL com/liferay/portal/kernel/io/Serializer writeInt (I)V _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Serializer.class), "writeInt", Type.VOID_TYPE, Type.INT_TYPE); Class<?>[] parameterTypes = method.getParameterTypes(); int offset = 1; for (int i = 0; i < parameterTypes.length; i++) { Class<?> parameterClass = parameterTypes[i]; // ALOAD argumentsSize _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, argumentsSize); // xLOAD i Type parameterType = Type.getType(parameterClass); _assertVarInsnNode(iterator.next(), parameterType.getOpcode(Opcodes.ILOAD), offset); offset += parameterType.getSize(); if (parameterClass.isPrimitive() || (parameterClass == String.class)) { String name = TextFormatter.format(parameterClass.getSimpleName(), TextFormatter.G); _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Serializer.class), "write".concat(name), Type.VOID_TYPE, parameterType); } else { _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Serializer.class), "writeObject", Type.VOID_TYPE, Type.getType(Serializable.class)); } } // ALOAD 0 _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, 0); // ALOAD argumentsSize _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, argumentsSize); Class<?> returnClass = method.getReturnType(); Type returnType = Type.getType(returnClass); if (returnClass == void.class) { // INVOKESPECIAL stubInternalName _send // (Lcom/liferay/portal/kernel/io/Serializer;)V _assertMethodInsnNode(iterator.next(), Opcodes.INVOKESPECIAL, stubInternalName, "_send", Type.VOID_TYPE, Type.getType(Serializer.class)); _assertInsnNode(iterator.next(), Opcodes.RETURN); } else { // INVOKESPECIAL stubInternalName _syncSend // (Lcom/liferay/portal/kernel/io/Serializer;)Ljava/io/Serializable; _assertMethodInsnNode(iterator.next(), Opcodes.INVOKESPECIAL, stubInternalName, "_syncSend", Type.getType(Serializable.class), Type.getType(Serializer.class)); if (returnClass.isPrimitive()) { // ASTORE argumentsSize + 1 _assertVarInsnNode(iterator.next(), Opcodes.ASTORE, argumentsSize + 1); // ALOAD argumentsSize + 1 _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, argumentsSize + 1); // IFNULL nullCheckLabel LabelNode nullCheckLabelNode = _assertJumpInsnNode(iterator.next(), Opcodes.IFNULL); // ALOAD argumentsSize + 1 _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, argumentsSize + 1); // CHECKCAST returnType _assertTypeInsnNode(iterator.next(), Opcodes.CHECKCAST, _autoboxingMap.get(returnClass)); if (returnClass == boolean.class) { // INVOKEVIRTUAL java/lang/Boolean booleanValue ()Z _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Boolean.class), "booleanValue", Type.BOOLEAN_TYPE); } else if (returnClass == byte.class) { // INVOKEVIRTUAL java/lang/Number intValue ()I _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Number.class), "intValue", Type.INT_TYPE); } else if (returnClass == char.class) { // INVOKEVIRTUAL java/lang/Character charValue ()C _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Character.class), "charValue", Type.CHAR_TYPE); } else if (returnClass == double.class) { // INVOKEVIRTUAL java/lang/Number doubleValue ()D _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Number.class), "doubleValue", Type.DOUBLE_TYPE); } else if (returnClass == float.class) { // INVOKEVIRTUAL java/lang/Number floatValue ()F _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Number.class), "floatValue", Type.FLOAT_TYPE); } else if (returnClass == int.class) { // INVOKEVIRTUAL java/lang/Number intValue ()I _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Number.class), "intValue", Type.INT_TYPE); } else if (returnClass == long.class) { // INVOKEVIRTUAL java/lang/Number longValue ()J _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Number.class), "longValue", Type.LONG_TYPE); } else if (returnClass == short.class) { // INVOKEVIRTUAL java/lang/Number intValue ()I _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Number.class), "intValue", Type.INT_TYPE); } // xRETURN _assertInsnNode(iterator.next(), returnType.getOpcode(Opcodes.IRETURN)); // nullCheckLabel Assert.assertSame(nullCheckLabelNode, iterator.next()); // xRETURN null/0 if (!returnClass.isPrimitive()) { _assertInsnNode(iterator.next(), Opcodes.ACONST_NULL); _assertInsnNode(iterator.next(), Opcodes.ARETURN); } else if (returnClass == void.class) { _assertInsnNode(iterator.next(), Opcodes.RETURN); } else if (returnClass == float.class) { _assertInsnNode(iterator.next(), Opcodes.FCONST_0); _assertInsnNode(iterator.next(), Opcodes.FRETURN); } else if (returnClass == double.class) { _assertInsnNode(iterator.next(), Opcodes.DCONST_0); _assertInsnNode(iterator.next(), Opcodes.DRETURN); } else if (returnClass == long.class) { _assertInsnNode(iterator.next(), Opcodes.LCONST_0); _assertInsnNode(iterator.next(), Opcodes.LRETURN); } else { _assertInsnNode(iterator.next(), Opcodes.ICONST_0); _assertInsnNode(iterator.next(), Opcodes.IRETURN); } } else { if (returnClass != Object.class) { // CHECKCAST _assertTypeInsnNode(iterator.next(), Opcodes.CHECKCAST, returnClass); } // ARETURN _assertInsnNode(iterator.next(), Opcodes.ARETURN); } } Assert.assertFalse(iterator.hasNext()); }
From source file:com.liferay.portal.upgrade.test.BaseBuildAutoUpgradeTestCase.java
License:Open Source License
private void _initTableColumns(MethodVisitor methodVisitor, Object[][] tableColumns) { methodVisitor.visitCode();/*from ww w . j a v a2 s. c o 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(); }
From source file:com.lucidtechnics.blackboard.TargetConstructor.java
License:Apache License
private static final byte[] createWrapperObjectByteArray(String _targetName, Class _class) { ClassWriter classWriter = new ClassWriter(true); FieldVisitor fieldVisitor;/*from www . j a v a 2 s .c om*/ MethodVisitor methodVisitor; String superClassName = _class.getCanonicalName().replaceAll("\\.", "/"); String[] superClassNameParts = superClassName.split("/"); String simpleClassName = superClassNameParts[superClassNameParts.length - 1]; String blackboardSubClassName = "com/lucidtechnics/blackboard/wrapper/" + superClassName + "Wrapper"; classWriter.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, blackboardSubClassName, null, superClassName, new String[] { "com/lucidtechnics/blackboard/Target" }); classWriter.visitSource(simpleClassName, null); { fieldVisitor = classWriter.visitField(Opcodes.ACC_PRIVATE, "blackboardObject", "Ljava/lang/Object;", null, null); fieldVisitor.visitEnd(); } { fieldVisitor = classWriter.visitField(Opcodes.ACC_PRIVATE, "intercepter", "Lcom/lucidtechnics/blackboard/Intercepter;", null, null); fieldVisitor.visitEnd(); } { methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "getBlackboardObject", "()Ljava/lang/Object;", null, null); methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitFieldInsn(Opcodes.GETFIELD, blackboardSubClassName, "blackboardObject", "Ljava/lang/Object;"); methodVisitor.visitInsn(Opcodes.ARETURN); methodVisitor.visitMaxs(0, 0); methodVisitor.visitEnd(); } { methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "getIntercepter", "()Lcom/lucidtechnics/blackboard/Intercepter;", null, null); methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitFieldInsn(Opcodes.GETFIELD, blackboardSubClassName, "intercepter", "Lcom/lucidtechnics/blackboard/Intercepter;"); methodVisitor.visitInsn(Opcodes.ARETURN); methodVisitor.visitMaxs(0, 0); methodVisitor.visitEnd(); } { methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "setBlackboardObject", "(Ljava/lang/Object;)V", null, null); methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, blackboardSubClassName, "blackboardObject", "Ljava/lang/Object;"); methodVisitor.visitInsn(Opcodes.RETURN); methodVisitor.visitMaxs(0, 0); methodVisitor.visitEnd(); } { methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "setIntercepter", "(Lcom/lucidtechnics/blackboard/Intercepter;)V", null, null); methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, blackboardSubClassName, "intercepter", "Lcom/lucidtechnics/blackboard/Intercepter;"); methodVisitor.visitInsn(Opcodes.RETURN); methodVisitor.visitMaxs(0, 0); methodVisitor.visitEnd(); } { methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, superClassName, "<init>", "()V"); methodVisitor.visitInsn(Opcodes.RETURN); methodVisitor.visitMaxs(0, 0); methodVisitor.visitEnd(); } List mutatorMethodList = findMutatorMethods(_class); Iterator mutatorMethods = mutatorMethodList.iterator(); while (mutatorMethods.hasNext() == true) { Method method = (Method) mutatorMethods.next(); MethodInfo methodInfo = (MethodInfo) MethodInfoTransformer.getInstance().transform(method); Signature signature = methodInfo.getSignature(); String methodName = signature.getName(); String parameterType = signature.getArgumentTypes()[0].getDescriptor(); String returnType = signature.getReturnType().getDescriptor(); String[] exceptionTypeArray = createExceptionTypeArray(methodInfo.getExceptionTypes()); { methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, methodName, "(" + parameterType + ")" + returnType, null, exceptionTypeArray); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, blackboardSubClassName, "getIntercepter", "()Lcom/lucidtechnics/blackboard/Intercepter;"); Label l1 = new Label(); methodVisitor.visitJumpInsn(Opcodes.IFNULL, l1); methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, blackboardSubClassName, "getIntercepter", "()Lcom/lucidtechnics/blackboard/Intercepter;"); methodVisitor.visitLdcInsn(superClassName); methodVisitor.visitLdcInsn(blackboardSubClassName); methodVisitor.visitLdcInsn(methodName); methodVisitor.visitLdcInsn(_targetName); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); int tempOpCode = getLoadOpcode(parameterType); methodVisitor.visitVarInsn(tempOpCode, 1); if (tempOpCode == Opcodes.ALOAD) { //this is an object. methodVisitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, "com/lucidtechnics/blackboard/Intercepter", "monitor", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V"); } else { //it is a primitive. methodVisitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, "com/lucidtechnics/blackboard/Intercepter", "monitor", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;" + parameterType + ")V"); } methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, blackboardSubClassName, "getBlackboardObject", "()Ljava/lang/Object;"); methodVisitor.visitTypeInsn(Opcodes.CHECKCAST, superClassName); methodVisitor.visitVarInsn(getLoadOpcode(parameterType), 1); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, superClassName, methodName, "(" + parameterType + ")" + returnType); methodVisitor.visitLabel(l1); methodVisitor.visitInsn(getReturnOpcode(returnType)); methodVisitor.visitMaxs(0, 0); methodVisitor.visitEnd(); } } List otherPublicMethodList = findOtherPublicMethods(_class); Iterator otherPublicMethods = otherPublicMethodList.iterator(); while (otherPublicMethods.hasNext() == true) { Method method = (Method) otherPublicMethods.next(); MethodInfo methodInfo = (MethodInfo) MethodInfoTransformer.getInstance().transform(method); Signature signature = methodInfo.getSignature(); String methodName = signature.getName(); String parameterTypes = constructParameterTypes(signature.getArgumentTypes()); String returnType = signature.getReturnType().getDescriptor(); String[] exceptionTypeArray = createExceptionTypeArray(methodInfo.getExceptionTypes()); if (logger.isDebugEnabled() == true) { logger.debug("Processing method: " + methodName); } if (logger.isDebugEnabled() == true) { logger.debug("Parameter types are: " + parameterTypes); } if ("toString".equalsIgnoreCase(methodName) == false) { methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, methodName, "(" + parameterTypes + ")" + returnType, null, exceptionTypeArray); methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, blackboardSubClassName, "getBlackboardObject", "()Ljava/lang/Object;"); methodVisitor.visitTypeInsn(Opcodes.CHECKCAST, superClassName); methodVisitor.visitVarInsn(Opcodes.ASTORE, signature.getArgumentTypes().length + 1); methodVisitor.visitVarInsn(Opcodes.ALOAD, signature.getArgumentTypes().length + 1); loadParameters(methodVisitor, signature.getArgumentTypes()); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, superClassName, methodName, "(" + parameterTypes + ")" + returnType); methodVisitor.visitInsn(getReturnOpcode(returnType)); methodVisitor.visitMaxs(0, 0); methodVisitor.visitEnd(); } } List protectedMethodList = findProtectedMethods(_class); Iterator protectedMethods = protectedMethodList.iterator(); while (protectedMethods.hasNext() == true) { Method method = (Method) protectedMethods.next(); MethodInfo methodInfo = (MethodInfo) MethodInfoTransformer.getInstance().transform(method); Signature signature = methodInfo.getSignature(); String methodName = signature.getName(); String parameterTypes = constructParameterTypes(signature.getArgumentTypes()); String returnType = signature.getReturnType().getDescriptor(); String[] exceptionTypeArray = createExceptionTypeArray(methodInfo.getExceptionTypes()); if (logger.isDebugEnabled() == true) { logger.debug("Processing method: " + methodName + " and parameter types are: " + parameterTypes); } { methodVisitor = classWriter.visitMethod(Opcodes.ACC_PROTECTED, methodName, "(" + parameterTypes + ")" + returnType, null, exceptionTypeArray); methodVisitor.visitCode(); methodVisitor.visitTypeInsn(Opcodes.NEW, "com/lucidtechnics/blackboard/BlackboardException"); methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitLdcInsn("Unable to access protected methods on Blackboard object"); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/lucidtechnics/blackboard/BlackboardException", "<init>", "(Ljava/lang/String;)V"); methodVisitor.visitInsn(Opcodes.ATHROW); methodVisitor.visitMaxs(0, 0); methodVisitor.visitEnd(); } } { methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null); methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, blackboardSubClassName, "getBlackboardObject", "()Ljava/lang/Object;"); methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, "com/lucidtechnics/blackboard/util/Utility", "toString", "(Ljava/lang/Object;)Ljava/lang/String;"); methodVisitor.visitInsn(getReturnOpcode("Ljava/lang/String;")); methodVisitor.visitMaxs(0, 0); methodVisitor.visitEnd(); } classWriter.visitEnd(); if (logger.isDebugEnabled() == true) { logger.debug("Finished creating new class: " + blackboardSubClassName + " for target class: " + superClassName + "."); } return classWriter.toByteArray(); }
From source file:com.mebigfatguy.exagent.StackTraceMethodVisitor.java
License:Apache License
private void injectCallStackPopulation() { // ExAgent.METHOD_INFO.get(); super.visitFieldInsn(Opcodes.GETSTATIC, EXASUPPORT_CLASS_NAME, "METHOD_INFO", signaturizeClass(THREADLOCAL_CLASS_NAME)); super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, THREADLOCAL_CLASS_NAME, "get", "()Ljava/lang/Object;", false); super.visitTypeInsn(Opcodes.CHECKCAST, LIST_CLASS_NAME); super.visitInsn(Opcodes.DUP); super.visitMethodInsn(Opcodes.INVOKEINTERFACE, LIST_CLASS_NAME, "size", "()I", true); super.visitVarInsn(Opcodes.ISTORE, depthLocalSlot); //new MethodInfo(cls, name, parmMap); super.visitTypeInsn(Opcodes.NEW, METHODINFO_CLASS_NAME); super.visitInsn(Opcodes.DUP); super.visitLdcInsn(clsName.replace('.', '/')); super.visitLdcInsn(methodName); if (parms.isEmpty()) { super.visitMethodInsn(Opcodes.INVOKESTATIC, COLLECTIONS_CLASS_NAME, "emptyList", "()Ljava/util/List;", false);/*from w ww . j a v a 2 s . c o m*/ } else { super.visitTypeInsn(Opcodes.NEW, ARRAYLIST_CLASS_NAME); super.visitInsn(Opcodes.DUP); super.visitIntInsn(Opcodes.BIPUSH, parms.size()); super.visitMethodInsn(Opcodes.INVOKESPECIAL, ARRAYLIST_CLASS_NAME, CTOR_NAME, "(I)V", false); for (Parm parm : parms) { super.visitInsn(Opcodes.DUP); switch (parm.signature) { case "C": super.visitVarInsn(Opcodes.ILOAD, parm.register); super.visitMethodInsn(Opcodes.INVOKESTATIC, STRING_CLASS_NAME, "valueOf", "(C)Ljava/lang/String;", false); break; case "Z": super.visitVarInsn(Opcodes.ILOAD, parm.register); super.visitMethodInsn(Opcodes.INVOKESTATIC, STRING_CLASS_NAME, "valueOf", "(Z)Ljava/lang/String;", false); break; case "B": case "S": case "I": super.visitVarInsn(Opcodes.ILOAD, parm.register); super.visitMethodInsn(Opcodes.INVOKESTATIC, STRING_CLASS_NAME, "valueOf", "(I)Ljava/lang/String;", false); break; case "J": super.visitVarInsn(Opcodes.LLOAD, parm.register); super.visitMethodInsn(Opcodes.INVOKESTATIC, STRING_CLASS_NAME, "valueOf", "(J)Ljava/lang/String;", false); break; case "F": super.visitVarInsn(Opcodes.FLOAD, parm.register); super.visitMethodInsn(Opcodes.INVOKESTATIC, STRING_CLASS_NAME, "valueOf", "(F)Ljava/lang/String;", false); break; case "D": super.visitVarInsn(Opcodes.DLOAD, parm.register); super.visitMethodInsn(Opcodes.INVOKESTATIC, STRING_CLASS_NAME, "valueOf", "(D)Ljava/lang/String;", false); break; default: super.visitVarInsn(Opcodes.ALOAD, parm.register); if (parm.signature.startsWith("[")) { char arrayElemTypeChar = parm.signature.charAt(1); if ((arrayElemTypeChar == 'L') || (arrayElemTypeChar == '[')) { super.visitMethodInsn(Opcodes.INVOKESTATIC, ARRAYS_CLASS_NAME, "toString", "([Ljava/lang/Object;)Ljava/lang/String;", false); } else { super.visitMethodInsn(Opcodes.INVOKESTATIC, ARRAYS_CLASS_NAME, "toString", "([" + arrayElemTypeChar + ")Ljava/lang/String;", false); } } else { super.visitMethodInsn(Opcodes.INVOKESTATIC, STRING_CLASS_NAME, "valueOf", "(Ljava/lang/Object;)Ljava/lang/String;", false); } break; } if (maxParmSize > 0) { super.visitInsn(Opcodes.DUP); super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, STRING_CLASS_NAME, "length", "()I", false); if (maxParmSize <= 127) { super.visitIntInsn(Opcodes.BIPUSH, maxParmSize); } else { super.visitLdcInsn(maxParmSize); } Label falseLabel = new Label(); super.visitJumpInsn(Opcodes.IF_ICMPLE, falseLabel); super.visitIntInsn(Opcodes.BIPUSH, 0); super.visitLdcInsn(maxParmSize); super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, STRING_CLASS_NAME, "substring", "(II)Ljava/lang/String;", false); super.visitLabel(falseLabel); } super.visitMethodInsn(Opcodes.INVOKEINTERFACE, LIST_CLASS_NAME, "add", "(Ljava/lang/Object;)Z", true); super.visitInsn(Opcodes.POP); } } super.visitMethodInsn(Opcodes.INVOKESPECIAL, METHODINFO_CLASS_NAME, CTOR_NAME, "(Ljava/lang/String;Ljava/lang/String;Ljava/util/List;)V", false); //add(methodInfo); super.visitMethodInsn(Opcodes.INVOKEINTERFACE, LIST_CLASS_NAME, "add", "(Ljava/lang/Object;)Z", true); super.visitInsn(Opcodes.POP); }
From source file:com.mebigfatguy.junitflood.jvm.OperandStack.java
License:Apache License
public void performInsn(int opcode) { switch (opcode) { case Opcodes.NOP: break;//from w ww .j a v a 2 s . c om case Opcodes.ACONST_NULL: { Operand op = new Operand(); op.setNull(true); push(op); } break; case Opcodes.ICONST_M1: { Operand op = new Operand(); op.setConstant(Integer.valueOf(-1)); push(op); } break; case Opcodes.ICONST_0: { Operand op = new Operand(); op.setConstant(Integer.valueOf(0)); push(op); } break; case Opcodes.ICONST_1: { Operand op = new Operand(); op.setConstant(Integer.valueOf(1)); push(op); } break; case Opcodes.ICONST_2: { Operand op = new Operand(); op.setConstant(Integer.valueOf(2)); push(op); } break; case Opcodes.ICONST_3: { Operand op = new Operand(); op.setConstant(Integer.valueOf(3)); push(op); } break; case Opcodes.ICONST_4: { Operand op = new Operand(); op.setConstant(Integer.valueOf(4)); push(op); } break; case Opcodes.ICONST_5: { Operand op = new Operand(); op.setConstant(Integer.valueOf(5)); push(op); } break; case Opcodes.LCONST_0: { Operand op = new Operand(); op.setConstant(Long.valueOf(0)); push(op); } break; case Opcodes.LCONST_1: { Operand op = new Operand(); op.setConstant(Long.valueOf(1)); push(op); } break; case Opcodes.FCONST_0: { Operand op = new Operand(); op.setConstant(Float.valueOf(0)); push(op); } break; case Opcodes.FCONST_1: { Operand op = new Operand(); op.setConstant(Float.valueOf(1)); push(op); } break; case Opcodes.FCONST_2: { Operand op = new Operand(); op.setConstant(Float.valueOf(2)); push(op); } break; case Opcodes.DCONST_0: { Operand op = new Operand(); op.setConstant(Double.valueOf(0)); push(op); } break; case Opcodes.DCONST_1: { Operand op = new Operand(); op.setConstant(Double.valueOf(1)); push(op); } break; case Opcodes.IALOAD: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LALOAD: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.FALOAD: { pop2(); Operand op = new Operand(); op.setSignature("F"); push(op); } break; case Opcodes.DALOAD: { pop2(); Operand op = new Operand(); op.setSignature("D"); push(op); } break; case Opcodes.AALOAD: { pop2(); Operand op = new Operand(); op.setSignature("Ljava/lang/Object;"); push(op); } break; case Opcodes.BALOAD: { pop2(); Operand op = new Operand(); op.setSignature("B"); push(op); } break; case Opcodes.CALOAD: { pop2(); Operand op = new Operand(); op.setSignature("C"); push(op); } break; case Opcodes.SALOAD: { pop2(); Operand op = new Operand(); op.setSignature("S"); push(op); } break; case Opcodes.IASTORE: case Opcodes.LASTORE: case Opcodes.FASTORE: case Opcodes.DASTORE: case Opcodes.AASTORE: case Opcodes.BASTORE: case Opcodes.CASTORE: case Opcodes.SASTORE: if (stack.size() < 2) { stack.clear(); } else { Operand value = stack.remove(stack.size() - 1); Operand reg = stack.remove(stack.size() - 1); registers.put(Integer.valueOf(reg.getRegister()), value); } break; case Opcodes.POP: pop(); break; case Opcodes.POP2: pop2(); break; case Opcodes.DUP: if (!stack.isEmpty()) { Operand op = stack.get(stack.size() - 1); push(op); } break; case Opcodes.DUP_X1: if (stack.size() >= 2) { Operand op = stack.get(stack.size() - 1); stack.add(stack.size() - 2, op); } break; case Opcodes.DUP_X2: if (stack.size() >= 2) { Operand op = stack.get(stack.size() - 2); String sig = op.getSignature(); op = stack.get(stack.size() - 1); if ("J".equals(sig) || "D".equals(sig)) { stack.add(stack.size() - 2, op); } else if (stack.size() >= 3) { stack.add(stack.size() - 3, op); } } break; case Opcodes.DUP2: if (stack.size() >= 2) { stack.add(stack.get(stack.size() - 2)); stack.add(stack.get(stack.size() - 2)); } break; case Opcodes.DUP2_X1: if (stack.size() >= 1) { Operand op = stack.get(stack.size() - 1); String sig = op.getSignature(); if ("J".equals(sig) || "D".equals(sig)) { if (stack.size() >= 3) { stack.add(stack.size() - 3, op); op = stack.get(stack.size() - 2); stack.add(stack.size() - 4, op); } } else { if (stack.size() >= 2) { stack.add(stack.size() - 2, op); } } } break; case Opcodes.DUP2_X2: if (stack.size() >= 1) { Operand op = stack.get(stack.size() - 1); String sig = op.getSignature(); if ("J".equals(sig) || "D".equals(sig)) { if (stack.size() >= 2) { op = stack.get(stack.size() - 2); sig = op.getSignature(); if ("J".equals(sig) || "D".equals(sig)) { op = stack.get(stack.size() - 1); stack.add(stack.size() - 2, op); } else { if (stack.size() >= 3) { op = stack.get(stack.size() - 1); stack.add(stack.size() - 3, op); } } } } else { if (stack.size() >= 3) { op = stack.get(stack.size() - 3); sig = op.getSignature(); if ("J".equals(sig) || "D".equals(sig)) { op = stack.get(stack.size() - 2); stack.add(stack.size() - 3, op); op = stack.get(stack.size() - 1); stack.add(stack.size() - 3, op); } else { if (stack.size() >= 4) { op = stack.get(stack.size() - 2); stack.add(stack.size() - 4, op); op = stack.get(stack.size() - 1); stack.add(stack.size() - 4, op); } } } } } break; case Opcodes.SWAP: if (stack.size() >= 2) { Operand op = stack.remove(stack.size() - 1); stack.add(stack.size() - 1, op); } break; case Opcodes.IADD: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LADD: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.FADD: { pop2(); Operand op = new Operand(); op.setSignature("F"); push(op); } break; case Opcodes.DADD: { pop2(); Operand op = new Operand(); op.setSignature("D"); push(op); } break; case Opcodes.ISUB: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LSUB: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.FSUB: { pop2(); Operand op = new Operand(); op.setSignature("F"); push(op); } break; case Opcodes.DSUB: { pop2(); Operand op = new Operand(); op.setSignature("D"); push(op); } break; case Opcodes.IMUL: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LMUL: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.FMUL: { pop2(); Operand op = new Operand(); op.setSignature("F"); push(op); } break; case Opcodes.DMUL: { pop2(); Operand op = new Operand(); op.setSignature("D"); push(op); } break; case Opcodes.IDIV: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LDIV: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.FDIV: { pop2(); Operand op = new Operand(); op.setSignature("F"); push(op); } break; case Opcodes.DDIV: { pop2(); Operand op = new Operand(); op.setSignature("D"); push(op); } break; case Opcodes.IREM: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LREM: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.FREM: { pop2(); Operand op = new Operand(); op.setSignature("F"); push(op); } break; case Opcodes.DREM: { pop2(); Operand op = new Operand(); op.setSignature("D"); push(op); } break; case Opcodes.INEG: { pop(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LNEG: { pop(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.FNEG: { pop(); Operand op = new Operand(); op.setSignature("F"); push(op); } break; case Opcodes.DNEG: { pop(); Operand op = new Operand(); op.setSignature("D"); push(op); } break; case Opcodes.ISHL: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LSHL: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.ISHR: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LSHR: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.IUSHR: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LUSHR: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.IAND: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LAND: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.IOR: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LOR: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.IXOR: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LXOR: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.I2L: { Operand lop = new Operand(); lop.setSignature("J"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { lop.setConstant(Long.valueOf(((Integer) o).longValue())); } } push(lop); } break; case Opcodes.I2F: { Operand fop = new Operand(); fop.setSignature("F"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { fop.setConstant(Float.valueOf(((Integer) o).floatValue())); } } push(fop); } break; case Opcodes.I2D: { Operand dop = new Operand(); dop.setSignature("D"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { dop.setConstant(Double.valueOf(((Integer) o).doubleValue())); } } push(dop); } break; case Opcodes.L2I: { Operand iop = new Operand(); iop.setSignature("I"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { iop.setConstant(Integer.valueOf(((Long) o).intValue())); } } push(iop); } break; case Opcodes.L2F: { Operand fop = new Operand(); fop.setSignature("F"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { fop.setConstant(Float.valueOf(((Long) o).floatValue())); } } push(fop); } break; case Opcodes.L2D: { Operand dop = new Operand(); dop.setSignature("D"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { dop.setConstant(Double.valueOf(((Long) o).doubleValue())); } } push(dop); } break; case Opcodes.F2I: { Operand iop = new Operand(); iop.setSignature("I"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { iop.setConstant(Integer.valueOf(((Float) o).intValue())); } } push(iop); } break; case Opcodes.F2L: { Operand lop = new Operand(); lop.setSignature("J"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { lop.setConstant(Long.valueOf(((Float) o).longValue())); } } push(lop); } break; case Opcodes.F2D: { Operand dop = new Operand(); dop.setSignature("D"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { dop.setConstant(Double.valueOf(((Float) o).doubleValue())); } } push(dop); } break; case Opcodes.D2I: { Operand iop = new Operand(); iop.setSignature("I"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { iop.setConstant(Integer.valueOf(((Double) o).intValue())); } } push(iop); } break; case Opcodes.D2L: { Operand lop = new Operand(); lop.setSignature("J"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { lop.setConstant(Long.valueOf(((Double) o).longValue())); } } push(lop); } break; case Opcodes.D2F: { Operand fop = new Operand(); fop.setSignature("F"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { fop.setConstant(Float.valueOf(((Double) o).floatValue())); } } push(fop); } break; case Opcodes.I2B: { Operand bop = new Operand(); bop.setSignature("B"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { bop.setConstant(Byte.valueOf(((Integer) o).byteValue())); } } push(bop); } break; case Opcodes.I2C: { Operand cop = new Operand(); cop.setSignature("C"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { cop.setConstant(Character.valueOf((char) ((Integer) o).intValue())); } } push(cop); } break; case Opcodes.I2S: { Operand sop = new Operand(); sop.setSignature("S"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { sop.setConstant(Short.valueOf((short) ((Integer) o).intValue())); } } push(sop); } break; case Opcodes.LCMP: case Opcodes.FCMPL: case Opcodes.FCMPG: case Opcodes.DCMPL: case Opcodes.DCMPG: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.IRETURN: case Opcodes.LRETURN: case Opcodes.FRETURN: case Opcodes.DRETURN: case Opcodes.ARETURN: pop(); break; case Opcodes.RETURN: //nop break; case Opcodes.ARRAYLENGTH: { pop(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.ATHROW: case Opcodes.MONITORENTER: case Opcodes.MONITOREXIT: pop(); break; } }