Java Doc for Flow.java in  » 6.0-JDK-Modules-sun » javac-compiler » com » sun » tools » javac » comp » 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 » 6.0 JDK Modules sun » javac compiler » com.sun.tools.javac.comp 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


com.sun.tools.javac.tree.TreeScanner
   com.sun.tools.javac.comp.Flow

Flow
public class Flow extends TreeScanner (Code)
This pass implements dataflow analysis for Java programs. Liveness analysis checks that every statement is reachable. Exception analysis ensures that every checked exception that is thrown is declared or caught. Definite assignment analysis ensures that each variable is assigned when used. Definite unassignment analysis ensures that no final variable is assigned more than once.

The second edition of the JLS has a number of problems in the specification of these flow analysis problems. This implementation attempts to address those issues.

First, there is no accommodation for a finally clause that cannot complete normally. For liveness analysis, an intervening finally clause can cause a break, continue, or return not to reach its target. For exception analysis, an intervening finally clause can cause any exception to be "caught". For DA/DU analysis, the finally clause can prevent a transfer of control from propagating DA/DU state to the target. In addition, code in the finally clause can affect the DA/DU status of variables.

For try statements, we introduce the idea of a variable being definitely unassigned "everywhere" in a block. A variable V is "unassigned everywhere" in a block iff it is unassigned at the beginning of the block and there is no reachable assignment to V in the block. An assignment V=e is reachable iff V is not DA after e. Then we can say that V is DU at the beginning of the catch block iff V is DU everywhere in the try block. Similarly, V is DU at the beginning of the finally block iff V is DU everywhere in the try block and in every catch block. Specifically, the following bullet is added to 16.2.2

 V is unassigned everywhere in a block if it is
 unassigned before the block and there is no reachable
 assignment to V within the block.
 

In 16.2.15, the third bullet (and all of its sub-bullets) for all try blocks is changed to

 V is definitely unassigned before a catch block iff V is
 definitely unassigned everywhere in the try block.
 

The last bullet (and all of its sub-bullets) for try blocks that have a finally block is changed to

 V is definitely unassigned before the finally block iff
 V is definitely unassigned everywhere in the try block
 and everywhere in each catch block of the try statement.
 

In addition,

 V is definitely assigned at the end of a constructor iff
 V is definitely assigned after the block that is the body
 of the constructor and V is definitely assigned at every
 return that can return from the constructor.
 

In addition, each continue statement with the loop as its target is treated as a jump to the end of the loop body, and "intervening" finally clauses are treated as follows: V is DA "due to the continue" iff V is DA before the continue statement or V is DA at the end of any intervening finally block. V is DU "due to the continue" iff any intervening finally cannot complete normally or V is DU at the end of every intervening finally block. This "due to the continue" concept is then used in the spec for the loops.

Similarly, break statements must consider intervening finally blocks. For liveness analysis, a break statement for which any intervening finally cannot complete normally is not considered to cause the target statement to be able to complete normally. Then we say V is DA "due to the break" iff V is DA before the break or V is DA at the end of any intervening finally block. V is DU "due to the break" iff any intervening finally cannot complete normally or V is DU at the break and at the end of every intervening finally block. (I suspect this latter condition can be simplified.) This "due to the break" is then used in the spec for all statements that can be "broken".

The return statement is treated similarly. V is DA "due to a return statement" iff V is DA before the return statement or V is DA at the end of any intervening finally block. Note that we don't have to worry about the return expression because this concept is only used for construcrors.

There is no spec in JLS2 for when a variable is definitely assigned at the end of a constructor, which is needed for final fields (8.3.1.2). We implement the rule that V is DA at the end of the constructor iff it is DA and the end of the body of the constructor and V is DA "due to" every return of the constructor.

Intervening finally blocks similarly affect exception analysis. An intervening finally that cannot complete normally allows us to ignore an otherwise uncaught exception.

