List of usage examples for org.objectweb.asm Opcodes IFNULL
int IFNULL
To view the source code for org.objectweb.asm Opcodes IFNULL.
Click Source Link
From source file:com.codename1.tools.translator.bytecodes.Jump.java
License:Open Source License
@Override public void appendInstruction(StringBuilder b, List<Instruction> instructions) { b.append(" "); switch (opcode) { case Opcodes.IFEQ: b.append("if(POP_INT() == 0) /* IFEQ */ "); break;// w w w.j a va 2 s.c o m case Opcodes.IFNE: b.append("if(POP_INT() != 0) /* IFNE */ "); break; case Opcodes.IFLT: b.append("if(POP_INT() < 0) /* IFLT */ "); break; case Opcodes.IFGE: b.append("if(POP_INT() >= 0) /* IFGE */ "); break; case Opcodes.IFGT: b.append("if(POP_INT() > 0) /* IFGT */ "); break; case Opcodes.IFLE: b.append("if(POP_INT() <= 0) /* IFLE */ "); break; case Opcodes.IF_ICMPEQ: b.append("SP-=2; if((*SP).data.i == SP[1].data.i) /* IF_ICMPEQ */ "); break; case Opcodes.IF_ICMPNE: b.append("SP-=2; if((*SP).data.i != SP[1].data.i) /* IF_ICMPNE */ "); break; case Opcodes.IF_ICMPLT: b.append("SP-=2; if((*SP).data.i < SP[1].data.i) /* IF_ICMPLT */ "); break; case Opcodes.IF_ICMPGE: b.append("SP-=2; if((*SP).data.i >= SP[1].data.i) /* IF_ICMPGE */ "); break; case Opcodes.IF_ICMPGT: b.append("SP-=2; if((*SP).data.i > SP[1].data.i) /* IF_ICMPGT */ "); break; case Opcodes.IF_ICMPLE: b.append("SP-=2; if((*SP).data.i <= SP[1].data.i) /* IF_ICMPLE */ "); break; case Opcodes.IF_ACMPEQ: b.append("SP-=2; if((*SP).data.o == SP[1].data.o) /* IF_ACMPEQ */ "); break; case Opcodes.IF_ACMPNE: b.append("SP-=2; if((*SP).data.o != SP[1].data.o) /* IF_ACMPNE */ "); break; case Opcodes.GOTO: // this space intentionally left blank break; case Opcodes.JSR: b.append("/* JSR TODO */"); /*b.append("PUSH_") b.append("goto label_"); b.append(label.toString()); b.append(";\n"); b.append("JSR_RETURN_LABEL_"); b.append(jsrCounter); b.append(":"); jsrCounter++;*/ return; case Opcodes.IFNULL: b.append("if(POP_OBJ() == JAVA_NULL) /* IFNULL */ "); break; case Opcodes.IFNONNULL: b.append("if(POP_OBJ() != JAVA_NULL) /* IFNONNULL */ "); break; } if (TryCatch.isTryCatchInMethod()) { b.append("JUMP_TO(label_"); b.append(label.toString()); b.append(", "); b.append(LabelInstruction.getLabelCatchDepth(label, instructions)); b.append(");\n"); } else { b.append("goto label_"); b.append(label.toString()); b.append(";\n"); } }
From source file:com.github.anba.es6draft.compiler.assembler.InstructionAssembler.java
License:Open Source License
public void ifnull(Jump jump) { methodVisitor.visitJumpInsn(Opcodes.IFNULL, jump.target()); stack.ifnull(jump); }
From source file:com.google.devtools.build.android.desugar.BytecodeTypeInference.java
License:Open Source License
@Override public void visitJumpInsn(int opcode, Label label) { switch (opcode) { case Opcodes.IFEQ: case Opcodes.IFNE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFLE: pop();//ww w .jav a2 s. c om break; case Opcodes.IF_ICMPEQ: case Opcodes.IF_ICMPNE: case Opcodes.IF_ICMPLT: case Opcodes.IF_ICMPGE: case Opcodes.IF_ICMPGT: case Opcodes.IF_ICMPLE: case Opcodes.IF_ACMPEQ: case Opcodes.IF_ACMPNE: pop(2); break; case Opcodes.GOTO: break; case Opcodes.JSR: throw new RuntimeException("The JSR instruction is not supported."); case Opcodes.IFNULL: case Opcodes.IFNONNULL: pop(1); break; default: throw new RuntimeException("Unhandled opcode " + opcode); } super.visitJumpInsn(opcode, label); }
From source file:com.google.devtools.build.lib.syntax.compiler.Jump.java
License:Open Source License
/** * Builds a conditional jump for one reference type operand from the stack compared to null. *//*from w w w.ja v a 2 s . co m*/ public static JumpWithoutTarget ifReferenceOperandToNull(ReferenceComparison comparison) { return new JumpWithoutTarget(Opcodes.IFNULL + comparison.ordinal(), new Size(-1, 0)); }
From source file:com.google.test.metric.asm.MethodVisitorBuilder.java
License:Apache License
public void visitJumpInsn(final int opcode, final Label label) { if (opcode == Opcodes.GOTO) { recorder.add(new Runnable() { public void run() { block.addOp(new Transform(lineNumber, "GOTO", null, null, null)); block.unconditionalGoto(label); }/*from w ww. jav a 2s. c om*/ }); } else if (opcode == Opcodes.JSR) { recorder.add(new Runnable() { public void run() { block.jumpSubroutine(label, lineNumber); } }); } else { recorder.add(new Runnable() { public void run() { cyclomaticComplexity.add(lineNumber); switch (opcode) { case Opcodes.IFEQ: if1("IFEQ"); break; case Opcodes.IFNE: if1("IFNE"); break; case Opcodes.IFLT: if1("IFLT"); break; case Opcodes.IFGE: if1("IFGE"); break; case Opcodes.IFGT: if1("IFGT"); break; case Opcodes.IFLE: if1("IFLE"); break; case Opcodes.IFNONNULL: if1("IFNONNULL"); break; case Opcodes.IFNULL: if1("IFNULL"); break; case Opcodes.IF_ACMPEQ: if2("IF_ACMPEQ"); break; case Opcodes.IF_ACMPNE: if2("IF_ACMPNE"); break; case Opcodes.IF_ICMPEQ: if2("IF_ICMPEQ"); break; case Opcodes.IF_ICMPGE: if2("IF_ICMPGE"); break; case Opcodes.IF_ICMPGT: if2("IF_ICMPGT"); break; case Opcodes.IF_ICMPLE: if2("IF_ICMPLE"); break; case Opcodes.IF_ICMPLT: if2("IF_ICMPLT"); break; case Opcodes.IF_ICMPNE: if2("IF_ICMPNE"); break; default: throw new UnsupportedOperationException("" + opcode); } block.conditionalGoto(label); } private void if1(String name) { block.addOp(new Transform(lineNumber, name, JavaType.INT, null, null)); } private void if2(String name) { block.addOp(new Transform(lineNumber, name, JavaType.INT, JavaType.INT, null)); } }); } }
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 . ja v a2s . c o m _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.lucidtechnics.blackboard.TargetConstructor.java
License:Apache License
private static final byte[] createWrapperObjectByteArray(String _targetName, Class _class) { ClassWriter classWriter = new ClassWriter(true); FieldVisitor fieldVisitor;// w ww . 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.junitflood.jvm.OperandStack.java
License:Apache License
public void performJumpInsn(int opcode, Label label) { switch (opcode) { case Opcodes.IFEQ: case Opcodes.IFNE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFLE: case Opcodes.IFNULL: case Opcodes.IFNONNULL: pop();// ww w.j a va 2 s .c o m break; case Opcodes.IF_ICMPEQ: case Opcodes.IF_ICMPNE: case Opcodes.IF_ICMPLT: case Opcodes.IF_ICMPGE: case Opcodes.IF_ICMPGT: case Opcodes.IF_ICMPLE: case Opcodes.IF_ACMPEQ: case Opcodes.IF_ACMPNE: pop2(); break; case Opcodes.GOTO: //nop break; case Opcodes.JSR: //nop -- a fudge break; } }
From source file:com.mogujie.instantrun.Redirection.java
License:Apache License
/** * Adds the instructions to do a generic redirection. *//*w ww . j av a 2s . com*/ protected void redirect(GeneratorAdapter mv, int change) { // code to check if a new implementation of the current class is available. Label l0 = new Label(); mv.loadLocal(change); mv.visitJumpInsn(Opcodes.IFNULL, l0); doRedirect(mv, change); // Return if (type == Type.VOID_TYPE) { mv.pop(); } else { ByteCodeUtils.unbox(mv, type); } mv.returnValue(); // jump label for classes without any new implementation, just invoke the original // method implementation. mv.visitLabel(l0); }
From source file:com.nginious.http.xsp.expr.AttributeValue.java
License:Apache License
/** * Creates bytecode for evaluating this attribute value. The bytecode is created using the * specified method visitor and creates a result of specified type. * //w w w . j a v a 2s. com * @param visitor the method visitor * @param type the type */ void compile(MethodVisitor visitor, Type type) { visitor.visitLdcInsn(this.name); visitor.visitMethodInsn(Opcodes.INVOKESTATIC, "com/nginious/http/xsp/expr/Expression", "getVariable", "(Ljava/lang/String;)Ljava/lang/Object;"); if (type != Type.ANY) { visitor.visitInsn(Opcodes.DUP); } if (type == Type.STRING) { Label nullLabel = new Label(); Label notNullLabel = new Label(); visitor.visitJumpInsn(Opcodes.IFNULL, nullLabel); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "toString", "()Ljava/lang/String;"); visitor.visitJumpInsn(Opcodes.GOTO, notNullLabel); visitor.visitLabel(nullLabel); visitor.visitInsn(Opcodes.POP); visitor.visitInsn(Opcodes.ACONST_NULL); visitor.visitLabel(notNullLabel); } else if (type == Type.INT) { Label nullLabel = new Label(); Label notNullLabel = new Label(); visitor.visitJumpInsn(Opcodes.IFNULL, nullLabel); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "toString", "()Ljava/lang/String;"); visitor.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Integer", "parseInt", "(Ljava/lang/String;)I"); visitor.visitJumpInsn(Opcodes.GOTO, notNullLabel); visitor.visitLabel(nullLabel); visitor.visitInsn(Opcodes.POP); visitor.visitLdcInsn(0); visitor.visitLabel(notNullLabel); } else if (type == Type.DOUBLE) { Label nullLabel = new Label(); Label notNullLabel = new Label(); visitor.visitJumpInsn(Opcodes.IFNULL, nullLabel); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "toString", "()Ljava/lang/String;"); visitor.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double", "parseDouble", "(Ljava/lang/String;)D"); visitor.visitJumpInsn(Opcodes.GOTO, notNullLabel); visitor.visitLabel(nullLabel); visitor.visitInsn(Opcodes.POP); visitor.visitLdcInsn(0.0d); visitor.visitLabel(notNullLabel); } }