Java Code Examples for org.objectweb.asm.Opcodes#ARETURN

The following examples show how to use org.objectweb.asm.Opcodes#ARETURN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InstructionAssembler.java    From es6draft with MIT License 6 votes vote down vote up
/**
 * value → ∅
 */
public void _return() {
    Type returnType = method.methodDescriptor.returnType();
    switch (returnType.getOpcode(Opcodes.IRETURN)) {
    case Opcodes.IRETURN:
        ireturn();
        return;
    case Opcodes.LRETURN:
        lreturn();
        return;
    case Opcodes.FRETURN:
        freturn();
        return;
    case Opcodes.DRETURN:
        dreturn();
        return;
    case Opcodes.ARETURN:
        areturn();
        return;
    case Opcodes.RETURN:
        voidreturn();
        return;
    default:
        throw new IllegalArgumentException();
    }
}
 
Example 2
Source File: ReturnValuesMutator.java    From pitest with Apache License 2.0 6 votes vote down vote up
@Override
public void visitInsn(final int opcode) {

  switch (opcode) {
  case Opcodes.IRETURN:
    mutatePrimitiveIntegerReturn();
    break;
  case Opcodes.LRETURN:
    mutatePrimitiveLongReturn();
    break;
  case Opcodes.FRETURN:
    mutatePrimitiveFloatReturn();
    break;
  case Opcodes.DRETURN:
    mutatePrimitiveDoubleReturn();
    break;
  case Opcodes.ARETURN:
    mutateObjectReferenceReturn();
    break;
  default:
    super.visitInsn(opcode);
    break;
  }
}
 
Example 3
Source File: ConstructorTransformerMethodVisitor.java    From scott with MIT License 6 votes vote down vote up
@Override
public void visitInsn(int opcode) {
	if ((opcode == Opcodes.ARETURN) || (opcode == Opcodes.IRETURN)
			|| (opcode == Opcodes.LRETURN)
			|| (opcode == Opcodes.FRETURN)
			|| (opcode == Opcodes.DRETURN)) {
		throw new RuntimeException(new UnmodifiableClassException("Constructors are supposed to return void"));
	}
	if (opcode == Opcodes.RETURN) {
		super.visitVarInsn(Opcodes.ALOAD, 0);
		super.visitTypeInsn(Opcodes.NEW, Type.getInternalName(ScottReportingRule.class));
		super.visitInsn(Opcodes.DUP);
		super.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(ScottReportingRule.class), "<init>", "()V", false);

		super.visitFieldInsn(Opcodes.PUTFIELD,
				className, "scottReportingRule",
				Type.getDescriptor(ScottReportingRule.class));
	}
	
	super.visitInsn(opcode);
}
 
Example 4
Source File: Instrumentator.java    From instrumentation with Apache License 2.0 6 votes vote down vote up
private void addTraceReturn() {

        InsnList il = this.mn.instructions;

        Iterator<AbstractInsnNode> it = il.iterator();
        while (it.hasNext()) {
            AbstractInsnNode abstractInsnNode = it.next();

            switch (abstractInsnNode.getOpcode()) {
                case Opcodes.RETURN:
                    il.insertBefore(abstractInsnNode, getVoidReturnTraceInstructions());
                    break;
                case Opcodes.IRETURN:
                case Opcodes.LRETURN:
                case Opcodes.FRETURN:
                case Opcodes.ARETURN:
                case Opcodes.DRETURN:
                    il.insertBefore(abstractInsnNode, getReturnTraceInstructions());
            }
        }
    }
 
