Package soot

Examples of soot.Local


        for (List<Unit> scc : sccAnalysis.getTrueComponents()) {
      for (Unit unit : scc) {
        for (ValueBox vb : unit.getDefBoxes()) {
          Value defValue = vb.getValue();
          if(defValue instanceof Local) {
            Local defLocal = (Local) defValue;
            if(defLocal.getType() instanceof RefLikeType) {
              Object instanceKey = getFlowBefore(unit).get(defLocal);
              //if key is not already UNKNOWN
              if(instanceKey instanceof Integer) {
                Integer intKey = (Integer) instanceKey;
                invalidInstanceKeys.add(intKey);
View Full Code Here


          Value className = ie.getArg(0);
          if( className instanceof StringConstant ) {
              String cls = ((StringConstant) className ).value;
              constantForName( cls, source, s );
          } else {
              Local constant = (Local) className;
              if( options.safe_forname() ) {
                  for (SootMethod tgt : EntryPoints.v().clinits()) {
                      addEdge( source, s, tgt, Kind.CLINIT );
                  }
              } else {
View Full Code Here

       
        //exc = new Error
        RefType runtimeExceptionType = RefType.v("java.lang.Error");
        NewExpr newExpr = Jimple.v().newNewExpr(runtimeExceptionType);
        LocalGenerator lg = new LocalGenerator(body);
        Local exceptionLocal = lg.generateLocal(runtimeExceptionType);
        AssignStmt assignStmt = Jimple.v().newAssignStmt(exceptionLocal, newExpr);
        body.getUnits().insertBefore(assignStmt, insertionPoint);
       
        //exc.<init>(message)
        SootMethodRef cref = runtimeExceptionType.getSootClass().getMethod("<init>", Collections.singletonList(RefType.v("java.lang.String"))).makeRef();
View Full Code Here

            if (s.containsInvokeExpr()) {
                InvokeExpr ie = s.getInvokeExpr();

                if (ie instanceof InstanceInvokeExpr) {
                    InstanceInvokeExpr iie = (InstanceInvokeExpr) ie;
                    Local receiver = (Local) iie.getBase();
                    NumberedString subSig =
                        iie.getMethodRef().getSubSignature();
                    addVirtualCallSite( s, m, receiver, iie, subSig,
                            Edge.ieToKind(iie) );
                    if( subSig == sigStart ) {
                        addVirtualCallSite( s, m, receiver, iie, sigRun,
                                Kind.THREAD );
                    }
                } else {
                  SootMethod tgt = ie.getMethod();
                  addEdge(m, s, tgt);
                  if( tgt.getSignature().equals( "<java.security.AccessController: java.lang.Object doPrivileged(java.security.PrivilegedAction)>" )
                      ||  tgt.getSignature().equals( "<java.security.AccessController: java.lang.Object doPrivileged(java.security.PrivilegedExceptionAction)>" )
                      ||  tgt.getSignature().equals( "<java.security.AccessController: java.lang.Object doPrivileged(java.security.PrivilegedAction,java.security.AccessControlContext)>" )
                      ||  tgt.getSignature().equals( "<java.security.AccessController: java.lang.Object doPrivileged(java.security.PrivilegedExceptionAction,java.security.AccessControlContext)>" ) ) {
                   
                    Local receiver = (Local) ie.getArg(0);
                    addVirtualCallSite( s, m, receiver, null, sigObjRun,
                        Kind.PRIVILEGED );
                  }                     
                }
            }
View Full Code Here

                                PtolemyUtilities.tokenClass)) {
                            if (_debug) {
                                System.out.println("handling as token type");
                            }

                            Local local = PtolemyUtilities
                                    .buildConstantTokenLocal(body, unit,
                                            (Token) object, "token");
                            box.setValue(local);
                            doneSomething = true;
                        } else if (returnClass.getName().equals(
View Full Code Here

            JimpleBody body = Jimple.v().newBody(initMethod);
            initMethod.setActiveBody(body);
            body.insertIdentityStmts();

            Chain units = body.getUnits();
            Local thisLocal = body.getThisLocal();

            // Populate...
            // Initialize attributes that already exist in the class.
            ModelTransformer.createAttributes(body, entity, thisLocal, entity,
                    thisLocal, entityInstanceClass, tempCreatedMap);

            // Create and initialize ports
            ModelTransformer.createPorts(body, thisLocal, entity, thisLocal,
                    entity, entityInstanceClass, tempCreatedMap);

            // return void
            units.add(Jimple.v().newReturnVoidStmt());
        }

        // Add fields to contain the tokens for each port.
        Map nameToField = new HashMap();
        Map nameToType = new HashMap();

        {
            Iterator inputPorts = entity.inputPortList().iterator();

            while (inputPorts.hasNext()) {
                TypedIOPort port = (TypedIOPort) (inputPorts.next());
                String name = port.getName(entity);
                Type type = PtolemyUtilities.tokenType;
                nameToType.put(name, port.getType());

                SootField field = new SootField(StringUtilities
                        .sanitizeName(name)
                        + "Token", type);
                entityInstanceClass.addField(field);
                nameToField.put(name, field);
            }
        }
        // Populate the fire method.
        {
            SootMethod fireMethod = new SootMethod("fire",
                    Collections.EMPTY_LIST, VoidType.v(), Modifier.PUBLIC);
            entityInstanceClass.addMethod(fireMethod);

            JimpleBody body = Jimple.v().newBody(fireMethod);
            fireMethod.setActiveBody(body);
            body.insertIdentityStmts();

            Chain units = body.getUnits();
            Local thisLocal = body.getThisLocal();

            Local hasTokenLocal = Jimple.v().newLocal("hasTokenLocal",
                    BooleanType.v());
            body.getLocals().add(hasTokenLocal);

            Local tokenLocal = Jimple.v().newLocal("tokenLocal",
                    PtolemyUtilities.tokenType);
            body.getLocals().add(tokenLocal);

            Iterator inputPorts = entity.inputPortList().iterator();

            while (inputPorts.hasNext()) {
                TypedIOPort port = (TypedIOPort) (inputPorts.next());

                // FIXME: Handle multiports
                if (port.getWidth() > 0) {
                    String name = port.getName(entity);

                    // Create an if statement.
                    //
                    Local portLocal = Jimple.v().newLocal("port",
                            PtolemyUtilities.componentPortType);
                    body.getLocals().add(portLocal);

                    SootField portField = entityInstanceClass
                            .getFieldByName(StringUtilities.sanitizeName(name));
                    units.add(Jimple.v().newAssignStmt(
                            portLocal,
                            Jimple.v().newInstanceFieldRef(thisLocal,
                                    portField.makeRef())));
                    units.add(Jimple.v().newAssignStmt(
                            hasTokenLocal,
                            Jimple.v().newVirtualInvokeExpr(portLocal,
                                    PtolemyUtilities.hasTokenMethod.makeRef(),
                                    IntConstant.v(0))));

                    Stmt target = Jimple.v().newNopStmt();
                    units.add(Jimple.v().newIfStmt(
                            Jimple.v().newEqExpr(hasTokenLocal,
                                    IntConstant.v(0)), target));
                    units.add(Jimple.v().newAssignStmt(
                            tokenLocal,
                            Jimple.v().newVirtualInvokeExpr(portLocal,
                                    PtolemyUtilities.getMethod.makeRef(),
                                    IntConstant.v(0))));

                    SootField tokenField = entityInstanceClass
                            .getFieldByName(name + "Token");
                    units.add(Jimple.v().newAssignStmt(
                            Jimple.v().newInstanceFieldRef(thisLocal,
                                    tokenField.makeRef()), tokenLocal));
                    units.add(target);
                }
            }

            StringAttribute expressionAttribute = (StringAttribute) entity
                    .getAttribute("expression");
            String expression = expressionAttribute.getExpression();

            Local local = DataUtilities.generateExpressionCode(entity,
                    entityInstanceClass, expression, nameToField, nameToType,
                    body);

            // send the computed token
            String name = "output";
            Local portLocal = Jimple.v().newLocal("port",
                    PtolemyUtilities.componentPortType);
            body.getLocals().add(portLocal);

            SootField portField = entityInstanceClass.getFieldByName(name);
View Full Code Here

                if (unit instanceof DefinitionStmt) {
                    DefinitionStmt stmt = (DefinitionStmt) unit;
                    Value rightValue = stmt.getRightOp();

                    if (stmt.getLeftOp() instanceof Local) {
                        Local local = (Local) stmt.getLeftOp();

                        if (rightValue instanceof Local) {
                            _update(local, (Local) rightValue);
                        } else if (rightValue instanceof CastExpr) {
                            Value value = ((CastExpr) rightValue).getOp();
View Full Code Here

            NamedObjAnalysis analysis = new NamedObjAnalysis(newMethod,
                    ModelTransformer.getObjectForClass(theClass));

            for (Iterator locals = newBody.getLocals().iterator(); locals
                    .hasNext();) {
                Local local = (Local) locals.next();
                Type type = local.getType();

                try {
                    if (type instanceof RefType
                            && (((RefType) type).getSootClass() == oldClass)
                            && (object == analysis.getObject(local))) {
                        local.setType(RefType.v(newClass));
                    }
                } catch (Exception ex) {
                    if (_debug) {
                        System.out.println("Exception on local = " + ex);
                    }
View Full Code Here

                                            .v()
                                            .loadClassAndSupport("java.net.URI");
                                    RefType type = RefType.v(uriClass);
                                    SootMethod initMethod = uriClass
                                            .getMethod("void <init>(java.lang.String)");
                                    Local local = (Local) ((AssignStmt) unit)
                                            .getLeftOp();
                                    String uriString = URIAttribute
                                            .getModelURI(_model).toString();
                                    body
                                            .getUnits()
                                            .insertBefore(
                                                    Jimple
                                                            .v()
                                                            .newAssignStmt(
                                                                    local,
                                                                    Jimple
                                                                            .v()
                                                                            .newNewExpr(
                                                                                    type)),
                                                    unit);
                                    body
                                            .getUnits()
                                            .insertBefore(
                                                    Jimple
                                                            .v()
                                                            .newInvokeStmt(
                                                                    Jimple
                                                                            .v()
                                                                            .newSpecialInvokeExpr(
                                                                                    local,
                                                                                    initMethod
                                                                                            .makeRef(),
                                                                                    StringConstant
                                                                                            .v(uriString))),
                                                    unit);
                                }

                                body.getUnits().remove(unit);
                            } else if (expr
                                    .getMethod()
                                    .getSubSignature()
                                    .equals(
                                            PtolemyUtilities.handleModelErrorMethod
                                                    .getSubSignature())) {
                                // Replace handleModelError with a throw clause.
                                body.getUnits()
                                        .insertBefore(
                                                Jimple.v().newThrowStmt(
                                                        expr.getArg(1)), unit);
                                body.getUnits().remove(unit);
                            }
                        }
                    }
                }
            }
        }

        List modifiedConstructorClassList = new LinkedList();

        // Loop over all the classes
        for (Iterator i = Scene.v().getApplicationClasses().iterator(); i
                .hasNext();) {
            SootClass theClass = (SootClass) i.next();

            if (SootUtilities
                    .derivesFrom(theClass, PtolemyUtilities.actorClass)
                    || SootUtilities.derivesFrom(theClass,
                            PtolemyUtilities.compositeActorClass)
                    || SootUtilities.derivesFrom(theClass,
                            PtolemyUtilities.attributeClass)) {
                System.out.println("changing superclass for " + theClass);
                theClass.setSuperclass(PtolemyUtilities.objectClass);

                // Fix the constructor for the actor to take just a
                // container argument, if it was a 2 arg constructor,
                // or no arguments otherwise.  FIXME: Here we assume
                // that there is just one constructor.. This will
                // throw an exception if there is more than one, in
                // which case we need to improve this code.
                SootMethod method = null;

                try {
                    method = theClass.getMethodByName("<init>");
                } catch (RuntimeException ex) {
                    System.out.println("Could not get method <init> by name "
                            + "from class " + theClass);
                    System.out.println("Methods = " + theClass.getMethods());
                    throw ex;
                }

                if (method.getParameterCount() == 2) {
                    // Change the constructor so that it only takes the container.
                    SootField containerField = theClass
                            .getFieldByName(ModelTransformer
                                    .getContainerFieldName());
                    RefType containerType = (RefType) containerField.getType();
                    List typeList = new LinkedList();
                    typeList.add(containerType);
                    method.setParameterTypes(typeList);
                } else {
                    method.setParameterTypes(Collections.EMPTY_LIST);
                }

                // Keep track of the modification, so we know to
                // modify invocations of that constructor.
                modifiedConstructorClassList.add(theClass);

                // Dance so that indexes in the Scene are properly updated.
                theClass.removeMethod(method);
                theClass.addMethod(method);

                System.out.println("method = " + method);
                JimpleBody body = (JimpleBody) method.retrieveActiveBody();

                for (Iterator units = body.getUnits().snapshotIterator(); units
                        .hasNext();) {
                    Stmt unit = (Stmt) units.next();

                    if (unit.containsInvokeExpr()) {
                        ValueBox box = unit.getInvokeExprBox();
                        Value value = box.getValue();

                        if (value instanceof SpecialInvokeExpr) {
                            // Fix super.<init> calls. constructor...
                            SpecialInvokeExpr expr = (SpecialInvokeExpr) value;

                            if (expr.getBase().equals(body.getThisLocal())
                                    && expr.getMethodRef().name().equals(
                                            "<init>")) {
                                //             System.out.println("replacing constructor = "
                                //       + unit + " in method " + method);
                                // Replace with zero arg object constructor.
                                box.setValue(Jimple.v().newSpecialInvokeExpr(
                                        (Local) expr.getBase(),
                                        PtolemyUtilities.objectConstructor
                                                .makeRef(),
                                        Collections.EMPTY_LIST));
                            }
                        }
                    } else if (unit instanceof IdentityStmt) {
                        IdentityStmt identityStmt = (IdentityStmt) unit;
                        Value value = identityStmt.getRightOp();

                        if (value instanceof ParameterRef) {
                            ParameterRef parameterRef = (ParameterRef) value;

                            if ((parameterRef.getIndex() == 0)
                                    && (method.getParameterCount() == 1)) {
                                //       System.out.println("found = " + identityStmt);
                                ValueBox box = identityStmt.getRightOpBox();
                                box.setValue(Jimple.v().newParameterRef(
                                        method.getParameterType(0), 0));

                                //    System.out.println("changed to: " + identityStmt);
                            } else {
                                // Parameter values are null.  Note that
                                // we need to make sure that the
                                // assignment to null happens after all
                                // the identity statements, otherwise the
                                // super constructor will be implicitly
                                // called.
                                body.getUnits().remove(identityStmt);
                                body.getUnits().insertBefore(
                                        Jimple.v().newAssignStmt(
                                                identityStmt.getLeftOp(),
                                                NullConstant.v()),
                                        body.getFirstNonIdentityStmt());
                            }
                        } //  else if (value instanceof ThisRef) {

                        //                             // Fix the type of thisRefs.
                        //                             ValueBox box = identityStmt.getRightOpBox();
                        //                             box.setValue(
                        //                                     Jimple.v().newThisRef(
                        //                                             RefType.v(PtolemyUtilities.objectClass)));
                        //                         }
                    }
                }
            }
        }

        // Reset the hierarchy, since we've changed superclasses and such.
        Scene.v().setActiveHierarchy(new Hierarchy());
        Scene.v().setFastHierarchy(new FastHierarchy());

        // Fix the specialInvokes.
        for (Iterator i = Scene.v().getApplicationClasses().iterator(); i
                .hasNext();) {
            SootClass theClass = (SootClass) i.next();

            // Loop through all the methods in the class.
            for (Iterator methods = theClass.getMethods().iterator(); methods
                    .hasNext();) {
                SootMethod method = (SootMethod) methods.next();

                // System.out.println("method = " + method);
                JimpleBody body = (JimpleBody) method.retrieveActiveBody();

                for (Iterator units = body.getUnits().snapshotIterator(); units
                        .hasNext();) {
                    Stmt unit = (Stmt) units.next();

                    if (unit.containsInvokeExpr()) {
                        ValueBox box = unit.getInvokeExprBox();
                        Value value = box.getValue();

                        if (value instanceof SpecialInvokeExpr) {
                            // If we're constructing one of our actor classes,
                            // then switch to the modified constructor.
                            SpecialInvokeExpr expr = (SpecialInvokeExpr) value;
                            SootClass declaringClass = expr.getMethodRef()
                                    .declaringClass();

                            if (expr.getMethodRef().name().equals("<init>")
                                    && modifiedConstructorClassList
                                            .contains(declaringClass)) {
                                System.out
                                        .println("replacing constructor invocation = "
                                                + unit + " in method " + method);
                                SootMethod newConstructor = declaringClass
                                        .getMethodByName("<init>");

                                if (newConstructor.getParameterCount() == 1) {
                                    // Replace with just container arg constructor.
                                    List args = new LinkedList();
                                    args.add(expr.getArg(0));
                                    box.setValue(Jimple.v()
                                            .newSpecialInvokeExpr(
                                                    (Local) expr.getBase(),
                                                    newConstructor.makeRef(),
                                                    args));
                                } else {
                                    // Replace with zero arg constructor.
                                    box.setValue(Jimple.v()
                                            .newSpecialInvokeExpr(
                                                    (Local) expr.getBase(),
                                                    newConstructor.makeRef(),
                                                    Collections.EMPTY_LIST));
                                }
                            }
                        }
                    }
                }
            }
        }

        for (Iterator i = Scene.v().getApplicationClasses().iterator(); i
                .hasNext();) {
            SootClass theClass = (SootClass) i.next();

            // Loop through all the methods in the class.
            for (Iterator methods = theClass.getMethods().iterator(); methods
                    .hasNext();) {
                SootMethod method = (SootMethod) methods.next();

                // System.out.println("method = " + method);
                JimpleBody body = (JimpleBody) method.retrieveActiveBody();

                // Infer types.
                LocalSplitter.v().transform(body, "nee.ls");
                TypeAssigner.v().transform(body, "nee.ta");
            }
        }

        for (Iterator i = Scene.v().getApplicationClasses().iterator(); i
                .hasNext();) {
            SootClass theClass = (SootClass) i.next();

            // Loop through all the methods in the class.
            for (Iterator methods = theClass.getMethods().iterator(); methods
                    .hasNext();) {
                SootMethod method = (SootMethod) methods.next();

                // System.out.println("method = " + method);
                JimpleBody body = (JimpleBody) method.retrieveActiveBody();
                for (Iterator units = body.getUnits().snapshotIterator(); units
                        .hasNext();) {
                    Stmt unit = (Stmt) units.next();

                    //        System.out.println("unit = " + unit);
                    // If any box is removable, then remove the statement.
                    for (Iterator boxes = unit.getUseAndDefBoxes().iterator(); boxes
                            .hasNext();) {
                        ValueBox box = (ValueBox) boxes.next();

                        Value value = box.getValue();
                        Type type = value.getType();

                        if (_isRemovableType(type)) {
                            //  System.out.println("Unit with removable type "
                            //        + type + ": " + unit);
                            body.getUnits().remove(unit);
                            break;
                        }
                    }

                    // If any locals are removable, then remove them.
                    for (Iterator locals = body.getLocals().snapshotIterator(); locals
                            .hasNext();) {
                        Local local = (Local) locals.next();
                        Type type = local.getType();

                        if (_isRemovableType(type)) {
                            body.getLocals().remove(local);
                        }
                    }
View Full Code Here

        if (value instanceof VirtualInvokeExpr
                || value instanceof InterfaceInvokeExpr
                || value instanceof SpecialInvokeExpr) {
            InstanceInvokeExpr r = (InstanceInvokeExpr) value;

            Local local = (Local) r.getBase();
            Type baseType = local.getType();

            if (baseType instanceof NullType) {
                // replace with NullPointerException..
                if (debug) {
                    System.out.println("Invoke base is null, replacing with "
                            + "NullPointerException");
                }

                Local exception = SootUtilities.createRuntimeException(body,
                        unit, "NullPointerException");
                body.getUnits().insertBefore(
                        Jimple.v().newThrowStmt(exception), unit);
                body.getUnits().remove(unit);
            }

            boolean isInlineableTokenMethod = _isLocalTokenTypeWithDepth(local,
                    typeAnalysis, unsafeLocalSet, depth, debug);

            if (debug) {
                System.out.println("checking inline for " + r);
            }

            // Check if token arguments are being used.  This makes
            // sure we get methods like Scale._scaleOnRight and
            // DB._doFunction inlined.  It would be better if the
            // token inliner modified the functions, but it doesn't.
            if (baseType instanceof RefType
                    && Scene.v().getApplicationClasses().contains(
                            ((RefType) baseType).getSootClass())) {
                Type returnType = r.getMethod().getReturnType();
                isInlineableTokenMethod |= _isInlineableTokenType(returnType);

                for (Iterator args = r.getArgs().iterator(); args.hasNext()
                        && !isInlineableTokenMethod;) {
                    Object arg = args.next();

                    if (arg instanceof Local) {
                        Local argLocal = (Local) arg;

                        if (debug) {
                            System.out.println("argtype = "
                                    + argLocal.getType());
                        }

                        isInlineableTokenMethod = _isLocalTokenTypeWithDepth(
                                argLocal, typeAnalysis, unsafeLocalSet, depth,
                                debug);
View Full Code Here

TOP

Related Classes of soot.Local

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.