org.objectweb.asm.Opcodes# ARETURN 源码实例Demo

下面列出了org.objectweb.asm.Opcodes# ARETURN 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: bazel   文件: Java7Compatibility.java

@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);
  }
}
 
源代码2 项目: maple-ir   文件: GenerationPass.java

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;
		}
	}
}
 
源代码3 项目: radon   文件: ASMUtils.java

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());
    }
}
 
源代码4 项目: quarkus   文件: AsmUtil.java

/**
 * 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;
    }
}
 
源代码5 项目: quarkus   文件: AsmUtil.java

/**
 * 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;
}
 
源代码6 项目: es6draft   文件: InstructionAssembler.java

/**
 * value → &#x2205;
 */
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();
    }
}
 

/** 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);
}
 
源代码8 项目: instrumentation   文件: Instrumentator.java

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());
            }
        }
    }
 

@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);
}
 
源代码10 项目: pitest   文件: ReturnValuesMutator.java

@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;
  }
}
 
源代码11 项目: Concurnas   文件: Utils.java

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
	
}
 
源代码12 项目: maple-ir   文件: TypeUtils.java

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());
	}
}
 
源代码13 项目: spotbugs   文件: ClassParserUsingASM.java

@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();
}
 

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;
    }
}
 
源代码15 项目: pitest   文件: ReturnValuesMutator.java

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);
}
 
源代码16 项目: pinpoint   文件: ASMMethodVariables.java

boolean isReturnCode(final int opcode) {
    return opcode == Opcodes.IRETURN || opcode == Opcodes.LRETURN || opcode == Opcodes.FRETURN || opcode == Opcodes.DRETURN || opcode == Opcodes.ARETURN || opcode == Opcodes.RETURN;
}
 
源代码17 项目: javaide   文件: FieldGetterDetector.java

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;
}
 

/**
 * {@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);
}
 
源代码19 项目: fabric-loader   文件: McVersionLookup.java

@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;
	};
}
 
源代码20 项目: grappa   文件: ClassVisitorExample.java

@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);
        }
    };
}
 
 方法所在类
 同类方法