Package soot

Examples of soot.SootMethod


            }

            // This will allow us to get a better type inference below.
            for (Iterator methods = entityClass.getMethods().iterator(); methods
                    .hasNext();) {
                SootMethod method = (SootMethod) methods.next();

                JimpleBody body = (JimpleBody) method.retrieveActiveBody();

                // First split local variables that are used in
                // multiple places.
                LocalSplitter.v().transform(body, _phaseName + ".ls");

                // We may have locals with the same name.  Rename them.
                LocalNameStandardizer.v().transform(body, _phaseName + ".lns");

                // Assign types to local variables... This types
                // everything that isn't a token type.
                TypeAssigner.v().transform(body, _phaseName + ".ta");

                // Run some cleanup...  this will speedup the rest
                // of the analysis.  And prevent typing errors.
                //     TokenInstanceofEliminator.eliminateCastsAndInstanceOf(
                //                         body, _phaseName + ".tie", unsafeLocalSet,
                //                         true);
                UnreachableCodeEliminator.v().transform(body,
                        _phaseName + ".uce");
                CopyPropagator.v().transform(body, _phaseName + ".cp");
                ConstantPropagatorAndFolder.v().transform(body,
                        _phaseName + ".cpf");
                ConditionalBranchFolder.v()
                        .transform(body, _phaseName + ".cbf");
                DeadAssignmentEliminator.v().transform(body,
                        _phaseName + ".dae");
                UnreachableCodeEliminator.v().transform(body,
                        _phaseName + ".uce");
                UnusedLocalEliminator.v().transform(body, _phaseName + ".ule");

                // Run some cleanup...  this will speedup the rest
                // of the analysis.  And prevent typing errors.
                if (debug) {
                    System.out.println("eliminating instanceof in " + method);
                }

                TokenInstanceofEliminator.eliminateCastsAndInstanceOf(body,
                        _phaseName + ".tie", unsafeLocalSet, debug);

                UnreachableCodeEliminator.v().transform(body,
                        _phaseName + ".uce");
                CopyPropagator.v().transform(body, _phaseName + ".cp");
                ConstantPropagatorAndFolder.v().transform(body,
                        _phaseName + ".cpf");
                ConditionalBranchFolder.v()
                        .transform(body, _phaseName + ".cbf");
                DeadAssignmentEliminator.v().transform(body,
                        _phaseName + ".dae");
                UnusedLocalEliminator.v().transform(body, _phaseName + ".ule");
                UnreachableCodeEliminator.v().transform(body,
                        _phaseName + ".uce");
                CopyPropagator.v().transform(body, _phaseName + ".cp");
                ConstantPropagatorAndFolder.v().transform(body,
                        _phaseName + ".cpf");
                ConditionalBranchFolder.v()
                        .transform(body, _phaseName + ".cbf");
                DeadAssignmentEliminator.v().transform(body,
                        _phaseName + ".dae");
                UnusedLocalEliminator.v().transform(body, _phaseName + ".ule");
                LocalSplitter.v().transform(body, _phaseName + ".ls");
                TypeAssigner.v().transform(body, _phaseName + ".ta");
                TokenInstanceofEliminator.eliminateCastsAndInstanceOf(body,
                        _phaseName + ".cie", Collections.EMPTY_SET, debug);
            }

            // Now run the type specialization algorithm...  This
            // allows us to resolve the methods that we are inlining
            // with better precision.
            // Map objectToTokenType = TypeSpecializer.specializeTypes(
            //   debug, entityClass, unsafeLocalSet);
            TypeSpecializerAnalysis typeAnalysis = new TypeSpecializerAnalysis(
                    entityClass, unsafeLocalSet);

            // Specialize the code, according to the analyzed types.
            //TypeSpecializer.specializeTypes(true, entityClass, unsafeLocalSet, typeAnalysis);
            for (Iterator methods = entityClass.getMethods().iterator(); methods
                    .hasNext();) {
                SootMethod method = (SootMethod) methods.next();

                // Check to see if the method is safe to modify with:
                // It has no arguments or return values which are
                // tokens.
                if (_methodWillBeInlined(method)) {
                    continue;
                }

                JimpleBody body = (JimpleBody) method.retrieveActiveBody();

                CompleteUnitGraph unitGraph = new CompleteUnitGraph(body);
                SimpleLocalDefs localDefs = new SimpleLocalDefs(unitGraph);
                SimpleLocalUses localUses = new SimpleLocalUses(unitGraph,
                        localDefs);
View Full Code Here


            // Then determine the method that was
            // actually invoked.
            List methodList;

            if (value instanceof SpecialInvokeExpr) {
                SootMethod targetMethod = hierarchy.resolveSpecialDispatch(
                        (SpecialInvokeExpr) r, method);
                methodList = new LinkedList();
                methodList.add(targetMethod);
            } else {
                methodList =
                //      invokeGraph.getTargetsOf((Stmt)unit);
                hierarchy.resolveAbstractDispatch(type.getSootClass(), r
                        .getMethod());
            }

            // If there was only one possible method...
            if (methodList.size() == 1) {
                // Then inline its code
                SootMethod inlinee = (SootMethod) methodList.get(0);

                if (inlinee.getName().equals("getClass")) {
                    SootClass typeClass = type.getSootClass();
                    int subclasses = hierarchy.getSubclassesOf(typeClass)
                            .size();

                    if (subclasses == 0) {
                        // FIXME: do something better here.
                        SootMethod newGetClassMethod = Scene.v().getMethod(
                                "<java.lang.Class: java.lang.Class "
                                        + "forName(java.lang.String)>");
                        box.setValue(Jimple.v().newStaticInvokeExpr(
                                newGetClassMethod.makeRef(),
                                StringConstant.v(typeClass.getName())));
                        doneSomething = true;
                    }
                } else if (inlinee.getName().equals("isNil")) {
                    box.setValue(IntConstant.v(0));
                    //                 } else if (inlinee.getSignature().equals(PtolemyUtilities.arrayTokenConstructor.getSignature())) {
                    //                     System.out.println("method = " + method);
                    //                     System.out.println("inlinee = " + inlinee.getSignature());
                    //                     throw new RuntimeException("Cannot inline arrayTokens that do not have a type explicitly specified.");
                } else {
                    SootClass declaringClass = inlinee.getDeclaringClass();

                    if (!declaringClass.isApplicationClass()) {
                        declaringClass.setLibraryClass();
                    }

                    if (!inlinee.isAbstract() && !inlinee.isNative()) {
                        // FIXME: only inline things where we are
                        // also inlining the constructor???
                        if (debug) {
                            System.out.println("inlining " + inlinee);
                        }

                        inlinee.retrieveActiveBody();

                        // Then we know exactly what method will
                        // be called, so inline it.
                        SiteInliner.inlineSite(inlinee, (Stmt) unit, method);
                        doneSomething = true;
                    } else {
                        throw new RuntimeException("inlinee is not concrete!: "
                                + inlinee);
                    }
                }
            } else {
                if (debug) {
                    System.out.println("uninlinable method invocation = " + r);

                    for (Iterator j = methodList.iterator(); j.hasNext();) {
                        System.out.println("method = " + j.next());
                    }
                }
            }
        } else if (value instanceof SpecialInvokeExpr) {
            SpecialInvokeExpr r = (SpecialInvokeExpr) value;

            if (debug) {
                System.out.println("special invoking = " + r.getMethod());
            }

            Type baseType = typeAnalysis.getSpecializedSootType((Local) r
                    .getBase());

            if (baseType instanceof RefType) {
                RefType type = (RefType) baseType;

                boolean isInlineableTokenMethod = SootUtilities.derivesFrom(
                        type.getSootClass(), PtolemyUtilities.tokenClass);

                // If it is a token, then check to
                // make sure that it has the
                // appropriate type
                if (isInlineableTokenMethod) {
                    type = (RefType) typeAnalysis
                            .getSpecializedSootType((Local) r.getBase());

                    if (PtolemyUtilities.getTypeDepth(typeAnalysis
                            .getSpecializedType((Local) r.getBase())) != depth) {
                        if (debug) {
                            System.out
                                    .println("skipping, type depth = "
                                            + PtolemyUtilities
                                                    .getTypeDepth(typeAnalysis
                                                            .getSpecializedType((Local) r
                                                                    .getBase()))
                                            + ", but only inlining depth "
                                            + depth);
                        }

                        return false;

                        //continue;
                    }
                }

                if (isInlineableTokenMethod) {
                    SootMethod inlinee = hierarchy.resolveSpecialDispatch(r,
                            method);
                    SootClass declaringClass = inlinee.getDeclaringClass();

                    if (!declaringClass.isApplicationClass()) {
                        declaringClass.setLibraryClass();
                    }

                    if (!inlinee.isAbstract() && !inlinee.isNative()) {
                        if (debug) {
                            System.out.println("inlining");
                        }

                        inlinee.retrieveActiveBody();

                        // Then we know exactly what method will
                        // be called, so inline it.
                        SiteInliner.inlineSite(inlinee, (Stmt) unit, method);
                        doneSomething = true;
                    } else {
                        if (debug) {
                            System.out.println("removing");
                        }

                        // If we don't have a method,
                        // then remove the invocation.
                        body.getUnits().remove(unit);
                    }
                }
            }
        } else if (value instanceof StaticInvokeExpr) {
            StaticInvokeExpr r = (StaticInvokeExpr) value;

            // Inline typelattice methods.
            if (r.getMethod().getDeclaringClass().equals(
                    PtolemyUtilities.typeLatticeClass)) {
                try {
                    if (debug) {
                        System.out.println("inlining typelattice method = "
                                + unit);
                    }

                    typeAnalysis.inlineTypeLatticeMethods(method, unit, box, r,
                            localDefs, localUses);
                } catch (Exception ex) {
                    ex.printStackTrace();
                    System.out.println("Exception occurred " + ex.getMessage());
                }
            } else {
                if (debug) {
                    System.out.println("static invoking = " + r.getMethod());
                }

                SootMethod inlinee = r.getMethod();
                SootClass declaringClass = inlinee.getDeclaringClass();
                Type returnType = inlinee.getReturnType();

                // These methods contain a large amount of
                // code, which greatly slows down further
                // inlining.  The code should also contain
                // little information, and is hard to get
                // rid of any other way.
                if (_mangleExceptionMessages
                        && (inlinee.getName().equals("notSupportedMessage")
                                || inlinee.getName().equals(
                                        "notSupportedConversionMessage")
                                || inlinee.getName().equals(
                                        "notSupportedIncomparableMessage") || inlinee
                                .getName()
                                .equals(
                                        "notSupportedIncomparableConversionMessage"))) {
                    box.setValue(StringConstant.v("Token Exception"));
                } else if (SootUtilities.derivesFrom(declaringClass,
                        PtolemyUtilities.tokenClass)
                        || ((returnType instanceof RefType) && SootUtilities
                                .derivesFrom(((RefType) returnType)
                                        .getSootClass(),
                                        PtolemyUtilities.tokenClass))) {
                    // Note that we make sure to inline method like
                    // UtilityFunctions.gaussian, which returns a
                    // DoubleMatrixToken.
                    if (!declaringClass.isApplicationClass()) {
                        declaringClass.setLibraryClass();
                    }

                    if (!inlinee.isAbstract() && !inlinee.isNative()) {
                        if (debug) {
                            System.out.println("inlining");
                        }

                        inlinee.retrieveActiveBody();

                        // Then we know exactly what method will
                        // be called, so inline it.
                        SiteInliner.inlineSite(inlinee, (Stmt) unit, method);
                        doneSomething = true;
View Full Code Here

            TypeSpecializerAnalysis typeAnalysis = new TypeSpecializerAnalysis(
                    entityClass, unsafeLocalSet);

            for (Iterator methods = entityClass.getMethods().iterator(); methods
                    .hasNext();) {
                SootMethod method = (SootMethod) methods.next();

                JimpleBody body = (JimpleBody) method.retrieveActiveBody();

                CompleteUnitGraph unitGraph = new CompleteUnitGraph(body);
                SimpleLocalDefs localDefs = new SimpleLocalDefs(unitGraph);
                SimpleLocalUses localUses = new SimpleLocalUses(unitGraph,
                        localDefs);
View Full Code Here

                            typeClass, r.getMethod());

                    // If there was only one possible method...
                    if (methodList.size() == 1) {
                        // Then inline its code
                        SootMethod inlinee = (SootMethod) methodList.get(0);

                        if (inlinee.getName().equals("getClass")) {
                            // FIXME: do something better here.
                            SootMethod newGetClassMethod = Scene.v().getMethod(
                                    "<java.lang.Class: java.lang.Class "
                                            + "forName(java.lang.String)>");
                            box.setValue(Jimple.v().newStaticInvokeExpr(
                                    newGetClassMethod.makeRef(),
                                    StringConstant.v("java.lang.Object")));
                        } else if (inlinee.getName().equals("getElementType")) {
                            if (debug) {
                                System.out.println("handling getElementType: "
                                        + unit);
View Full Code Here

        TypeSpecializerAnalysis typeAnalysis = new TypeSpecializerAnalysis(
                entityClass, unsafeLocalSet);

        for (Iterator methods = entityClass.getMethods().iterator(); methods
                .hasNext();) {
            SootMethod method = (SootMethod) methods.next();

            // Check to see if the method is safe to modify with:
            // It has no arguments or return values which are
            // tokens.
            if (_methodWillBeInlined(method)) {
                continue;
            }

            JimpleBody body = (JimpleBody) method.retrieveActiveBody();

            //  UnitGraph graph = new CompleteUnitGraph(body);
            //  MustAliasAnalysis aliasAnalysis = new MustAliasAnalysis(graph);
            if (debug) {
                System.out.println("creating replacement locals in method = "
                        + method);
            }

            // A map from a local variable that references a
            // token and a field of that token class to the
            // local variable that will replace a
            // fieldReference to that field based on the
            // local.
            for (Iterator locals = body.getLocals().snapshotIterator(); locals
                    .hasNext();) {
                Local local = (Local) locals.next();
                Type localType = typeAnalysis.getSpecializedSootType(local);

                if (debug) {
                    System.out
                            .println("Attempting to create replacement fields for local = "
                                    + local);
                }

                if (debug) {
                    System.out.println("Type = " + localType);
                }

                // If the type is not a token, then skip it.
                if (!PtolemyUtilities.isConcreteTokenType(localType)
                        || unsafeLocalSet.contains(local)) {
                    if (debug) {
                        System.out
                                .println("skipping: unsafe or not concrete token");
                    }

                    continue;
                }

                ptolemy.data.type.Type localTokenType = typeAnalysis
                        .getSpecializedType(local);

                if (debug) {
                    System.out.println("localTokenType = " + localTokenType);
                }

                // Ignore fields that aren't of the right depth.
                if (PtolemyUtilities.getTypeDepth(localTokenType) != depth) {
                    if (debug) {
                        System.out
                                .println("skipping: depth is only "
                                        + PtolemyUtilities
                                                .getTypeDepth(localTokenType));
                    }

                    continue;
                }

                // If the type is not instantiable, then skip it.
                //    if (!localTokenType.isInstantiable()) {
                //    continue;
                // }
                // If we've already created subfields for this
                // field, then don't do it again.
                if (localToFieldToLocal.get(local) != null) {
                    continue;
                }

                RefType type = PtolemyUtilities.getBaseTokenType(localType);
                SootClass localClass = type.getSootClass();

                if (!SootUtilities.derivesFrom(localClass,
                        PtolemyUtilities.tokenClass)) {
                    if (debug) {
                        System.out.println("skipping: not a token.");
                    }

                    continue;
                }

                if (debug) {
                    System.out
                            .println("Creating replacement fields for local = "
                                    + local);
                }

                if (debug) {
                    System.out.println("localClass = " + localClass);
                }

                // We are going to make a modification
                doneSomething = true;

                Type isNotNullType = SootUtilities.createIsomorphicType(
                        localType, BooleanType.v());

                // Create a boolean value that tells us whether or
                // not the token is null.  Initialize it to true.
                Local isNotNullLocal = Jimple.v().newLocal(
                        local.getName() + "_isNotNull", isNotNullType);
                body.getLocals().add(isNotNullLocal);
                localToIsNotNullLocal.put(local, isNotNullLocal);

                // Note: default initialization is to false..
                //                 body.getUnits().insertBefore(
                //                         Jimple.v().newAssignStmt(
                //                                 isNotNullLocal,
                //                                 IntConstant.v(1)),
                //                         body.getFirstNonIdentityStmt());
                Map tokenFieldToReplacementLocal = new HashMap();
                localToFieldToLocal.put(local, tokenFieldToReplacementLocal);

                for (Iterator tokenFields = _getTokenClassFields(localClass)
                        .iterator(); tokenFields.hasNext();) {
                    SootField tokenField = (SootField) tokenFields.next();

                    if (debug) {
                        System.out.println("tokenField = " + tokenField);
                    }

                    Type replacementType = SootUtilities.createIsomorphicType(
                            localType, tokenField.getType());
                    Local replacementLocal = Jimple.v().newLocal(
                            local.getName() + "_" + tokenField.getName(),
                            replacementType);
                    body.getLocals().add(replacementLocal);
                    tokenFieldToReplacementLocal.put(tokenField,
                            replacementLocal);
                }
            }

            // Go back again and replace references to fields
            // in the token with references to local
            // variables.
            for (Iterator units = body.getUnits().snapshotIterator(); units
                    .hasNext();) {
                Unit unit = (Unit) units.next();

                if (debug) {
                    System.out.println("ttn2 unit = " + unit);
                }

                if (unit instanceof InvokeStmt) {
                    // Handle java.lang.arraycopy
                    InvokeExpr r = (InvokeExpr) ((InvokeStmt) unit)
                            .getInvokeExpr();

                    if (r.getMethod().equals(PtolemyUtilities.arraycopyMethod)) {
                        if (debug) {
                            System.out.println("handling as array copy");
                        }

                        Local toLocal = (Local) r.getArg(0);
                        Local fromLocal = (Local) r.getArg(2);
                        Map toFieldToReplacementLocal = (Map) localToFieldToLocal
                                .get(toLocal);
                        Map fromFieldToReplacementLocal = (Map) localToFieldToLocal
                                .get(fromLocal);

                        if ((toFieldToReplacementLocal != null)
                                && (fromFieldToReplacementLocal != null)) {
                            if (debug) {
                                System.out
                                        .println("toFieldToReplacementLocal = "
                                                + toFieldToReplacementLocal);
                            }

                            if (debug) {
                                System.out
                                        .println("fromFieldToReplacementLocal = "
                                                + fromFieldToReplacementLocal);
                            }

                            {
                                List argumentList = new LinkedList();
                                argumentList.add((Local) localToIsNotNullLocal
                                        .get(toLocal));
                                argumentList.add(r.getArg(1));
                                argumentList.add((Local) localToIsNotNullLocal
                                        .get(fromLocal));
                                argumentList.add(r.getArg(3));
                                argumentList.add(r.getArg(4));

                                body
                                        .getUnits()
                                        .insertBefore(
                                                Jimple
                                                        .v()
                                                        .newInvokeStmt(
                                                                Jimple
                                                                        .v()
                                                                        .newStaticInvokeExpr(
                                                                                PtolemyUtilities.arraycopyMethod
                                                                                        .makeRef(),
                                                                                argumentList)),
                                                unit);
                            }

                            for (Iterator tokenFields = toFieldToReplacementLocal
                                    .keySet().iterator(); tokenFields.hasNext();) {
                                SootField tokenField = (SootField) tokenFields
                                        .next();

                                Local toReplacementLocal = (Local) toFieldToReplacementLocal
                                        .get(tokenField);
                                Local fromReplacementLocal = (Local) fromFieldToReplacementLocal
                                        .get(tokenField);
                                List argumentList = new LinkedList();
                                argumentList.add(toReplacementLocal);
                                argumentList.add(r.getArg(1));
                                argumentList.add(fromReplacementLocal);
                                argumentList.add(r.getArg(3));
                                argumentList.add(r.getArg(4));

                                body
                                        .getUnits()
                                        .insertBefore(
                                                Jimple
                                                        .v()
                                                        .newInvokeStmt(
                                                                Jimple
                                                                        .v()
                                                                        .newStaticInvokeExpr(
                                                                                PtolemyUtilities.arraycopyMethod
                                                                                        .makeRef(),
                                                                                argumentList)),
                                                unit);
                            }

                            body.getUnits().remove(unit);
                            doneSomething = true;
                        }
                    }
                } else if (unit instanceof AssignStmt) {
                    AssignStmt stmt = (AssignStmt) unit;
                    /*Type assignmentType =*/stmt.getLeftOp().getType();

                    if (stmt.getLeftOp() instanceof Local
                            && stmt.getRightOp() instanceof LengthExpr) {
                        if (debug) {
                            System.out.println("handling as length expr");
                        }

                        LengthExpr lengthExpr = (LengthExpr) stmt.getRightOp();
                        Local baseLocal = (Local) lengthExpr.getOp();

                        if (debug) {
                            System.out.println("operating on " + baseLocal);
                        }

                        Map fieldToReplacementArrayLocal = (Map) localToFieldToLocal
                                .get(baseLocal);

                        if (fieldToReplacementArrayLocal != null) {
                            doneSomething = true;

                            // Get the length of a random one of the replacement fields.
                            List replacementList = new ArrayList(
                                    fieldToReplacementArrayLocal.keySet());
                            Collections.sort(replacementList, new Comparator() {
                                public int compare(Object o1, Object o2) {
                                    SootField f1 = (SootField) o1;
                                    SootField f2 = (SootField) o2;
                                    return f1.getName().compareTo(f2.getName());
                                }
                            });

                            SootField field = (SootField) replacementList
                                    .get(replacementList.size() - 1);

                            if (debug) {
                                System.out.println("replace with  "
                                        + fieldToReplacementArrayLocal
                                                .get(field));
                            }

                            lengthExpr
                                    .setOp((Local) fieldToReplacementArrayLocal
                                            .get(field));

                            if (debug) {
                                System.out.println("unit now = " + unit);
                            }

                            //    body.getUnits().remove(unit);
                        }
                    } else if (stmt.getLeftOp() instanceof InstanceFieldRef) {
                        // Replace references to fields of tokens.
                        // FIXME: assign to all aliases as well.
                        if (debug) {
                            System.out
                                    .println("is assignment to Instance FieldRef");
                        }

                        InstanceFieldRef r = (InstanceFieldRef) stmt
                                .getLeftOp();
                        SootField field = r.getField();

                        if (r.getBase().getType() instanceof RefType) {
                            RefType type = (RefType) r.getBase().getType();

                            //System.out.println("BaseType = " + type);
                            if (SootUtilities.derivesFrom(type.getSootClass(),
                                    PtolemyUtilities.tokenClass)) {
                                if (debug) {
                                    System.out.println("handling " + unit
                                            + " token operation");
                                }

                                // We have a reference to a field of a token class.
                                Local baseLocal = (Local) r.getBase();
                                Local instanceLocal = _getInstanceLocal(body,
                                        baseLocal, field, localToFieldToLocal,
                                        debug);

                                if (debug) {
                                    System.out.println("instanceLocal = "
                                            + instanceLocal);
                                }

                                if (instanceLocal != null) {
                                    stmt.getLeftOpBox().setValue(instanceLocal);
                                    doneSomething = true;
                                }
                            }
                        }
                    } else if (stmt.getRightOp() instanceof InstanceFieldRef) {
                        // Replace references to fields of tokens.
                        if (debug) {
                            System.out
                                    .println("is assignment from Instance FieldRef");
                        }

                        InstanceFieldRef r = (InstanceFieldRef) stmt
                                .getRightOp();
                        SootField field = r.getField();

                        if (r.getBase().getType() instanceof RefType) {
                            RefType type = (RefType) r.getBase().getType();

                            //System.out.println("BaseType = " + type);
                            if (SootUtilities.derivesFrom(type.getSootClass(),
                                    PtolemyUtilities.tokenClass)) {
                                if (debug) {
                                    System.out.println("handling " + unit
                                            + " token operation");
                                }

                                // We have a reference to a field of a token class.
                                Local baseLocal = (Local) r.getBase();
                                Local instanceLocal = _getInstanceLocal(body,
                                        baseLocal, field, localToFieldToLocal,
                                        debug);

                                if (debug) {
                                    System.out.println("instanceLocal = "
                                            + instanceLocal);
                                }

                                if (instanceLocal != null) {
                                    stmt.getRightOpBox()
                                            .setValue(instanceLocal);
                                    doneSomething = true;
                                }
                            }
                        }
                    }
                }
            }
        }

        if (debug) {
            System.out.println("Specializing types for " + entityClass);
        }

        // Specialize the token types.  Any field we created above
        // should now have its correct concrete type.
        // TypeSpecializer.specializeTypes(debug, entityClass, unsafeLocalSet);
        // Now go through the methods again and handle all token assignments,
        // replacing them with assignments on the native replacements.
        for (Iterator methods = entityClass.getMethods().iterator(); methods
                .hasNext();) {
            SootMethod method = (SootMethod) methods.next();

            if (debug) {
                System.out.println("Replacing token assignments in method "
                        + method);
            }

            JimpleBody body = (JimpleBody) method.retrieveActiveBody();

            //   InstanceEqualityEliminator.removeInstanceEqualities(body, null, true);
            for (Iterator units = body.getUnits().snapshotIterator(); units
                    .hasNext();) {
                Unit unit = (Unit) units.next();
View Full Code Here

                .hasNext();) {
            SootClass entityClass = (SootClass) i.next();

            for (Iterator methods = entityClass.getMethods().iterator(); methods
                    .hasNext();) {
                SootMethod method = (SootMethod) methods.next();
                JimpleBody body = (JimpleBody) method.retrieveActiveBody();

                for (Iterator stmts = body.getUnits().iterator(); stmts
                        .hasNext();) {
                    Stmt stmt = (Stmt) stmts.next();

                    for (Iterator boxes = stmt.getUseBoxes().iterator(); boxes
                            .hasNext();) {
                        ValueBox box = (ValueBox) boxes.next();
                        Value value = box.getValue();

                        if (value instanceof FieldRef) {
                            Object field = ((FieldRef) value).getField();
                            unusedFieldSet.remove(field);
                        }
                    }
                }
            }
        }

        // Loop through the methods again, and kill the statements
        // that write to an unused field.
        for (Iterator i = Scene.v().getApplicationClasses().iterator(); i
                .hasNext();) {
            SootClass entityClass = (SootClass) i.next();

            for (Iterator methods = entityClass.getMethods().iterator(); methods
                    .hasNext();) {
                SootMethod method = (SootMethod) methods.next();
                JimpleBody body = (JimpleBody) method.retrieveActiveBody();

                for (Iterator stmts = body.getUnits().snapshotIterator(); stmts
                        .hasNext();) {
                    Stmt stmt = (Stmt) stmts.next();
View Full Code Here

                .hasNext();) {
            SootClass entityClass = (SootClass) i.next();

            for (Iterator methods = entityClass.getMethods().iterator(); methods
                    .hasNext();) {
                SootMethod method = (SootMethod) methods.next();

                if (method.isConcrete()) {
                    method.setActiveBody(Grimp.v().newBody(
                            method.retrieveActiveBody(), "gb"));
                }
            }
        }
    }
View Full Code Here

        // Generate function prototypes for all private methods.
        int count = 0;
        Iterator methods = source.getMethods().iterator();

        while (methods.hasNext()) {
            SootMethod method = (SootMethod) (methods.next());

            if (method.isPrivate() && RequiredFileGenerator.isRequired(method)) {
                if (count++ == 0) {
                    bodyCode.append(_comment("Prototypes for functions that "
                            + "implement private methods"));
                }

                bodyCode.append(_generateMethodHeader(method) + ";\n");
            }
        }

        bodyCode.append("\n");

        // Generate the code for all of the methods.
        MethodCodeGenerator methodCodeGenerator = new MethodCodeGenerator(
                _context, _requiredTypeMap);

        methods = source.getMethods().iterator();

        while (methods.hasNext()) {
            SootMethod thisMethod = (SootMethod) methods.next();
            String methodCode = null;

            if (RequiredFileGenerator.isRequired(thisMethod)) {
                methodCode = methodCodeGenerator.generate(thisMethod);
                bodyCode.append(methodCode);
View Full Code Here

            String argumentReference) {
        StringBuffer code = new StringBuffer();
        Iterator methods = methodList.iterator();

        while (methods.hasNext()) {
            SootMethod method = (SootMethod) (methods.next());

            // Method Pointer Initialization is not done for methods that
            // are not required, static methods, and abstract methods.
            if ((!method.isStatic())
                    && RequiredFileGenerator.isRequired(method)
                    && (!method.isAbstract())) {
                code.append(_indent(1) + argumentReference + "methods."
                        + CNames.methodNameOf(method) + " = "
                        + CNames.functionNameOf(method) + ";\n");
                _updateRequiredTypes(method.getDeclaringClass().getType());
            }
        }

        return code.toString();
    }
View Full Code Here

        code.append(_indent(indentLevel++) + "{\n");

        Iterator interfaceMethods = interfaceMethodsMap.keySet().iterator();

        while (interfaceMethods.hasNext()) {
            SootMethod interfaceMethod = (SootMethod) interfaceMethods.next();

            // The corresponding actual method.
            SootMethod actualMethod = (SootMethod) interfaceMethodsMap
                    .get(interfaceMethod);

            if (RequiredFileGenerator.isRequired(actualMethod)
            // We don't need to map abstract methods.
                    && !actualMethod.isAbstract()) {
                code.append(_indent(indentLevel)
                        + _comment(interfaceMethod.toString()));

                code.append(_indent(indentLevel) + "case "
                        + CNames.hashNumberOf(interfaceMethod) + ": "
View Full Code Here

TOP

Related Classes of soot.SootMethod

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.