Package org.apache.bcel.generic

Examples of org.apache.bcel.generic.CodeExceptionGen


                // Special case: when merging predecessor facts for entry to
                // an exception handler, we clear the stack and push a
                // single entry for the exception object. That way, the locals
                // can still be merged.
                CodeExceptionGen exceptionGen = basicBlock.getExceptionGen();
                tmpFact.clearStack();

                // Determine the type of exception(s) caught.
                Type catchType = null;

                if (FORCE_ACCURATE_EXCEPTIONS
                        || AnalysisContext.currentAnalysisContext().getBoolProperty(AnalysisFeatures.ACCURATE_EXCEPTIONS)) {
                    try {
                        // Ideally, the exceptions that can be propagated
                        // on this edge has already been computed.
                        CachedExceptionSet cachedExceptionSet = getCachedExceptionSet(edge.getSource());
                        ExceptionSet edgeExceptionSet = cachedExceptionSet.getEdgeExceptionSet(edge);
                        if (!edgeExceptionSet.isEmpty()) {
                            // System.out.println("Using computed edge exception set!");
                            catchType = ExceptionObjectType.fromExceptionSet(edgeExceptionSet);
                        }
                    } catch (ClassNotFoundException e) {
                        lookupFailureCallback.reportMissingClass(e);
                    }
                }

                if (catchType == null) {
                    // No information about propagated exceptions, so
                    // pick a type conservatively using the handler catch type.
                    catchType = exceptionGen.getCatchType();
                    if (catchType == null)
                    {
                        catchType = Type.THROWABLE; // handle catches anything
                        // throwable
                    }
View Full Code Here


            thrownExceptionSet.clear();
            return result;
        }

        BasicBlock handlerBlock = edge.getTarget();
        CodeExceptionGen handler = handlerBlock.getExceptionGen();
        ObjectType catchType = handler.getCatchType();

        if (Hierarchy.isUniversalExceptionHandler(catchType)) {
            result.addAll(thrownExceptionSet);
            thrownExceptionSet.clear();
        } else {
View Full Code Here

                tmpFact.clearStack();

                // Downgrade NULL and NSP to DNR if the handler is for
                // CloneNotSupportedException or InterruptedException
                if (true) {
                    CodeExceptionGen handler = destBlock.getExceptionGen();
                    ObjectType catchType = handler.getCatchType();
                    if (catchType != null) {
                        String catchClass = catchType.getClassName();
                        if (catchClass.equals("java.lang.CloneNotSupportedException")
                                || catchClass.equals("java.lang.InterruptedException")) {
                            for (int i = 0; i < tmpFact.getNumSlots(); ++i) {
View Full Code Here

            if (block == null) {
                block = allocateBasicBlock();
                blockMap.put(start, block);

                // Block is an exception handler?
                CodeExceptionGen exceptionGen = exceptionHandlerMap.getHandlerForStartInstruction(start);
                if (exceptionGen != null) {
                    block.setExceptionGen(null, exceptionGen);
                }

                addItem(new WorkListItem(start, block));
View Full Code Here

            throws DataflowAnalysisException {
        result.copyFrom(start);

        if (start.isValid()) {
            if (basicBlock.isExceptionHandler()) {
                CodeExceptionGen exceptionGen = basicBlock.getExceptionGen();
                ObjectType catchType = exceptionGen.getCatchType();
                if (catchType == null) {
                    // Probably a finally block, or a synchronized block
                    // exception-compensation catch block.
                    result.pushFinally();
                } else {
View Full Code Here

            // log error
            return e1;
        }
        try {
            Type t = m.mergeTypes(e1.getCatchType(), e2.getCatchType());
            return new CodeExceptionGen(e1.getStartPC(), e1.getEndPC(), e1.getHandlerPC(), (ObjectType) t);
        } catch (DataflowAnalysisException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return e1;
        }
View Full Code Here

    }


    private void addExceptionHandler(CodeExceptionGen exceptionHandler) {
        InstructionHandle handlerPC = exceptionHandler.getHandlerPC();
        CodeExceptionGen existing = startInstructionToHandlerMap.get(handlerPC);
        if (existing != null) {
            exceptionHandler = merge (this.merger, existing, exceptionHandler);
        }
        startInstructionToHandlerMap.put(handlerPC, exceptionHandler);
    }
View Full Code Here

            out.println("BASIC BLOCK: " + bb.getLabel() + (bb.isExceptionThrower() ? " [EXCEPTION THROWER]" : "")
                    + blockStartAnnotate(bb));
            if (bb.isExceptionThrower()) {
                out.println("  Exception thrower: " + bb.getExceptionThrower());
            }
            CodeExceptionGen exceptionGen = bb.getExceptionGen();
            if (exceptionGen != null) {
                out.println("\tCATCHES " + exceptionGen.getCatchType());
            }
            Iterator<InstructionHandle> j = instructionIterator(bb);
            while (j.hasNext()) {
                InstructionHandle handle = j.next();
                out.println(handle + instructionAnnotate(handle, bb));
View Full Code Here


    private void updateExceptionHandlers() {
        CodeExceptionGen[] handlers = _mg.getExceptionHandlers();
        for (int i = 0; i < handlers.length; i++) {
            CodeExceptionGen h = handlers[i];
            String type = (h.getCatchType() == null) ? "null" : BCELifier.printType(h
                    .getCatchType());
            _out.println("    method.addExceptionHandler(" + "ih_" + h.getStartPC().getPosition()
                    + ", " + "ih_" + h.getEndPC().getPosition() + ", " + "ih_"
                    + h.getHandlerPC().getPosition() + ", " + type + ");");
        }
    }
View Full Code Here

      put(ih, "Label" + label_counter++ + ":")
    }
   
    CodeExceptionGen[] ehs = mg.getExceptionHandlers();
    for(int i=0; i < ehs.length; i++) {
      CodeExceptionGen  c  = ehs[i];
      InstructionHandle ih = c.getStartPC();

      put(ih, "Label" + label_counter++ + ":")
      ih = c.getEndPC();
      put(ih, "Label" + label_counter++ + ":")
      ih = c.getHandlerPC();
      put(ih, "Label" + label_counter++ + ":")
    }

    LineNumberGen[] lns = mg.getLineNumbers();
    for(int i=0; i < lns.length; i++) {
      InstructionHandle ih = lns[i].getInstruction();
      put(ih, ".line " + lns[i].getSourceLine());
    }
    /* Pass 2: Output code.
     */
    for(int i=0; i < lvs.length; i++) {
      LocalVariableGen l = lvs[i];
      out.println(".var " + l.getIndex() + " is " + l.getName() + " " +
      l.getType().getSignature() +
      " from " + get(l.getStart()) +
      " to " + get(l.getEnd()));
    }

    out.print("\n");
   
    for(int i=0; i < ihs.length; i++) {
      InstructionHandle ih   = ihs[i];
      Instruction       inst = ih.getInstruction();
      String            str  = (String)map.get(ih);
     
      if(str != null) {
        out.println(str);
    }

      if(inst instanceof BranchInstruction) {
  if(inst instanceof Select) { // Special cases LOOKUPSWITCH and TABLESWITCH
    Select              s       = (Select)inst;
    int[]               matchs  = s.getMatchs();
    InstructionHandle[] targets = s.getTargets();
   
    if(s instanceof TABLESWITCH) {
      out.println("\ttableswitch " + matchs[0] + " " +
      matchs[matchs.length - 1]);
     
      for(int j=0; j < targets.length; j++) {
            out.println("\t\t" + get(targets[j]));
        }

    } else { // LOOKUPSWITCH
      out.println("\tlookupswitch ");

      for(int j=0; j < targets.length; j++) {
            out.println("\t\t" + matchs[j] + " : " + get(targets[j]));
        }
    }

    out.println("\t\tdefault: " + get(s.getTarget())); // Applies for both
  } else {
    BranchInstruction bi  = (BranchInstruction)inst;
    ih  = bi.getTarget();
    str = get(ih);
    out.println("\t" + Constants.OPCODE_NAMES[bi.getOpcode()] + " " + str);
  }
      } else {
        out.println("\t" + inst.toString(cp.getConstantPool()));
    }
    }
   
    out.print("\n");

    for(int i=0; i < ehs.length; i++) {
      CodeExceptionGen c = ehs[i];
      ObjectType caught = c.getCatchType();
      String class_name = (caught == null)// catch any exception, used when compiling finally
  "all" : caught.getClassName().replace('.', '/');

      out.println(".catch " + class_name + " from " +
      get(c.getStartPC()) + " to " + get(c.getEndPC()) +
      " using " + get(c.getHandlerPC()));
    }

    printEndMethod(code);
  }
View Full Code Here

TOP

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

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.