Package org.apache.bcel.generic

Examples of org.apache.bcel.generic.InstructionHandle


    InstructionList il,
    InstructionHandle getStaticHandle,
    InstructionHandle invokeInterfaceHandle,
    ConstantPoolGen cp) {
    logger.info("Inserting GETSTATIC");
    InstructionHandle insertHandle =
      il.insert(getStaticHandle, getStaticHandle.getInstruction().copy());
    String isEnabled =
      getIsEnabled(
        (
          (INVOKEINTERFACE) invokeInterfaceHandle
View Full Code Here


    MethodGen orig,
    InstructionList il,
    InstructionHandle firstInstructionHandle,
    ConstantPoolGen cp) {
    logger.info("Inserting Enter code.");
    InstructionHandle backup = il.insert(
      firstInstructionHandle,
      instFact.createGetStatic(
        clazz.getClassName(),
        loggerAttribute.getName(),
        loggerAttribute.getType()));
View Full Code Here

    MethodGen orig,
    InstructionList il,
    InstructionHandle returnInstructionHandle,
    ConstantPoolGen cp) {
      logger.info("Inserting Exit code.");
  InstructionHandle backup = il.insert(
  returnInstructionHandle,
    instFact.createGetStatic(
      clazz.getClassName(),
      loggerAttribute.getName(),
      loggerAttribute.getType()));
View Full Code Here

        InstructionHandle handle,
        ConstantPoolGen cp)
        throws NoMatchingInvokeInterfaceInstruction {

        logger.info("Found a logger instruction.");
        InstructionHandle lastLogHandle = handle;

        InvokeInstruction invokeInterface = null;
        Instruction inst = null;
        while (true) {
            handle = handle.getNext();
            if (handle == null) {
                logger.warn("No matching invokeInterface found.");
                throw new NoMatchingInvokeInterfaceInstruction("No matching invokeInterface found.");
            }
            inst = handle.getInstruction();
            if (inst instanceof InvokeInstruction) {
                invokeInterface = (InvokeInstruction) inst;
                if (invokeInterface.getClassType(cp).equals(getLogType())) {
                    logger.info("Found matching invokeInstruction.");
                    if (level_logs == FORKLOGS) {
                        InstructionHandle insertHandle =
                            insertFork(il, lastLogHandle, handle, cp);
                        if (insertHandle != null) {
                            il.redirectBranches(lastLogHandle, insertHandle);
                            il.redirectExceptionHandlers(
                                mg.getExceptionHandlers(),
View Full Code Here

                    + mg.getName()
                    + " is a special method and won't be modified.");
            return orig;
        }
        InstructionList il = null;
        InstructionHandle handle = null;
        Instruction inst = null;

        GETSTATIC getStatic = null;

        Method m = null;

        try {
            il = mg.getInstructionList();
            handle = il.getStart();
            if (level_enters == SIMPLEENTER) {

                insertEnter(mg, il, handle, cp);
                insertFork(il, il.getStart(), handle.getPrev(), cp);
            }

            for (; handle != null; handle = handle.getNext()) {
                inst = handle.getInstruction();
                logger.info("next instruction: " + inst);
                if (level_exits == SIMPLEEXIT
                    && inst instanceof ReturnInstruction) {
                    InstructionHandle lastLogHandle = handle;
                    logger.info(
                        "Found a ReturnInstruction of type: "
                            + inst.toString());
                    int stackSize =
                        inst.consumeStack(cp) - inst.produceStack(cp);
                    while (stackSize != 0) {
                        handle = handle.getPrev();
                        inst = handle.getInstruction();
                        logger.info("prev instruction: " + inst);
                        stackSize += inst.consumeStack(cp)
                            - inst.produceStack(cp);
                    }

                    InstructionHandle insertHandle =
                        insertExit(mg, il, handle, cp);
                    if (insertHandle != null) {
                      // We need to redirect branches etc.... twice
                      // so that the if fork doesn't get erroneous modified.
                        il.redirectBranches(handle, insertHandle);
View Full Code Here

      // this is not a correct methodname.
      return null;
    }
    logger.info("the level of enabling is: " + level);
    logger.info("Inserting GETSTATIC");
    InstructionHandle insertHandle =
      il.insert(getStaticHandle, getStaticHandle.getInstruction().copy());
    il.insert(
      getStaticHandle,
      instFact.createGetStatic(LEVEL, level, LevelType));
View Full Code Here

    MethodGen orig,
    InstructionList il,
    InstructionHandle firstInstructionHandle,
    ConstantPoolGen cp) {
      logger.info("Inserting Enter code.");
      InstructionHandle backup = il.insert(
        firstInstructionHandle,
        instFact.createGetStatic(
          clazz.getClassName(),
          loggerAttribute.getName(),
          loggerAttribute.getType()));
View Full Code Here

    MethodGen orig,
    InstructionList il,
    InstructionHandle returnInstructionHandle,
    ConstantPoolGen cp) {
      logger.info("Inserting Exit code.");
      InstructionHandle backup = il.insert(
      returnInstructionHandle,
        instFact.createGetStatic(
          clazz.getClassName(),
          loggerAttribute.getName(),
          loggerAttribute.getType()));
View Full Code Here

                }
            }

        }// while (!icq.isEmpty()) END
       
        InstructionHandle ih = start.getInstruction();
        do{
            if ((ih.getInstruction() instanceof ReturnInstruction) && (!(cfg.isDead(ih)))) {
                InstructionContext ic = cfg.contextOf(ih);
                Frame f = ic.getOutFrame(new ArrayList<InstructionContext>()); // TODO: This is buggy, we check only the top-level return instructions this way. Maybe some maniac returns from a method when in a subroutine?
                LocalVariables lvs = f.getLocals();
                for (int i=0; i<lvs.maxLocals(); i++){
                    if (lvs.get(i) instanceof UninitializedObjectType){
                        this.addMessage("Warning: ReturnInstruction '"+ic+"' may leave method with an uninitialized object in the local variables array '"+lvs+"'.");
                    }
                }
                OperandStack os = f.getStack();
                for (int i=0; i<os.size(); i++){
                    if (os.peek(i) instanceof UninitializedObjectType){
                        this.addMessage("Warning: ReturnInstruction '"+ic+"' may leave method with an uninitialized object on the operand stack '"+os+"'.");
                    }
                }
                //see JVM $4.8.2
                //TODO implement all based on stack
                Type returnedType = null;
                if( ih.getPrev().getInstruction() instanceof InvokeInstruction )
                {
                    returnedType = ((InvokeInstruction)ih.getPrev().getInstruction()).getType(m.getConstantPool());
                }
                if( ih.getPrev().getInstruction() instanceof LoadInstruction )
                {
                    int index = ((LoadInstruction)ih.getPrev().getInstruction()).getIndex();
                    returnedType = lvs.get(index);
                }
                if( ih.getPrev().getInstruction() instanceof GETFIELD )
                {
                    returnedType = ((GETFIELD)ih.getPrev().getInstruction()).getType(m.getConstantPool());
                }
                if( returnedType != null )
                {
                    if( returnedType instanceof ObjectType )
                    {
                        try
                        {
                            if( !((ObjectType)returnedType).isAssignmentCompatibleWith(m.getReturnType()) )
                            {
                                throw new StructuralCodeConstraintException("Returned type "+returnedType+" does not match Method's return type "+m.getReturnType());
                            }
                        }
                        catch (Exception e)
                        {
                            //dont know what do do now, so raise RuntimeException
                            throw new RuntimeException(e);
                        }
                    }
                    else if( !returnedType.equals(m.getReturnType()) )
                    {
                        throw new StructuralCodeConstraintException("Returned type "+returnedType+" does not match Method's return type "+m.getReturnType());
                    }
                }
            }
        }while ((ih = ih.getNext()) != null);
       
    }
View Full Code Here

                mg.removeLineNumbers();
            }
            mg.stripAttributes(skipDebug);
            InstructionList il = mg.getInstructionList();
            if (il != null) {
                InstructionHandle ih = il.getStart();
                while (ih != null) {
                    ih = ih.getNext();
                }
                if (compute) {
                    mg.setMaxStack();
                    mg.setMaxLocals();
                }
View Full Code Here

TOP

Related Classes of org.apache.bcel.generic.InstructionHandle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.