To implement the semantics of intervening finally clauses, all nonlocal transfers (break, continue, return, throw, method call that can throw a checked exception, and a constructor invocation that can thrown a checked exception) are recorded in a queue, and removed from the queue when we complete processing the target of the nonlocal transfer. This allows us to modify the queue in accordance with the above rules when we encounter a finally clause. The only exception to this [no pun intended] is that checked exceptions that are known to be caught or declared to be caught in the enclosing method are not recorded in the queue, but instead are recorded in a global variable "Set thrown" that records the type of all exceptions that can be thrown.

Other minor issues the treatment of members of other classes (always considered DA except that within an anonymous class constructor, where DA status from the enclosing scope is preserved), treatment of the case expression (V is DA before the case expression iff V is DA after the switch expression), treatment of variables declared in a switch block (the implied DA/DU status after the switch expression is DU and not DA for variables defined in a switch block), the treatment of boolean ?: expressions (The JLS rules only handle b and c non-boolean; the new rule is that if b and c are boolean valued, then V is (un)assigned after a?b:c when true/false iff V is (un)assigned after b when true/false and V is (un)assigned after c when true/false).

There is the remaining question of what syntactic forms constitute a reference to a variable. It is conventional to allow this.x on the left-hand-side to initialize a final instance field named x, yet this.x isn't considered a "use" when appearing on a right-hand-side in most implementations. Should parentheses affect what is considered a variable reference? The simplest rule would be to allow unqualified forms only, parentheses optional, and phase out support for assigning to a final field via this.x.

This is NOT part of any API supported by Sun Microsystems. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.


Inner Class :static class PendingExit

Field Summary
 List<Type>caught
     The list of exceptions that are either caught or declared to be thrown.
 JCClassDeclclassDef
     The current class being defined.
 intfirstadr
     The first variable sequence number in this class definition.
final protected static  Context.Key<Flow>flowKey
    
 Bitsinits
     The set of definitely assigned variables.
 BitsinitsWhenFalse
    
 BitsinitsWhenTrue
     When analyzing a condition, inits and uninits are null.
 booleanloopPassTwo
     Set when processing a loop body the second time for DU analysis.
 intnextadr
     The next available variable sequence number.
 ListBuffer<PendingExit>pendingExits
     The currently pending exits that go from current inner blocks to an enclosing block, in source order.
 List<Type>thrown
     The list of possibly thrown declarable exceptions.
 Bitsuninits
     The set of definitely unassigned variables.
 BitsuninitsTry
     The set of variables that are definitely unassigned everywhere in current try block.
 BitsuninitsWhenFalse
    
 BitsuninitsWhenTrue
    
 VarSymbol[]vars
     A mapping from addresses to variable symbols.

Constructor Summary
protected  Flow(Context context)
    

Method Summary
public  voidanalyzeTree(JCTree tree, TreeMaker make)
     Perform definite assignment/unassignment analysis on a tree.
 voidcheckInit(DiagnosticPosition pos, VarSymbol sym)
     Check that trackable variable is initialized.
 voiderrorUncaught()
     Complain that pending exceptions are not caught.
public static  Flowinstance(Context context)
    
 voidletInit(DiagnosticPosition pos, VarSymbol sym)
     Record an initialization of a trackable variable.
 voidletInit(JCTree tree)
     If tree is either a simple name or of the form this.name or C.this.name, and tree represents a trackable variable, record an initialization of the variable.
 voidmarkDead()
     Record that statement is unreachable.
 voidmarkThrown(JCTree tree, Type exc)
     Record that exception is potentially thrown and check that it is caught.
 voidmerge()
     Merge (intersect) inits/uninits from WhenTrue/WhenFalse sets.
 voidnewVar(VarSymbol sym)
     Initialize new trackable variable by setting its address field to the next available sequence number and entering it under that index into the vars array.
 voidrecordExit(JCTree tree)
     Record an outward transfer of control.
 booleanresolveBreaks(JCTree tree, ListBuffer<PendingExit> oldPendingExits)
     Resolve all breaks of this statement.
 booleanresolveContinues(JCTree tree)
     Resolve all continues of this statement.
 voidscanCond(JCTree tree)
     Analyze a condition.
 voidscanDef(JCTree tree)
     Analyze a definition.
 voidscanExpr(JCTree tree)
     Analyze an expression.
 voidscanExprs(List<? extends JCExpression> trees)
     Analyze a list of expressions.
 voidscanStat(JCTree tree)
     Analyze a statement.
 voidscanStats(List<? extends JCStatement> trees)
     Analyze list of statements.
 voidsplit()
    
 booleantrackable(VarSymbol sym)
     Do we need to track init/uninit state of this symbol? I.e.