Example 5
Source File: ConstructorInstrumenter.java    From allocation-instrumenter with Apache License 2.0 6 votes vote down vote up
/** Inserts the appropriate INVOKESTATIC call */
@Override
public void visitInsn(int opcode) {
  if ((opcode == Opcodes.ARETURN)
      || (opcode == Opcodes.IRETURN)
      || (opcode == Opcodes.LRETURN)
      || (opcode == Opcodes.FRETURN)
      || (opcode == Opcodes.DRETURN)) {
    throw new RuntimeException(
        new UnmodifiableClassException("Constructors are supposed to return void"));
  }
  if (opcode == Opcodes.RETURN) {
    super.visitVarInsn(Opcodes.ALOAD, 0);
    super.visitMethodInsn(
        Opcodes.INVOKESTATIC,
        "com/google/monitoring/runtime/instrumentation/ConstructorInstrumenter",
        "invokeSamplers",
        "(Ljava/lang/Object;)V",
        false);
  }
  super.visitInsn(opcode);
}
 
Example 6
Source File: Java7Compatibility.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Override
public void visitInsn(int opcode) {
  switch (opcode) {
    case Opcodes.IRETURN:
    case Opcodes.LRETURN:
    case Opcodes.FRETURN:
    case Opcodes.DRETURN:
    case Opcodes.ARETURN:
    case Opcodes.RETURN:
      checkState(mv != null, "Encountered a second return it would seem: %s", opcode);
      mv = null; // Done: we don't expect anything to follow
      return;
    default:
      super.visitInsn(opcode);
  }
}
 
Example 7
Source File: AsmUtil.java    From quarkus with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a return bytecode instruction suitable for the given return Jandex Type. This will return
 * specialised return instructions <tt>IRETURN, LRETURN, FRETURN, DRETURN, RETURN</tt> for primitives/void,
 * and <tt>ARETURN</tt> otherwise;
 * 
 * @param typeDescriptor the return Jandex Type.
 * @return the correct bytecode return instruction for that return type descriptor.
 */
public static int getReturnInstruction(Type jandexType) {
    if (jandexType.kind() == Kind.PRIMITIVE) {
        switch (jandexType.asPrimitiveType().primitive()) {
            case BOOLEAN:
            case BYTE:
            case SHORT:
            case INT:
            case CHAR:
                return Opcodes.IRETURN;
            case DOUBLE:
                return Opcodes.DRETURN;
            case FLOAT:
                return Opcodes.FRETURN;
            case LONG:
                return Opcodes.LRETURN;
            default:
                throw new IllegalArgumentException("Unknown primitive type: " + jandexType);
        }
    } else if (jandexType.kind() == Kind.VOID) {
        return Opcodes.RETURN;
    }
    return Opcodes.ARETURN;
}
 
Example 8
Source File: AsmUtil.java    From quarkus with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a return bytecode instruction suitable for the given return type descriptor. This will return
 * specialised return instructions <tt>IRETURN, LRETURN, FRETURN, DRETURN, RETURN</tt> for primitives/void,
 * and <tt>ARETURN</tt> otherwise;
 * 
 * @param typeDescriptor the return type descriptor.
 * @return the correct bytecode return instruction for that return type descriptor.
 */
public static int getReturnInstruction(String typeDescriptor) {
    switch (typeDescriptor) {
        case "Z":
        case "B":
        case "C":
        case "S":
        case "I":
            return Opcodes.IRETURN;
        case "J":
            return Opcodes.LRETURN;
        case "F":
            return Opcodes.FRETURN;
        case "D":
            return Opcodes.DRETURN;
        case "V":
            return Opcodes.RETURN;
        default:
            return Opcodes.ARETURN;
    }
}
 
Example 9
Source File: ASMUtils.java    From radon with GNU General Public License v3.0 6 votes vote down vote up
public static int getReturnOpcode(Type type) {
    switch (type.getSort()) {
        case Type.BOOLEAN:
        case Type.CHAR:
        case Type.BYTE:
        case Type.SHORT:
        case Type.INT:
            return Opcodes.IRETURN;
        case Type.FLOAT:
            return Opcodes.FRETURN;
        case Type.LONG:
            return Opcodes.LRETURN;
        case Type.DOUBLE:
            return Opcodes.DRETURN;
        case Type.ARRAY:
        case Type.OBJECT:
            return Opcodes.ARETURN;
        case Type.VOID:
            return Opcodes.RETURN;
        default:
            throw new AssertionError("Unknown type sort: " + type.getClassName());
    }
}
 
