Package org.apache.bcel.classfile

Examples of org.apache.bcel.classfile.Code


          String lvtname = ((ConstantUtf8) cp.getConstant(lvt.getNameIndex())).getBytes();
          if (! lvtname.equals("LocalVariableTable")){
            throw new ClassConstraintException("The LocalVariableTable attribute '"+tostring(lvt)+"' is not correctly named 'LocalVariableTable' but '"+lvtname+"'.");
          }

          Code code = obj;

          //In JustIce, the check for correct offsets into the code array is delayed to Pass 3a.
          LocalVariable[] localvariables = lvt.getLocalVariableTable();

          for (int i=0; i<localvariables.length; i++){
            checkIndex(lvt, localvariables[i].getNameIndex(), CONST_Utf8);
            String localname = ((ConstantUtf8) cp.getConstant(localvariables[i].getNameIndex())).getBytes();
            if (!validJavaIdentifier(localname)){
              throw new ClassConstraintException("LocalVariableTable '"+tostring(lvt)+"' references a local variable by the name '"+localname+"' which is not a legal Java simple name.");
            }

            checkIndex(lvt, localvariables[i].getSignatureIndex(), CONST_Utf8);
            String localsig  = ((ConstantUtf8) (cp.getConstant(localvariables[i].getSignatureIndex()))).getBytes(); // Local signature(=descriptor)
            Type t;
            try{
              t = Type.getType(localsig);
            }
            catch (ClassFormatException cfe){
              throw new ClassConstraintException("Illegal descriptor (==signature) '"+localsig+"' used by LocalVariable '"+tostring(localvariables[i])+"' referenced by '"+tostring(lvt)+"'.");
            }
            int localindex = localvariables[i].getIndex();
            if ( ( (t==Type.LONG || t==Type.DOUBLE)? localindex+1:localindex) >= code.getMaxLocals()){
              throw new ClassConstraintException("LocalVariableTable attribute '"+tostring(lvt)+"' references a LocalVariable '"+tostring(localvariables[i])+"' with an index that exceeds the surrounding Code attribute's max_locals value of '"+code.getMaxLocals()+"'.");
            }

            try{
              localVariablesInfos[method_number].add(localindex, localname, localvariables[i].getStartPC(), localvariables[i].getLength(), t);
            }
View Full Code Here


                + "</A></H4>");
        /* Handle different attributes
         */
        switch (tag) {
            case ATTR_CODE:
                Code c = (Code) attribute;
                // Some directly printable values
                file.print("<UL><LI>Maximum stack size = " + c.getMaxStack()
                        + "</LI>\n<LI>Number of local variables = " + c.getMaxLocals()
                        + "</LI>\n<LI><A HREF=\"" + class_name + "_code.html#method"
                        + method_number + "\" TARGET=Code>Byte code</A></LI></UL>\n");
                // Get handled exceptions and list them
                CodeException[] ce = c.getExceptionTable();
                int len = ce.length;
                if (len > 0) {
                    file.print("<P><B>Exceptions handled</B><UL>");
                    for (int i = 0; i < len; i++) {
                        int catch_type = ce[i].getCatchType(); // Index in constant pool
View Full Code Here

        @Override
        public @CheckForNull JumpInfo analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor) throws CheckedAnalysisException {
            Method method = analysisCache.getMethodAnalysis(Method.class, descriptor);
            JavaClass jclass = getJavaClass(analysisCache, descriptor.getClassDescriptor());
            Code code = method.getCode();
            if (code == null) {
                return null;
            }

            JumpStackComputation branchAnalysis = new JumpStackComputation(descriptor);
View Full Code Here

    public int resetForMethodEntry(final DismantleBytecode visitor) {
        this.v = visitor;
        initialize();

        int result = resetForMethodEntry0(v);
        Code code = v.getMethod().getCode();
        if (code == null) {
            return result;
        }
        JumpInfo jump = null;
        if (useIterativeAnalysis) {
View Full Code Here

        clearJumpInfoChangedByBackwardsBranch();

        setReachOnlyByBranch(false);
        seenTransferOfControl = false;
        exceptionHandlers.clear();
        Code code = m.getCode();
        if (code != null) {
            CodeException[] exceptionTable = code.getExceptionTable();
            if (exceptionTable != null) {
                for (CodeException ex : exceptionTable) {
                    exceptionHandlers.set(ex.getHandlerPC());
                }
            }
View Full Code Here

        } catch (CheckedAnalysisException e1) {
            analysisCache.getErrorLogger().logError("Unable to get method for " + descriptor, e1);
            return null;
        }

        Code code = method.getCode();
        if (code == null) {
            return null;
        }
        StackMapTable stackMapTable = getStackMapTable(code);
        if (stackMapTable == null) {
View Full Code Here

        XMethod xmethod = XFactory.createXMethod(clazz, method);
        if (cachedBitsets().containsKey(xmethod)) {
            return cachedBitsets().get(xmethod);
        }
        Code code = method.getCode();
        if (code == null) {
            return null;
        }

        byte[] instructionList = code.getCode();

        // Create callback
        UnpackedBytecodeCallback callback = new UnpackedBytecodeCallback(instructionList.length);

        // Scan the method.
View Full Code Here

                assert false;
                return Collections.<Integer> emptySet();
            }
            return result;
        }
        Code code = method.getCode();
        if (code == null) {
            assert false;
            return Collections.<Integer> emptySet();
        }

        byte[] instructionList = code.getCode();

        Set<Integer> result = new HashSet<Integer>();
        for (int i = 0; i < instructionList.length; i++) {
            if (checkForBranchExit(instructionList, i)) {
                result.add(i);
View Full Code Here

            AnalysisContext.logError("Error getting jump information", e);
        }
        BitSet lineMentionedMultipleTimes = new BitSet();
        BitSet pcInFinallyBlock = new BitSet();

        Code code = method.getCode();
        if (code == null) {
            return lineMentionedMultipleTimes;
        }
        CodeException[] exceptionTable = code.getExceptionTable();
        if (exceptionTable == null || exceptionTable.length == 0) {
            return lineMentionedMultipleTimes;
        }
        int firstHandler = Integer.MAX_VALUE;
        for (CodeException e : exceptionTable) {
View Full Code Here

     * Dump the disassembled code of all methods in the class.
     */
    public static void printCode(Method[] methods) {
        for (Method m : methods) {
            System.out.println(m);
            Code code = m.getCode();
            if (code != null) {
                System.out.println(code);
            }

        }
View Full Code Here

TOP

Related Classes of org.apache.bcel.classfile.Code

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.