public  voidvisitApply(JCMethodInvocation tree)
    
public  voidvisitAssert(JCAssert tree)
    
public  voidvisitAssign(JCAssign tree)
    
public  voidvisitAssignop(JCAssignOp tree)
    
public  voidvisitBinary(JCBinary tree)
    
public  voidvisitBlock(JCBlock tree)
    
public  voidvisitBreak(JCBreak tree)
    
public  voidvisitClassDef(JCClassDecl tree)
    
public  voidvisitConditional(JCConditional tree)
    
public  voidvisitContinue(JCContinue tree)
    
public  voidvisitDoLoop(JCDoWhileLoop tree)
    
public  voidvisitForLoop(JCForLoop tree)
    
public  voidvisitForeachLoop(JCEnhancedForLoop tree)
    
public  voidvisitIdent(JCIdent tree)
    
public  voidvisitIf(JCIf tree)
    
public  voidvisitLabelled(JCLabeledStatement tree)
    
public  voidvisitMethodDef(JCMethodDecl tree)
    
public  voidvisitNewArray(JCNewArray tree)
    
public  voidvisitNewClass(JCNewClass tree)
    
public  voidvisitReturn(JCReturn tree)
    
public  voidvisitSwitch(JCSwitch tree)
    
public  voidvisitThrow(JCThrow tree)
    
public  voidvisitTopLevel(JCCompilationUnit tree)
    
public  voidvisitTry(JCTry tree)
    
public  voidvisitTypeCast(JCTypeCast tree)
    
public  voidvisitUnary(JCUnary tree)
    
public  voidvisitVarDef(JCVariableDecl tree)
    
public  voidvisitWhileLoop(JCWhileLoop tree)
    

Field Detail
caught
List<Type> caught(Code)
The list of exceptions that are either caught or declared to be thrown.



classDef
JCClassDecl classDef(Code)
The current class being defined.



firstadr
int firstadr(Code)
The first variable sequence number in this class definition.



flowKey
final protected static Context.Key<Flow> flowKey(Code)



inits
Bits inits(Code)
The set of definitely assigned variables.



initsWhenFalse
Bits initsWhenFalse(Code)



initsWhenTrue
Bits initsWhenTrue(Code)
When analyzing a condition, inits and uninits are null. Instead we have:



loopPassTwo
boolean loopPassTwo(Code)
Set when processing a loop body the second time for DU analysis.



nextadr
int nextadr(Code)
The next available variable sequence number.



pendingExits
ListBuffer<PendingExit> pendingExits(Code)
The currently pending exits that go from current inner blocks to an enclosing block, in source order.



thrown
List<Type> thrown(Code)
The list of possibly thrown declarable exceptions.



uninits
Bits uninits(Code)
The set of definitely unassigned variables.



uninitsTry
Bits uninitsTry(Code)
The set of variables that are definitely unassigned everywhere in current try block. This variable is maintained lazily; it is updated only when something gets removed from uninits, typically by being assigned in reachable code. To obtain the correct set of variables which are definitely unassigned anywhere in current try block, intersect uninitsTry and uninits.



uninitsWhenFalse
Bits uninitsWhenFalse(Code)



uninitsWhenTrue
Bits uninitsWhenTrue(Code)



vars
VarSymbol[] vars(Code)
A mapping from addresses to variable symbols.




Constructor Detail
Flow
protected Flow(Context context)(Code)




Method Detail
analyzeTree
public void analyzeTree(JCTree tree, TreeMaker make)(Code)
Perform definite assignment/unassignment analysis on a tree.



checkInit
void checkInit(DiagnosticPosition pos, VarSymbol sym)(Code)
Check that trackable variable is initialized.



errorUncaught
void errorUncaught()(Code)
Complain that pending exceptions are not caught.



instance
public static Flow instance(Context context)(Code)