Example 10
Source File: GenerationPass.java    From maple-ir with GNU General Public License v3.0 6 votes vote down vote up
static boolean isExitOpcode(int opcode) {
	switch(opcode) {
		case Opcodes.RET:
		case Opcodes.ATHROW:
		case Opcodes.RETURN:
		case Opcodes.IRETURN:
		case Opcodes.LRETURN:
		case Opcodes.FRETURN:
		case Opcodes.DRETURN:
		case Opcodes.ARETURN: {
			return true;
		}
		default: {
			return false;
		}
	}
}
 
Example 11
Source File: ClassParserUsingASM.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void visitInsn(int opcode) {
    switch (opcode) {
    case Opcodes.MONITORENTER:
        mBuilder.setUsesConcurrency();
        break;
    case Opcodes.ARETURN:
    case Opcodes.IRETURN:
    case Opcodes.LRETURN:
    case Opcodes.DRETURN:
    case Opcodes.FRETURN:
        if (identityState == IdentityMethodState.LOADED_PARAMETER) {
            mBuilder.setIsIdentity();
        }
        sawReturn = true;
        break;
    case Opcodes.RETURN:
        sawReturn = true;
        break;
    case Opcodes.ATHROW:
        if (stubState == StubState.INITIALIZE_RUNTIME) {
            sawStubThrow = true;
        } else if (justSawInitializationOfUnsupportedOperationException) {
            sawUnsupportedThrow = true;
        } else {
            sawNormalThrow = true;
        }
        break;
    default:
        break;
    }

    resetState();
}
 
Example 12
Source File: TypeUtils.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
public static int getReturnOpcode(Type type) {
	if (type.getSort() >= Type.BOOLEAN && type.getSort() <= Type.INT) {
		return Opcodes.IRETURN;
	} else if (type == Type.LONG_TYPE) {
		return Opcodes.LRETURN;
	} else if (type == Type.FLOAT_TYPE) {
		return Opcodes.FRETURN;
	} else if (type == Type.DOUBLE_TYPE) {
		return Opcodes.DRETURN;
	} else if (type.getSort() >= Type.ARRAY && type.getSort() <= Type.OBJECT) {
		return Opcodes.ARETURN;
	} else {
		throw new IllegalArgumentException(type.toString());
	}
}
 
Example 13
Source File: JvmType.java    From turin-programming-language with Apache License 2.0 5 votes vote down vote up
public int returnOpcode() {
    if (signature.equals("J")){
        return Opcodes.LRETURN;
    } else if (signature.equals("V")) {
        return Opcodes.RETURN;
    } else if (signature.equals("F")) {
        return Opcodes.FRETURN;
    } else if (signature.equals("D")) {
        return Opcodes.DRETURN;
    } else if (signature.equals("B")||signature.equals("S")||signature.equals("C")||signature.equals("I")||signature.equals("Z")) {
        return Opcodes.IRETURN;
    } else {
        return Opcodes.ARETURN;
    }
}
 
Example 14
Source File: ReturnValuesMutator.java    From pitest with Apache License 2.0 5 votes vote down vote up
private void mutateObjectReferenceReturn() {
  if (shouldMutate("object reference", "[see docs for details]")) {
    final Type returnType = this.methodInfo.getReturnType();

    super.visitLdcInsn(returnType);
    super.visitMethodInsn(Opcodes.INVOKESTATIC,
        OBJECT_MUTATION_METHOD.getClassName(),
        OBJECT_MUTATION_METHOD.getMethodName(),
        OBJECT_MUTATION_METHOD.getMethodDescriptor(), false);
    super.visitTypeInsn(Opcodes.CHECKCAST, returnType.getInternalName());
  }
  super.visitInsn(Opcodes.ARETURN);
}
 
