Source Code Cross Referenced for LocalSplitter.java in  » Code-Analyzer » soot » soot » toolkits » scalar » 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.toolkits.scalar 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Soot - a J*va Optimization Framework
002:         * Copyright (C) 1997-1999 Raja Vallee-Rai
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:        /*
021:         * Modified by the Sable Research Group and others 1997-1999.  
022:         * See the 'credits' file distributed with Soot for the complete list of
023:         * contributors.  (Soot is distributed at http://www.sable.mcgill.ca/soot)
024:         */
025:
026:        package soot.toolkits.scalar;
027:
028:        import soot.options.*;
029:
030:        import soot.*;
031:        import soot.toolkits.graph.*;
032:        import soot.util.*;
033:        import java.util.*;
034:
035:        /**
036:         *    A BodyTransformer that attemps to indentify and separate uses of a local
037:         *    varible that are independent of each other. Conceptually the inverse transform
038:         *    with respect to the LocalPacker transform.
039:         *
040:         *    For example the code:
041:         *
042:         *    for(int i; i < k; i++);
043:         *    for(int i; i < k; i++);
044:         *
045:         *    would be transformed into:
046:         *    for(int i; i < k; i++);
047:         *    for(int j; j < k; j++);
048:         *
049:         *
050:         *    @see BodyTransformer
051:         *    @see LocalPacker
052:         *    @see Body 
053:         */
054:        public class LocalSplitter extends BodyTransformer {
055:            public LocalSplitter(Singletons.Global g) {
056:            }
057:
058:            public static LocalSplitter v() {
059:                return G.v().soot_toolkits_scalar_LocalSplitter();
060:            }
061:
062:            protected void internalTransform(Body body, String phaseName,
063:                    Map options) {
064:                Chain units = body.getUnits();
065:                List<List> webs = new ArrayList<List>();
066:
067:                if (Options.v().verbose())
068:                    G.v().out.println("[" + body.getMethod().getName()
069:                            + "] Splitting locals...");
070:
071:                Map boxToSet = new HashMap(units.size() * 2 + 1, 0.7f);
072:
073:                if (Options.v().time())
074:                    Timers.v().splitPhase1Timer.start();
075:
076:                // Go through the definitions, building the webs
077:                {
078:                    ExceptionalUnitGraph graph = new ExceptionalUnitGraph(body);
079:
080:                    LocalDefs localDefs;
081:
082:                    localDefs = new SmartLocalDefs(graph, new SimpleLiveLocals(
083:                            graph));
084:
085:                    LocalUses localUses = new SimpleLocalUses(graph, localDefs);
086:
087:                    if (Options.v().time())
088:                        Timers.v().splitPhase1Timer.end();
089:
090:                    if (Options.v().time())
091:                        Timers.v().splitPhase2Timer.start();
092:
093:                    Set<ValueBox> markedBoxes = new HashSet<ValueBox>();
094:                    Map<ValueBox, Unit> boxToUnit = new HashMap<ValueBox, Unit>(
095:                            units.size() * 2 + 1, 0.7f);
096:
097:                    Iterator codeIt = units.iterator();
098:
099:                    while (codeIt.hasNext()) {
100:                        Unit s = (Unit) codeIt.next();
101:
102:                        if (s.getDefBoxes().size() > 1)
103:                            throw new RuntimeException(
104:                                    "stmt with more than 1 defbox!");
105:
106:                        if (s.getDefBoxes().size() < 1)
107:                            continue;
108:
109:                        ValueBox loBox = (ValueBox) s.getDefBoxes().get(0);
110:                        Value lo = loBox.getValue();
111:
112:                        if (lo instanceof  Local && !markedBoxes.contains(loBox)) {
113:                            LinkedList<Unit> defsToVisit = new LinkedList<Unit>();
114:                            LinkedList<ValueBox> boxesToVisit = new LinkedList<ValueBox>();
115:
116:                            List web = new ArrayList();
117:                            webs.add(web);
118:
119:                            defsToVisit.add(s);
120:                            markedBoxes.add(loBox);
121:
122:                            while (!boxesToVisit.isEmpty()
123:                                    || !defsToVisit.isEmpty()) {
124:                                if (!defsToVisit.isEmpty()) {
125:                                    Unit d = defsToVisit.removeFirst();
126:
127:                                    web.add(d.getDefBoxes().get(0));
128:
129:                                    // Add all the uses of this definition to the queue
130:                                    {
131:                                        List uses = localUses.getUsesOf(d);
132:                                        Iterator useIt = uses.iterator();
133:
134:                                        while (useIt.hasNext()) {
135:                                            UnitValueBoxPair use = (UnitValueBoxPair) useIt
136:                                                    .next();
137:
138:                                            if (!markedBoxes
139:                                                    .contains(use.valueBox)) {
140:                                                markedBoxes.add(use.valueBox);
141:                                                boxesToVisit
142:                                                        .addLast(use.valueBox);
143:                                                boxToUnit.put(use.valueBox,
144:                                                        use.unit);
145:                                            }
146:                                        }
147:                                    }
148:                                } else {
149:                                    ValueBox box = boxesToVisit.removeFirst();
150:
151:                                    web.add(box);
152:
153:                                    // Add all the definitions of this use to the queue.
154:                                    {
155:                                        List<Unit> defs = localDefs
156:                                                .getDefsOfAt((Local) box
157:                                                        .getValue(), boxToUnit
158:                                                        .get(box));
159:                                        Iterator<Unit> defIt = defs.iterator();
160:
161:                                        while (defIt.hasNext()) {
162:                                            Unit u = defIt.next();
163:
164:                                            Iterator defBoxesIter = u
165:                                                    .getDefBoxes().iterator();
166:                                            ValueBox b;
167:
168:                                            for (; defBoxesIter.hasNext();) {
169:                                                b = (ValueBox) defBoxesIter
170:                                                        .next();
171:                                                if (!markedBoxes.contains(b)) {
172:                                                    markedBoxes.add(b);
173:                                                    defsToVisit.addLast(u);
174:                                                }
175:                                            }
176:                                        }
177:                                    }
178:                                }
179:                            }
180:                        }
181:                    }
182:                }
183:
184:                // Assign locals appropriately.
185:                {
186:                    Map<Local, Integer> localToUseCount = new HashMap<Local, Integer>(
187:                            body.getLocalCount() * 2 + 1, 0.7f);
188:                    Iterator<List> webIt = webs.iterator();
189:
190:                    while (webIt.hasNext()) {
191:                        List web = webIt.next();
192:
193:                        ValueBox rep = (ValueBox) web.get(0);
194:                        Local desiredLocal = (Local) rep.getValue();
195:
196:                        if (!localToUseCount.containsKey(desiredLocal)) {
197:                            // claim this local for this set
198:
199:                            localToUseCount.put(desiredLocal, new Integer(1));
200:                        } else {
201:                            // generate a new local
202:
203:                            int useCount = localToUseCount.get(desiredLocal)
204:                                    .intValue() + 1;
205:                            localToUseCount.put(desiredLocal, new Integer(
206:                                    useCount));
207:
208:                            Local local = (Local) desiredLocal.clone();
209:                            local.setName(desiredLocal.getName() + "#"
210:                                    + useCount);
211:
212:                            body.getLocals().add(local);
213:
214:                            // Change all boxes to point to this new local
215:                            {
216:                                Iterator j = web.iterator();
217:
218:                                while (j.hasNext()) {
219:                                    ValueBox box = (ValueBox) j.next();
220:
221:                                    box.setValue(local);
222:                                }
223:                            }
224:                        }
225:                    }
226:                }
227:
228:                if (Options.v().time())
229:                    Timers.v().splitPhase2Timer.end();
230:
231:            }
232:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.