letInit
void letInit(DiagnosticPosition pos, VarSymbol sym)(Code)
Record an initialization of a trackable variable.



letInit
void letInit(JCTree tree)(Code)
If tree is either a simple name or of the form this.name or C.this.name, and tree represents a trackable variable, record an initialization of the variable.



markDead
void markDead()(Code)
Record that statement is unreachable.



markThrown
void markThrown(JCTree tree, Type exc)(Code)
Record that exception is potentially thrown and check that it is caught.



merge
void merge()(Code)
Merge (intersect) inits/uninits from WhenTrue/WhenFalse sets.



newVar
void newVar(VarSymbol sym)(Code)
Initialize new trackable variable by setting its address field to the next available sequence number and entering it under that index into the vars array.



recordExit
void recordExit(JCTree tree)(Code)
Record an outward transfer of control.



resolveBreaks
boolean resolveBreaks(JCTree tree, ListBuffer<PendingExit> oldPendingExits)(Code)
Resolve all breaks of this statement.



resolveContinues
boolean resolveContinues(JCTree tree)(Code)
Resolve all continues of this statement.



scanCond
void scanCond(JCTree tree)(Code)
Analyze a condition. Make sure to set (un)initsWhenTrue(WhenFalse) rather than (un)inits on exit.



scanDef
void scanDef(JCTree tree)(Code)
Analyze a definition.



scanExpr
void scanExpr(JCTree tree)(Code)
Analyze an expression. Make sure to set (un)inits rather than (un)initsWhenTrue(WhenFalse) on exit.



scanExprs
void scanExprs(List<? extends JCExpression> trees)(Code)
Analyze a list of expressions.



scanStat
void scanStat(JCTree tree)(Code)
Analyze a statement. Check that statement is reachable.



scanStats
void scanStats(List<? extends JCStatement> trees)(Code)
Analyze list of statements.



split
void split()(Code)
Split (duplicate) inits/uninits into WhenTrue/WhenFalse sets



trackable
boolean trackable(VarSymbol sym)(Code)
Do we need to track init/uninit state of this symbol? I.e. is symbol either a local or a blank final variable?



visitApply
public void visitApply(JCMethodInvocation tree)(Code)



visitAssert
public void visitAssert(JCAssert tree)(Code)



visitAssign
public void visitAssign(JCAssign tree)(Code)



visitAssignop
public void visitAssignop(JCAssignOp tree)(Code)



visitBinary
public void visitBinary(JCBinary tree)(Code)



visitBlock
public void visitBlock(JCBlock tree)(Code)



visitBreak
public void visitBreak(JCBreak tree)(Code)



visitClassDef
public void visitClassDef(JCClassDecl tree)(Code)



visitConditional
public void visitConditional(JCConditional tree)(Code)



visitContinue
public void visitContinue(JCContinue tree)(Code)



visitDoLoop
public void visitDoLoop(JCDoWhileLoop tree)(Code)



visitForLoop
public void visitForLoop(JCForLoop tree)(Code)



visitForeachLoop
public void visitForeachLoop(JCEnhancedForLoop tree)(Code)



visitIdent
public void visitIdent(JCIdent tree)(Code)



visitIf
public void visitIf(JCIf tree)(Code)



visitLabelled
public void visitLabelled(JCLabeledStatement tree)(Code)



visitMethodDef
public void visitMethodDef(JCMethodDecl tree)(Code)



visitNewArray
public void visitNewArray(JCNewArray tree)(Code)



visitNewClass
public void visitNewClass(JCNewClass tree)(Code)



visitReturn
public void visitReturn(JCReturn tree)(Code)



visitSwitch
public void visitSwitch(JCSwitch tree)(Code)



visitThrow
public void visitThrow(JCThrow tree)(Code)



visitTopLevel
public void visitTopLevel(JCCompilationUnit tree)(Code)



visitTry
public void visitTry(JCTry tree)(Code)



visitTypeCast
public void visitTypeCast(JCTypeCast tree)(Code)



visitUnary
public void visitUnary(JCUnary tree)(Code)



visitVarDef
public void visitVarDef(JCVariableDecl tree)(Code)