Example 15
Source File: Utils.java    From Concurnas with MIT License 5 votes vote down vote up
public static int returnTypeToOpcode(Type ret)
{
	if(ret == null)
	{
		return Opcodes.RETURN;//void
	}
	else if(ret instanceof PrimativeType && !ret.hasArrayLevels())
	{
		PrimativeTypeEnum pte = ((PrimativeType)ret).type;
		switch(pte)
		{
			case VOID: return Opcodes.RETURN;
			case BOOLEAN:
			case BYTE:
			case SHORT:
			case CHAR:
			case INT: return Opcodes.IRETURN;
			case LONG: return Opcodes.LRETURN;
			case FLOAT: return Opcodes.FRETURN;
			case DOUBLE: return Opcodes.DRETURN;
			
			default: return Opcodes.ARETURN;//PrimativeTypeEnum.LAMBDA
		}
	}
	return Opcodes.ARETURN; //object
	
}
 
Example 16
Source File: ASMMethodVariables.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
boolean isReturnCode(final int opcode) {
    return opcode == Opcodes.IRETURN || opcode == Opcodes.LRETURN || opcode == Opcodes.FRETURN || opcode == Opcodes.DRETURN || opcode == Opcodes.ARETURN || opcode == Opcodes.RETURN;
}
 
Example 17
Source File: FieldGetterDetector.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
private static Map<String, String> checkMethods(ClassNode classNode, Set<String> names) {
    Map<String, String> validGetters = Maps.newHashMap();
    @SuppressWarnings("rawtypes")
    List methods = classNode.methods;
    String fieldName = null;
    checkMethod:
    for (Object methodObject : methods) {
        MethodNode method = (MethodNode) methodObject;
        if (names.contains(method.name)
                && method.desc.startsWith("()")) { //$NON-NLS-1$ // (): No arguments
            InsnList instructions = method.instructions;
            int mState = 1;
            for (AbstractInsnNode curr = instructions.getFirst();
                    curr != null;
                    curr = curr.getNext()) {
                switch (curr.getOpcode()) {
                    case -1:
                        // Skip label and line number nodes
                        continue;
                    case Opcodes.ALOAD:
                        if (mState == 1) {
                            fieldName = null;
                            mState = 2;
                        } else {
                            continue checkMethod;
                        }
                        break;
                    case Opcodes.GETFIELD:
                        if (mState == 2) {
                            FieldInsnNode field = (FieldInsnNode) curr;
                            fieldName = field.name;
                            mState = 3;
                        } else {
                            continue checkMethod;
                        }
                        break;
                    case Opcodes.ARETURN:
                    case Opcodes.FRETURN:
                    case Opcodes.IRETURN:
                    case Opcodes.DRETURN:
                    case Opcodes.LRETURN:
                    case Opcodes.RETURN:
                        if (mState == 3) {
                            validGetters.put(method.name, fieldName);
                        }
                        continue checkMethod;
                    default:
                        continue checkMethod;
                }
            }
        }
    }

    return validGetters;
}
 
Example 18
Source File: SerianalyzerMethodVisitor.java    From serianalyzer with GNU General Public License v3.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @see org.objectweb.asm.MethodVisitor#visitInsn(int)
 */
