Download - CS3215 – Software Engineering Project
-
8/14/2019 CS3215 Software Engineering Project
1/40
CS3215 Software
Engineering Project Team 8 Static Program Analyzer
-
8/14/2019 CS3215 Software Engineering Project
2/40
Presentation Purpose
To highlight USP s of Team8s SPATo show how unique we are and why we chose tobe so
The Missing Piece to our Final ReportFew ideas could have been overlooked.Also provides clearer explanation to topicscovered briefly
An Addendum to the ReportClearer understanding of our ideas, project
-
8/14/2019 CS3215 Software Engineering Project
3/40
Presentation Overall Achievements
All Project Requirements have been met.Modifies, Uses and Calls Data Structures in thePKBParent, Follows, Next, Affects On Demand
Clear and Efficient QES.Optimizations both from PKB and PQL.Flexible and Extensible SPA
-
8/14/2019 CS3215 Software Engineering Project
4/40
Presentation - Agenda
Team PKB (First Half)ParserPKB DesignPKB API - The Narrow Passage Approach
PKB Optimization
Team PQL (Second Half)Query Processor
Query Evaluation StrategyQuery Optimization Principles
-
8/14/2019 CS3215 Software Engineering Project
5/40
-
8/14/2019 CS3215 Software Engineering Project
6/40
The Parser Exceptions
Exceptions reported Token MismatchReports found and expected tokens and the line number
Invalid Variable NameEmpty Program or Empty Statement ListProcedure calling itself ( Direct Recursion )Called procedure is not foundMultiple procedures having the same identifier ( name )
Exceptions API is used consistently
-
8/14/2019 CS3215 Software Engineering Project
7/40
The Parser Exception Class
Generic , global classInherited classes used both in the Parser and theQuery Pre-processorException: One of the minor reusable components
of our SPA
-
8/14/2019 CS3215 Software Engineering Project
8/40
PKB Overview (1/3)
Crucial-Entity Tables
Relationship Tables Cache Table
Var Table
Proc Table
Stmt Table Mod Table Uses Table Calls Table
Stmt Table API
Proc Table API
Var TableAPI
ModifiesAPI
Uses API Calls API
-
8/14/2019 CS3215 Software Engineering Project
9/40
PKB Overview (2/3)
Abstract Syntax Tree
Control FlowGraph
Parent API
Follows API
AST APICFG API
Next API Affects API
-
8/14/2019 CS3215 Software Engineering Project
10/40
PKB Overview (3/3)
Crucial Entities Ec
is a subset of all entities Eall
(from
the Entity Table )Conditions:
One of the arguments for any of the relationships in theRelationships TableCannot be a derivative of another E c. Eg. StmtList is a Statement
Design FocusSpeed - Data structures must enable quick data retrieval
thereby aiding in the speed of the query in a small wayExtensibility
Design Choice Hash Maps
-
8/14/2019 CS3215 Software Engineering Project
11/40
PKB Variable Table (1/3)Two dimensional Hash
Index points to variable and variable points to a structure that includes indexA KeyMapper keeps track of the keysSpeed is guaranteed
Data is handled by the Modifies, Uses (friends) and Variable Table APIs
Extensible Can be easily extended to handle new relationships Take a look at the diagram (next slide)
Procedure Table is quite similar except for Calls .
-
8/14/2019 CS3215 Software Engineering Project
12/40
PKB Variable Table (2/3)Variable
Name
Variable Vector
Index Stmts_used Stmt_modfd Proc_used Proc_modfd
x 0 4, 5, 7, 8, 9 4, 5, 14, 15, 18 P, Q Example, P
y 1 17, 18, 19 - R -
z 2 - 4, 5, 7, 8, 9 - P
i 3 24, 25 4, 5, 7, 8, 9 P R, Q
-
8/14/2019 CS3215 Software Engineering Project
13/40
PKB Variable Table (3/3)Variable Table = Hash_Map( Variable Name, Variable Vector )Extensibility Assume new relationship Coexist (variable, variable)So, there is a relationship R such that entity variable is one of the arguments.
Two new columns need to be added to the Variable Table.variable_ coexisting , variable_ coexisted
Generic View: < entity_ relationship >Structure accommodates change Extensible design
-
8/14/2019 CS3215 Software Engineering Project
14/40
PKB ModifiesTable (1/3)Hash Map with a Vector Key
Key is a vector of two values (variable being modified and identifier of theentity modifying the variable ( From the entity table )Speed is guaranteed
Key is mapped to a Boolean Vector.
Conserves Space. Each element = 1 bit only.
Extensible Can be easily extended to handle new entities Take a look at the diagram (next slide)
UsesTable, Calls Table are quite similar
-
8/14/2019 CS3215 Software Engineering Project
15/40
PKB Modifies Table (2/3)Modifies Key Modifies Vector
VarName Modifier_ID Boolean Vector
x 1 110
x 3 111101010110101010101000000
y1 001
y 3 0000000000000000000000100
Taken from EntityTable,
1 = Procedure, 3 =Stmt
Varname Taken from Variable Table
ith bit here corresponds to whether the ith statementmodifies variable x or not
-
8/14/2019 CS3215 Software Engineering Project
16/40
PKB ModifiesTable (3/3)Modifies Table = Hash_Map ( Modifies Key , Modifies Vector )Extensibility Assume new entity Function such that Modifies is extended toinclude Modifies( Function, variable )Modifies Table neither be changed nor a new Modifies Table
be createdStructure accommodates change Extensible design
-
8/14/2019 CS3215 Software Engineering Project
17/40
PKB API The Narrow Passage Approach (1/3)
PKB API methods are covered by a wrapper interfaceQuery Processor Access
Restricted to the Entity Table, Relationship Table and the wrapperinterface Narrow Passage
InterfacerelationshipHandler(relationship, arguments)withHandler( arguments)patternHandler( arguments, pattern)
Design - Can be detached and added to the Evaluator
-
8/14/2019 CS3215 Software Engineering Project
18/40
PKB API The Narrow Passage Approach (2/3)
Query Processor independent of the PKB subcomponents.Useful Scenario: Data structures are added. API widens.Query Processor needs to change if not for this approach.With NPA, PKB adjusts or accommodates itself Query Processor just looks at the change in the Relationship Table
Minimizing PKBs public API methods Taking burden off the Evaluator
Easier to cache relationship calls in the PKB.Covered under PKBs Cache Table.
-
8/14/2019 CS3215 Software Engineering Project
19/40
PKB API The Narrow Passage Approach (3/3)
relationshipHandler(relationship, arguments)
Ex . relationshipHandler( 2 , { { 1 , 12 }, { v, 11 } })Its a call to the Modifies relationship witharguments, a constant with a value 1 and a non-constant variableModifies(1,v)
Relationship indexfrom the Relationship
table
An argument has anentity from the Entity
Table and a value
-
8/14/2019 CS3215 Software Engineering Project
20/40
PKB Optimization Cache Table (1/4) Traditional view of PKB Static Knowledge BaseCache Missing Dynamic Knowledge ComponentDynamic Knowledge
Derived Knowledge or Learn from Experience principle
Alternative to storing the Follows, Parent, Affects andNext relationship calls in the PKB in separate datastructures. ( Why? )Caching is done in the relationshipHandler() interfacemethod.
Controlled by Global Parameters (constants)
-
8/14/2019 CS3215 Software Engineering Project
21/40
PKB Optimization Cache Table (2/4)Eliminating computation on demand
By pre-computing and storing all design abstractions in the PKBNot elegant Space Doesnt work out in the real world!
Time Quite high for Affects*Extensible Difficult to extend when RelTable increases in sizeIs it worth it?No
Fails when Q is a small for a program size of large N
-
8/14/2019 CS3215 Software Engineering Project
22/40
PKB Optimization Cache Table (3/4)Pre-computation time and PKB space depend of the program size
S, T is proportional to N
Fails as Pre-computation time and PKB space depend of the program sizeand number of queries, QS, T is proportional to Q, N
Our Cache Table introduces the Q factor for design abstractions computed ondemand Dont pre-compute, store when calculated
-
8/14/2019 CS3215 Software Engineering Project
23/40
PKB Optimization Cache Table (4/4)Global Parameters
CACHE, 0 or 1CACHE_MAX_QUERIES, 0 to maxMIN_CALLS_CACHE_OPEN, 0 to maxExtremely useful when the User knows the number of queries that will be entered in aparticular Querier session. (Which is the case mostly )
Cache miss doesnt cost much as the Cache table is also a hash map.Cache Table = Hash_map( QueryObj, QueryResult );
We call it Query but itrefers to the relationship
call object and relationshipcall result.
-
8/14/2019 CS3215 Software Engineering Project
24/40
-
8/14/2019 CS3215 Software Engineering Project
25/40
Entity TableIndex Name Attribute Type Values
0 program progName name1 procedure procName name P, Q, Example
2 stmtList
3 stmt stmt# integer 1, 2, 3 25
4 assign stmt# integer 2, 4, 5, 5 call stmt# integer 4, 3
6 while stmt# integer 6, 9
7 if stmt# integer 10
8, 9, 10 plus, minus,times
11 variable varName name x, y, z, i
12 constant value value13 program line stmt# integer 1, 2, 3 25
Program lines in which allinstances of the entity are
found
-
8/14/2019 CS3215 Software Engineering Project
26/40
Relationship TableIndex Name Arguments Type1 Type2 Entity1 Entity2
0 Calls 2 name name 1 1
1 Calls* 2 name name 1 12 Modifies 2 both name 1, 3, 4, 5, 6, 7,
1311
3 Uses 2 both name1, 3, 4, 5, 6, 7,
1311
4 Parent 2 integer integer 3, 6, 7, 13 3, 4, 5, 6, 7, 13
5 Parent* 2 integer integer 3, 6, 7, 13 3, 4, 5, 6, 7, 13
6 Follows 2 integer integer 3, 4, 5, 6, 7, 13 3, 4, 5, 6, 7, 13
7 Follows* 2 integer integer 3, 4, 5, 6, 7, 13 3, 4, 5, 6, 7, 13
8 Next 2 integer integer 3, 4, 5, 6, 7, 13 3, 4, 5, 6, 7, 13
Number of fields under Type, Entityvaries with the number of arguments
-
8/14/2019 CS3215 Software Engineering Project
27/40
Query Evaluation Strategy - InterfaceMethods
getValues(Entity) from Entity TablerelationshipHandler(Name, Arg1, Arg2)patternHandler(Arg1, Arg2)withHandler(Arg1, Arg2)
-
8/14/2019 CS3215 Software Engineering Project
28/40
Query Evaluation Strategy
Assume Select variables in the form Select)Step 1: getValues(), all values of s 1, s 2, , s n.Step 2: patternHandler() and withHandler(),filter Select values.Step 3: Form combinations of output results.[e.g. s 1={4,5}, s 2={6,7}. will form {46, 4 7, 5 6, 5 7}.]
-
8/14/2019 CS3215 Software Engineering Project
29/40
Query Evaluation Strategy
Store non-Select values in memory to aid infinding Select values as query answer.E.g. program line n; assign a; Select a suchthat Next*(13, n) and Affects*(a, n)
relationshipHandler() to find and store valuesof n into memory, then userelationshipHandler() to find values of a, givenn.
-
8/14/2019 CS3215 Software Engineering Project
30/40
Query Evaluation Strategy
Constants: 2, 3, 5, Example, xNon-constants: declaration variables and _
Step 4: For each Relationship clause,Case 1: [Relationship](constant, constant)Case 2: [Relationship](constant, non-constant)Case 3: [Relationship](non-constant, constant)Case 4: [Relationship](non-constant, non-constant)
-
8/14/2019 CS3215 Software Engineering Project
31/40
Query Evaluation Strategy
Case 1
Case 2 and 3,a) Non-constant is placeholder.
b) Non-constant is in Select values.c) Non-constant is not in Select values.
-
8/14/2019 CS3215 Software Engineering Project
32/40
Query Evaluation Strategy
Case 4,a) Both non-constant are the samei. Placeholderii. Select valuesiii. Non-Select values
b) Both non-constant are differenti. Placeholder in either argumentii. Both arguments in Select valuesiii. Select value in either argumentiv. Both arguments not in Select values
-
8/14/2019 CS3215 Software Engineering Project
33/40
Query Evaluation Strategy
Variables not in Select and Relationshipclauses, but are in With and Patternclauses.E.g. Stmt s, s1; Select s such that
Follows(2,s) with s1.stmt#=5
-
8/14/2019 CS3215 Software Engineering Project
34/40
Query Pre-ProcessorValidates queries
Transforms query string into query tree forefficiency of query optimization and evaluation
-
8/14/2019 CS3215 Software Engineering Project
35/40
Example Query
assign a, a1; stmt s, s1; Select suchthat Follows(a, s) and Next*(a1, s1) withs.stmt# = 1 pattern a(_, _x+z_)
-
8/14/2019 CS3215 Software Engineering Project
36/40
Query Validation
Rules for PQL:Grammar table using static regular expressionsRules for relationships and entities stored in statictables, e.g. RelTable, EntTableRules are not hardcoded
-
8/14/2019 CS3215 Software Engineering Project
37/40
Query ValidationCheck full syntax of queryAll variable synonyms are checked againstdeclared variable mapRelationships are checked for correct number
of arguments, correct type of arguments, andnon-ambiguityAttribute references must correspond to thoseof variable synonyms
-
8/14/2019 CS3215 Software Engineering Project
38/40
Query ParsingRegex expressions in grammar table are usedto extract parts of queryParsing is recursive, similar to parsing of SIMPLE source code
As parsing is done, query tree is built
-
8/14/2019 CS3215 Software Engineering Project
39/40
PQL OptimizationBasic strategy
Reordering relationships for optimal linearevaluation of relationships from left to rightLeft: Most restrictiveRight: Least restrictivePriority given to joins between relationshipscompared to crosses between relationships
-
8/14/2019 CS3215 Software Engineering Project
40/40
PQL OptimizationOrder by relationship types
Follows vs. AffectsOrder by number of occurrences forrelationship argument types
Follows*(a1, a2) vs. Follows*(a1, s1)Order by combinations of variables andconstants as relationship arguments
Modifies(First, x) vs. Modifies(p, v)
Order by number of output variables withrelationship arguments
Select ; Follows(a1, s1) vs. Follows(a, s)