visitWhileLoop
public void visitWhileLoop(JCWhileLoop tree)(Code)



Methods inherited from com.sun.tools.javac.tree.TreeScanner
public void scan(JCTree tree)(Code)(Java Doc)
public void scan(List<? extends JCTree> trees)(Code)(Java Doc)
public void visitAnnotation(JCAnnotation tree)(Code)(Java Doc)
public void visitApply(JCMethodInvocation tree)(Code)(Java Doc)
public void visitAssert(JCAssert tree)(Code)(Java Doc)
public void visitAssign(JCAssign tree)(Code)(Java Doc)
public void visitAssignop(JCAssignOp tree)(Code)(Java Doc)
public void visitBinary(JCBinary tree)(Code)(Java Doc)
public void visitBlock(JCBlock tree)(Code)(Java Doc)
public void visitBreak(JCBreak tree)(Code)(Java Doc)
public void visitCase(JCCase tree)(Code)(Java Doc)
public void visitCatch(JCCatch tree)(Code)(Java Doc)
public void visitClassDef(JCClassDecl tree)(Code)(Java Doc)
public void visitConditional(JCConditional tree)(Code)(Java Doc)
public void visitContinue(JCContinue tree)(Code)(Java Doc)
public void visitDoLoop(JCDoWhileLoop tree)(Code)(Java Doc)
public void visitErroneous(JCErroneous tree)(Code)(Java Doc)
public void visitExec(JCExpressionStatement tree)(Code)(Java Doc)
public void visitForLoop(JCForLoop tree)(Code)(Java Doc)
public void visitForeachLoop(JCEnhancedForLoop tree)(Code)(Java Doc)
public void visitIdent(JCIdent tree)(Code)(Java Doc)
public void visitIf(JCIf tree)(Code)(Java Doc)
public void visitImport(JCImport tree)(Code)(Java Doc)
public void visitIndexed(JCArrayAccess tree)(Code)(Java Doc)
public void visitLabelled(JCLabeledStatement tree)(Code)(Java Doc)
public void visitLetExpr(LetExpr tree)(Code)(Java Doc)
public void visitLiteral(JCLiteral tree)(Code)(Java Doc)
public void visitMethodDef(JCMethodDecl tree)(Code)(Java Doc)
public void visitModifiers(JCModifiers tree)(Code)(Java Doc)
public void visitNewArray(JCNewArray tree)(Code)(Java Doc)
public void visitNewClass(JCNewClass tree)(Code)(Java Doc)
public void visitParens(JCParens tree)(Code)(Java Doc)
public void visitReturn(JCReturn tree)(Code)(Java Doc)
public void visitSelect(JCFieldAccess tree)(Code)(Java Doc)
public void visitSkip(JCSkip tree)(Code)(Java Doc)
public void visitSwitch(JCSwitch tree)(Code)(Java Doc)
public void visitSynchronized(JCSynchronized tree)(Code)(Java Doc)
public void visitThrow(JCThrow tree)(Code)(Java Doc)
public void visitTopLevel(JCCompilationUnit tree)(Code)(Java Doc)
public void visitTree(JCTree tree)(Code)(Java Doc)
public void visitTry(JCTry tree)(Code)(Java Doc)
public void visitTypeApply(JCTypeApply tree)(Code)(Java Doc)
public void visitTypeArray(JCArrayTypeTree tree)(Code)(Java Doc)
public void visitTypeBoundKind(TypeBoundKind that)(Code)(Java Doc)
public void visitTypeCast(JCTypeCast tree)(Code)(Java Doc)
public void visitTypeIdent(JCPrimitiveTypeTree tree)(Code)(Java Doc)
public void visitTypeParameter(JCTypeParameter tree)(Code)(Java Doc)
public void visitTypeTest(JCInstanceOf tree)(Code)(Java Doc)
public void visitUnary(JCUnary tree)(Code)(Java Doc)
public void visitVarDef(JCVariableDecl tree)(Code)(Java Doc)
public void visitWhileLoop(JCWhileLoop tree)(Code)(Java Doc)
public void visitWildcard(JCWildcard tree)(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.