@Override
public void visitInsn ( int opcode ) {

    switch ( opcode ) {
    case Opcodes.ARETURN:
        Object ret = this.stack.pop();
        Type sigType = Type.getReturnType(this.ref.getSignature());
        Type retType = null;
        Set<Type> altTypes = null;
        if ( ret != null ) {
            if ( ret instanceof SimpleType ) {
                retType = ( (SimpleType) ret ).getType();
                altTypes = ( (SimpleType) ret ).getAlternativeTypes();
            }
            else if ( ret instanceof MultiAlternatives ) {
                retType = ( (MultiAlternatives) ret ).getCommonType();
            }
        }

        if ( retType != null ) {
            this.returnTypes.add(retType);
            if ( altTypes != null ) {
                this.returnTypes.addAll(altTypes);
            }
        }
        else {
            this.returnTypes.add(sigType);
        }
        this.stack.clear();
        break;

    case Opcodes.IRETURN:
    case Opcodes.LRETURN:
    case Opcodes.FRETURN:
    case Opcodes.DRETURN:
    case Opcodes.RETURN:
        if ( this.log.isTraceEnabled() ) {
            this.log.trace("Found return " + this.stack.pop()); //$NON-NLS-1$
        }
        this.stack.clear();
        break;

    case Opcodes.ATHROW:
        Object thrw = this.stack.pop();
        this.log.trace("Found throw " + thrw); //$NON-NLS-1$
        this.stack.clear();
        break;

    default:
        JVMImpl.handleJVMInsn(opcode, this.stack);
    }

    super.visitInsn(opcode);
}
 
Example 19
Source File: McVersionLookup.java    From fabric-loader with Apache License 2.0 4 votes vote down vote up
@Override
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
	if (result != null
			|| methodName != null && !name.equals(methodName)
			|| !descriptor.endsWith(STRING_DESC)
			|| descriptor.charAt(descriptor.length() - STRING_DESC.length() - 1) != ')') {
		return null;
	}

	// capture LDC ".." followed by ARETURN
	return new InsnFwdMethodVisitor() {
		@Override
		public void visitLdcInsn(Object value) {
			String str;

			if (value instanceof String && isProbableVersion(str = (String) value)) {
				lastLdc = str;
			} else {
				lastLdc = null;
			}
		}

		@Override
		public void visitInsn(int opcode) {
			if (result == null
					&& lastLdc != null
					&& opcode == Opcodes.ARETURN) {
				result = lastLdc;
			}

			lastLdc = null;
		}

		@Override
		protected void visitAnyInsn() {
			lastLdc = null;
		}

		String lastLdc;
	};
}
 
Example 20
Source File: ClassVisitorExample.java    From grappa with Apache License 2.0 4 votes vote down vote up
@Override
public MethodVisitor visitMethod(final int access, final String name,
    final String desc, final String signature, final String[] exceptions)
{
    // Unused?
    /*
    final MethodVisitor mv = super.visitMethod(access, name, desc,
        signature, exceptions);
    */

    return new MethodNode(Opcodes.ASM5, access, name, desc, signature,
        exceptions)
    {
        @Override
        public void visitEnd()
        {
            super.visitEnd();

            try {
                final BasicInterpreter basicInterpreter
                    = new BasicInterpreter();
                final Analyzer<BasicValue> analyzer
                    = new Analyzer<>(basicInterpreter);
                final AbstractInsnNode[] nodes = instructions.toArray();
                final Frame<BasicValue>[] frames
                    = analyzer.analyze(className, this);
                int areturn = -1;
                for (int i = nodes.length -1; i >= 0; i--)
                {
                    if (nodes[i].getOpcode() == Opcodes.ARETURN) {
                        areturn = i;
                        System.out.println(className + "." + name + desc);
                        System.out.println("Found areturn at: " + i);
                    } else if (areturn != -1
                        && nodes[i].getOpcode() != -1
                        && frames[i].getStackSize() == 0) {
                        System.out.println("Found start of block at: " + i);

                        final InsnList list = new InsnList();
                        for (int j = i; j <= areturn; j++)
                            list.add(nodes[j]);
                        final Textifier textifier = new Textifier();
                        final PrintWriter pw = new PrintWriter(System.out);
                        list.accept(new TraceMethodVisitor(textifier));
                        textifier.print(pw);
                        pw.flush();
                        System.out.println("\n\n");
                        areturn = -1;
                    }
                }
            }
            catch (AnalyzerException e) {
                e.printStackTrace();
            }

            if (mv != null)
                accept(mv);
        }
    };
}