Package org.apache.bcel.generic

Examples of org.apache.bcel.generic.InstructionHandle


        if (!(next instanceof IFNULL)) {
            return false;
        }

        IFNULL ifNull = (IFNULL) next;
        InstructionHandle nextNextHandle = nextHandle.getNext(); // aload
        if (nextNextHandle == null) {
            return false;
        }
        Instruction nextInstruction = nextNextHandle.getInstruction();

        if (!(nextInstruction instanceof ALOAD)) {
            return false;
        }
        ALOAD nextLoad = (ALOAD) nextInstruction;
        if (load.getIndex() != nextLoad.getIndex()) {
            return false;
        }
        InstructionHandle nextNextNextHandle = nextNextHandle.getNext(); // invoke
        if (nextNextNextHandle == null) {
            return false;
        }
        Instruction nextNextNextInstruction = nextNextNextHandle.getInstruction();
        if (!(nextNextNextInstruction instanceof INVOKEVIRTUAL)) {
            return false;
        }
        INVOKEVIRTUAL invokeVirtual = (INVOKEVIRTUAL) nextNextNextInstruction;
        String methodName = invokeVirtual.getMethodName(classContext.getConstantPoolGen());
        String methodSig = invokeVirtual.getSignature(classContext.getConstantPoolGen());
        if (!methodName.equals("close")) {
            return false;
        }
        if (!methodSig.equals("()V")) {
            return false;
        }
        InstructionHandle nextNextNextNextHandle = nextNextNextHandle.getNext(); // after
        if (ifNull.getTarget() != nextNextNextNextHandle) {
            return false;
        }

        return true;
View Full Code Here


        }
        System.out.println(msg + " " + shortAnalysisName + " on " + getFullyQualifiedMethodName());
    }

    private static String blockId(BasicBlock bb) {
        InstructionHandle handle = bb.getFirstInstruction();
        if (handle == null) {
            return "" + bb.getLabel();
        }
        return bb.getLabel() + ":" + handle.getPosition() + " " + handle.getInstruction();
    }
View Full Code Here

        bugReporter.reportBug(bugInstance);
    }

    public static boolean isThrower(BasicBlock target) {
        InstructionHandle ins = target.getFirstInstruction();
        int maxCount = 7;
        while (ins != null) {
            if (maxCount-- <= 0) {
                break;
            }
            Instruction i = ins.getInstruction();
            if (i instanceof ATHROW) {
                return true;
            }
            if (i instanceof InstructionTargeter || i instanceof ReturnInstruction) {
                return false;
            }
            ins = ins.getNext();
        }
        return false;
    }
View Full Code Here

        return result;
    }

    boolean callToAssertionMethod(Location loc) {

        InstructionHandle h = loc.getHandle();
        int firstPos = h.getPosition();

        LineNumberTable ln = method.getLineNumberTable();
        int firstLine = ln == null ? -1 : ln.getSourceLine(firstPos);

        while (h != null) {
            int pos = h.getPosition();

            if (ln == null) {
                if (pos > firstPos + 15) {
                    break;
                }
            } else {
                int line = ln.getSourceLine(pos);
                if (line != firstLine) {
                    break;
                }
            }
            Instruction i = h.getInstruction();
            if (i instanceof InvokeInstruction) {
                InvokeInstruction ii = (InvokeInstruction) i;
                String name = ii.getMethodName(classContext.getConstantPoolGen());
                if (name.startsWith("check") || name.startsWith("assert")) {
                    return true;
                }
            }
            h = h.getNext();
        }

        return false;
    }
View Full Code Here

            while (bbIter.hasNext()) {
                BasicBlock basicBlock = bbIter.next();

                if (basicBlock.isNullCheck()) {
                    InstructionHandle exceptionThrowerHandle = basicBlock.getExceptionThrower();
                    Instruction exceptionThrower = exceptionThrowerHandle.getInstruction();
                    ValueNumberFrame vnaFrame = vna.getStartFact(basicBlock);
                    if (!vnaFrame.isValid()) {
                        continue;
                    }
                    ValueNumber valueNumber = vnaFrame.getInstance(exceptionThrower, cpg);

                    Location location = new Location(exceptionThrowerHandle, basicBlock);
                    if (valueNumberForThis != valueNumber) {
                        derefs.add(location, valueNumber, PointerUsageRequiringNonNullValue.getPointerDereference());
                    }

                }
            }

            for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
                Location location = i.next();
                InstructionHandle handle = location.getHandle();
                Instruction ins = handle.getInstruction();
                ValueNumberFrame valueNumberFrame = vna.getFactAtLocation(location);
                TypeFrame typeFrame = typeDataflow.getFactAtLocation(location);
                if (ins instanceof InvokeInstruction) {
                    InvokeInstruction inv = (InvokeInstruction) ins;
                    XMethod m = XFactory.createXMethod(inv, cpg);
View Full Code Here

    }

    public static void compileStripSpace(BranchHandle strip[],
           int sCount,
           InstructionList il) {
  final InstructionHandle target = il.append(ICONST_1);
  il.append(IRETURN);
  for (int i = 0; i < sCount; i++) {
      strip[i].setTarget(target);
  }
    }
