Source Code Cross Referenced for SideEffectAnalysis.java in  » Code-Analyzer » soot » soot » jimple » toolkits » pointer » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Code Analyzer » soot » soot.jimple.toolkits.pointer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Soot - a J*va Optimization Framework
002:         * Copyright (C) 2003 Ondrej Lhotak
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2.1 of the License, or (at your option) any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the
016:         * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
017:         * Boston, MA 02111-1307, USA.
018:         */
019:
020:        package soot.jimple.toolkits.pointer;
021:
022:        import soot.*;
023:        import soot.jimple.*;
024:        import soot.jimple.toolkits.callgraph.*;
025:        import java.util.*;
026:
027:        /** Generates side-effect information from a PointsToAnalysis. */
028:        public class SideEffectAnalysis {
029:            PointsToAnalysis pa;
030:            CallGraph cg;
031:            Map<SootMethod, MethodRWSet> methodToNTReadSet = new HashMap<SootMethod, MethodRWSet>();
032:            Map<SootMethod, MethodRWSet> methodToNTWriteSet = new HashMap<SootMethod, MethodRWSet>();
033:            int rwsetcount = 0;
034:            TransitiveTargets tt;
035:
036:            public void findNTRWSets(SootMethod method) {
037:                if (methodToNTReadSet.containsKey(method)
038:                        && methodToNTWriteSet.containsKey(method))
039:                    return;
040:
041:                MethodRWSet read = null;
042:                MethodRWSet write = null;
043:                for (Iterator sIt = method.retrieveActiveBody().getUnits()
044:                        .iterator(); sIt.hasNext();) {
045:                    final Stmt s = (Stmt) sIt.next();
046:                    RWSet ntr = ntReadSet(method, s);
047:                    if (ntr != null) {
048:                        if (read == null)
049:                            read = new MethodRWSet();
050:                        read.union(ntr);
051:                    }
052:                    RWSet ntw = ntWriteSet(method, s);
053:                    if (ntw != null) {
054:                        if (write == null)
055:                            write = new MethodRWSet();
056:                        write.union(ntw);
057:                    }
058:                }
059:                methodToNTReadSet.put(method, read);
060:                methodToNTWriteSet.put(method, write);
061:                SootClass c = method.getDeclaringClass();
062:            }
063:
064:            public RWSet nonTransitiveReadSet(SootMethod method) {
065:                findNTRWSets(method);
066:                return methodToNTReadSet.get(method);
067:            }
068:
069:            public RWSet nonTransitiveWriteSet(SootMethod method) {
070:                findNTRWSets(method);
071:                return methodToNTWriteSet.get(method);
072:            }
073:
074:            public SideEffectAnalysis(PointsToAnalysis pa, CallGraph cg) {
075:                this .pa = pa;
076:                this .cg = cg;
077:                this .tt = new TransitiveTargets(cg);
078:            }
079:
080:            public SideEffectAnalysis(PointsToAnalysis pa, CallGraph cg,
081:                    Filter filter) {
082:                // This constructor allows customization of call graph edges to
083:                // consider via the use of a transitive targets filter.
084:                // For example, using the NonClinitEdgesPred, you can create a 
085:                // SideEffectAnalysis that will ignore static initializers
086:                // - R. Halpert 2006-12-02
087:                this .pa = pa;
088:                this .cg = cg;
089:                this .tt = new TransitiveTargets(cg, filter);
090:            }
091:
092:            private RWSet ntReadSet(SootMethod method, Stmt stmt) {
093:                if (stmt instanceof  AssignStmt) {
094:                    AssignStmt a = (AssignStmt) stmt;
095:                    Value r = a.getRightOp();
096:                    return addValue(r, method, stmt);
097:                }
098:                return null;
099:            }
100:
101:            public RWSet readSet(SootMethod method, Stmt stmt) {
102:                RWSet ret = null;
103:                Iterator<MethodOrMethodContext> targets = tt.iterator(stmt);
104:                while (targets.hasNext()) {
105:                    SootMethod target = (SootMethod) targets.next();
106:                    if (target.isNative()) {
107:                        if (ret == null)
108:                            ret = new SiteRWSet();
109:                        ret.setCallsNative();
110:                    } else if (target.isConcrete()) {
111:                        RWSet ntr = nonTransitiveReadSet(target);
112:                        if (ntr != null) {
113:                            if (ret == null)
114:                                ret = new SiteRWSet();
115:                            ret.union(ntr);
116:                        }
117:                    }
118:                }
119:                if (ret == null)
120:                    return ntReadSet(method, stmt);
121:                ret.union(ntReadSet(method, stmt));
122:                return ret;
123:            }
124:
125:            private RWSet ntWriteSet(SootMethod method, Stmt stmt) {
126:                if (stmt instanceof  AssignStmt) {
127:                    AssignStmt a = (AssignStmt) stmt;
128:                    Value l = a.getLeftOp();
129:                    return addValue(l, method, stmt);
130:                }
131:                return null;
132:            }
133:
134:            public RWSet writeSet(SootMethod method, Stmt stmt) {
135:                RWSet ret = null;
136:                Iterator<MethodOrMethodContext> targets = tt.iterator(stmt);
137:                while (targets.hasNext()) {
138:                    SootMethod target = (SootMethod) targets.next();
139:                    if (target.isNative()) {
140:                        if (ret == null)
141:                            ret = new SiteRWSet();
142:                        ret.setCallsNative();
143:                    } else if (target.isConcrete()) {
144:                        RWSet ntw = nonTransitiveWriteSet(target);
145:                        if (ntw != null) {
146:                            if (ret == null)
147:                                ret = new SiteRWSet();
148:                            ret.union(ntw);
149:                        }
150:                    }
151:                }
152:                if (ret == null)
153:                    return ntWriteSet(method, stmt);
154:                ret.union(ntWriteSet(method, stmt));
155:                return ret;
156:            }
157:
158:            protected RWSet addValue(Value v, SootMethod m, Stmt s) {
159:                RWSet ret = null;
160:                if (v instanceof  InstanceFieldRef) {
161:                    InstanceFieldRef ifr = (InstanceFieldRef) v;
162:                    PointsToSet base = pa
163:                            .reachingObjects((Local) ifr.getBase());
164:                    ret = new StmtRWSet();
165:                    ret.addFieldRef(base, ifr.getField());
166:                } else if (v instanceof  StaticFieldRef) {
167:                    StaticFieldRef sfr = (StaticFieldRef) v;
168:                    ret = new StmtRWSet();
169:                    ret.addGlobal(sfr.getField());
170:                } else if (v instanceof  ArrayRef) {
171:                    ArrayRef ar = (ArrayRef) v;
172:                    PointsToSet base = pa.reachingObjects((Local) ar.getBase());
173:                    ret = new StmtRWSet();
174:                    ret.addFieldRef(base, PointsToAnalysis.ARRAY_ELEMENTS_NODE);
175:                }
176:                return ret;
177:            }
178:
179:            public String toString() {
180:                return "SideEffectAnalysis: PA=" + pa + " CG=" + cg;
181:            }
182:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.