View Full Code Here

    }

    public static void compilePreserveSpace(BranchHandle preserve[],
              int pCount,
              InstructionList il) {
  final InstructionHandle target = il.append(ICONST_0);
  il.append(IRETURN);
  for (int i = 0; i < pCount; i++) {
      preserve[i].setTarget(target);
  }
    }
View Full Code Here

         "extractValueFromDOM", className, il, cpg);

  // Values needed for the switch statement
  final int levels = sortObjects.size();
  final int match[] = new int[levels];
  final InstructionHandle target[] = new InstructionHandle[levels];
  InstructionHandle tblswitch = null;

  // Compile switch statement only if the key has multiple levels
  if (levels > 1) {
      // Put the parameter to the swtich statement on the stack
      il.append(new ILOAD(extractMethod.getLocalIndex("level")));
      // Append the switch statement here later on
      tblswitch = il.append(new NOP());
  }

  // Append all the cases for the switch statment
  for (int level = 0; level < levels; level++) {
      match[level] = level;
      final Sort sort = (Sort)sortObjects.elementAt(level);
      target[level] = il.append(NOP);
      sort.translateSelect(sortRecord, extractMethod);
      il.append(ARETURN);
  }
 
  // Compile def. target for switch statement if key has multiple levels
  if (levels > 1) {
      // Append the default target - it will _NEVER_ be reached
      InstructionHandle defaultTarget =
    il.append(new PUSH(cpg, EMPTYSTRING));
      il.insert(tblswitch,new TABLESWITCH(match, target, defaultTarget));
      il.append(ARETURN);
  }
View Full Code Here

    _falseList.append(exp._falseList);
      }
  }

  // Backpatch true list and restore current iterator/node
  InstructionHandle restore;
  restore = il.append(methodGen.storeCurrentNode());
  backPatchTrueList(restore);
  BranchHandle skipFalse = il.append(new GOTO(null));

  // Backpatch false list and restore current iterator/node
View Full Code Here

      // Translate left hand side - must be true
      _left.translateDesynthesized(classGen, methodGen);

      // Need this for chaining any OR-expression children
      InstructionHandle middle = il.append(NOP);

      // Translate left right side - must be true
      _right.translateDesynthesized(classGen, methodGen);

      // Need this for chaining any OR-expression children
      InstructionHandle after = il.append(NOP);

      // Append child expression false-lists to our false-list
      _falseList.append(_right._falseList.append(_left._falseList));

      // Special case for OR-expression as a left child of AND.
      // The true-list of OR must point to second clause of AND.
      if ((_left instanceof LogicalExpr) &&
    (((LogicalExpr)_left).getOp() == OR)) {
    _left.backPatchTrueList(middle);
      }
      else if (_left instanceof NotCall) {
    _left.backPatchTrueList(middle);
      }
      else {
    _trueList.append(_left._trueList);
      }

      // Special case for OR-expression as a right child of AND
      // The true-list of OR must point to true-list of AND.
      if ((_right instanceof LogicalExpr) &&
    (((LogicalExpr)_right).getOp() == OR)) {
    _right.backPatchTrueList(after);
      }
      else if (_right instanceof NotCall) {
    _right.backPatchTrueList(after);
      }
      else {
    _trueList.append(_right._trueList);
      }
  }
  // Compile OR-expression
  else {
      // Translate left-hand side expression and produce true/false list
      _left.translateDesynthesized(classGen, methodGen);

      // This GOTO is used to skip over the code for the last test
      // in the case where the the first test succeeds
      InstructionHandle ih = il.append(new GOTO(null));

      // Translate right-hand side expression and produce true/false list
      _right.translateDesynthesized(classGen, methodGen);

      _left._trueList.backPatch(ih);
      _left._falseList.backPatch(ih.getNext());
     
      _falseList.append(_right._falseList);
      _trueList.add(ih).append(_right._trueList);
  }
    }
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.