SlideShare a Scribd company logo
Software Analysis and
Testing
SEC5261
Week 08
Murtaza Munawar Fazal
Pointer Analysis
[x == 1]
Introducing Pointers
x = 1;
y = x;
assert(y == 1)
x = new Circle();
x.radius = 1;
y = x.radius;
assert(y == 1)
Example without pointers
[y == 1]
Same example with pointers
[x == 1]
Introducing Pointers
x = 1;
y = x;
assert(y == 1)
x = new Circle();
x.radius = 1;
y = x.radius;
assert(y == 1)
Example without pointers
[y == 1]
Same example with pointers
[y == 1]
[x.radius == 1]
Pointer Aliasing
• Situation in which same address referred to in different ways
Circle x = new Circle();
Circle z = ?
x.radius = 1;
z.radius = 2;
y = x.radius;
assert(y == 1)
x = new Circle();
x.radius = 1;
y = x.radius;
assert(y == 1)
[x.radius == 1]
[x.radius == ?]
[x.radius == 1]
[y == 1]
May-Alias Analysis
Circle x = new Circle();
Circle z = new Circle();
x.radius = 1;
z.radius = 2;
y = x.radius;
assert(y == 1)
May-Alias Analysis == Pointer Analysis
[x.radius == 1, x != z]
[x.radius == 1]
[y == 1]
[x != z]
Circle x = new Circle();
Circle z = x;
x.radius = 1;
z.radius = 2;
y = x.radius;
assert(y == 1)
Must-Alias Analysis
• May-Alias and Must-Alias are dual problems
• Must-Alias more advanced, less useful in practice
• Focus of this Lesson: May-Alias Analysis
[x.radius == 2]
[y == 2]
[x.radius == 1, x == z]
[x == z]
y == 2
h.data
h.next.prev.data
h.next.next.prev.prev.data
h.next.prev.next.prev.data
And many more ...
Why Is Pointer Analysis Hard?
class Node {
int data;
Node next, prev;
}
Node h = null;
for (...) {
Node v = new Node();
if (h != null) {
v.next = h;
h.prev = v;
}
h = v;
}
n1 n2
next
n3
prev
next
prev
h
Approximation to the Rescue
•Pointer analysis problem is undecidable
=> We must sacrifice some combination of:
Soundness, Completeness, Termination
•We are going to sacrifice completeness
=> False positives but no false negatives
What False Positives Mean
Circle x = new Circle();
Circle z = new Circle();
x.radius = 1;
z.radius = 2;
y = x.radius;
assert(y == 1)
Pointer analysis answers questions of form: MayAlias(x, z)?
No => x and z are not aliased in any run
Yes => Can’t tell if x and z are aliased in some run
[x.radius == 1, x == z or x != z]
No Yes
[x == z or x != z]
[x.radius == 1 or x.radius == 2]
[y == 1 or y == 2]
False Positive!
[x.radius == 1, x != z]
[x.radius == 1]
[y == 1]
[x != z]
Approximation to the Rescue
•Many sound approximate algorithms for pointer analysis
•Varying levels of precision
•Differ in two key aspects:
• How to abstract the heap (i.e. dynamically allocated data)
• How to abstract control-flow
Example Java Program
void doit(int M, int N) {
Elevator v = new Elevator();
v.floors = new Object[M];
v.events = new Object[N];
for (int i = 0; i < M; i++) {
Floor f = new Floor();
v.floors[i] = f;
}
for (int i = 0; i < N; i++) {
Event e = new Event();
v.events[i] = e;
}
}
class Elevator {
Object[] floors;
Object[] events;
}
A Run of the Program
void doit(int M, int N) {
Elevator v = new Elevator();
v.floors = new Object[M];
v.events = new Object[N];
for (int i = 0; i < M; i++) {
Floor f = new Floor();
v.floors[i] = f;
}
for (int i = 0; i < N; i++) {
Event e = new Event();
v.events[i] = e;
}
}
doit(3, 2) v
Abstracting the Heap
void doit(int M, int N) {
Elevator v = new Elevator();
v.floors = new Object[M];
v.events = new Object[N];
for (int i = 0; i < M; i++) {
Floor f = new Floor();
v.floors[i] = f;
}
for (int i = 0; i < N; i++) {
Event e = new Event();
v.events[i] = e;
}
}
v
Result of Heap Abstraction: Points-to Graph
Elevator
v
Object[] Object[]
Floor Event
f e
floors
[*] [*]
event
s
v
Abstracting Control-Flow
void doit(int M, int N) {
Elevator v = new Elevator();
v.floors = new Object[M];
v.events = new Object[N];
for (int i = 0; i < M; i++) {
Floor f = new Floor();
v.floors[i] = f;
}
for (int i = 0; i < N; i++) {
Event e = new Event();
v.events[i] = e;
}
}
Elevator
v
Object[
]
Object[
]
Floor Event
f e
floors
[*] [*]
events
Flow Insensitivity
void doit(int M, int N) {
Elevator v = new Elevator();
v.floors = new Object[M];
v.events = new Object[N];
for (int i = 0; i < M; i++) {
Floor f = new Floor();
v.floors[i] = f;
}
for (int i = 0; i < N; i++) {
Event e = new Event();
v.events[i] = e;
}
}
void doit(int M, int N) {
v = new Elevator
v.floors = new Object[]
v.events = new Object[]
f = new Floor
v.floors[*] = f
e = new Event
v.events[*] = e
}
- Notice that all control-flow features have been removed, including constructs like for-loops and also semicolons indicating sequentially
ordered statements.
- All statements that do not affect pointers have also been removed. For example, the approximated code no longer has statements
setting the integer i equal to 0 and incrementing i.
- Finally, array indices are replaced by nondeterministic choice, denoted by the asterisk symbol. This is similar to how conditions at
branch points in dataflow analysis were replaced by nondeterministic choice.
Chaotic Iteration Algorithm
graph = empty
repeat:
for (each statement s in set)
apply rule corresponding to s on graph
until graph stops changing
Kinds of Statements
(statement) s ::= v = new … | v = v2 | v2 = v.f |
v.f = v2 | v2 = v[*] | v[*] = v2
(pointer-type variable) v
(pointer-type field) f
Is This Grammar Enough?
v.events = new Object[]
tmp = new Object[]
v.events = tmp
v.events[*] = e
tmp = v.events
tmp[*] = e
v = new … | v = v2 | v2 = v.f |
v.f = v2 | v2 = v[*] | v[*] = v2
Example Program in Normal Form
void doit(int M, int N) {
v = new Elevator
v.floors = new Object[]
v.events = new Object[]
f = new Floor
v.floors[*] = f
e = new Event
v.events[*] = e
}
void doit(int M, int N) {
v = new Elevator
tmp1 = new Object[]
v.floors = tmp1
tmp2 = new Object[]
v.events = tmp2
f = new Floor
tmp3 = v.floors
tmp3[*] = f
e = new Event
tmp4 = v.events
tmp4[*] = e
}
Normal Form of Programs
v1.f.g = v2.h
v1.f = v2.f
v = new … | v = v2 | v2 = v.f |
v.f = v2 | v2 = v[*] | v[*] = v2
Convert each of these two expressions to normal form:
Normal Form of Programs
v1.f.g = v2.h
v1.f = v2.f
tmp1 = v1.f
tmp2 = v2.h
tmp1.g = tmp2
tmp = v2.f
v1.f = tmp
v = new … | v = v2 | v2 = v.f |
v.f = v2 | v2 = v[*] | v[*] = v2
Convert each of these two expressions to normal form:
Rule for Object Allocation Sites
v = new B
After:
v
Before:
v
A
A
B
Rule for Object Allocation Sites: Example
void doit(int M, int N) {
v = new Elevator
tmp1 = new Object[]
v.floors = tmp1
tmp2 = new Object[]
v.events = tmp2
f = new Floor
tmp3 = v.floors
tmp3[*] = f
e = new Event
tmp4 = v.events
tmp4[*] = e
}
Elevator
v
Object[] Object[]
Floor Event
f e
tmp
1
tmp
2
Rule for Object Copy
v1 = v2
A
v1 v2
v1 v2 B
After:
Before:
A
B
B
Rule for Field Writes
f or [*]
After:
Before:
v1 . f = v2
v1[*] = v2
v1 A v2 B A C
v1 v2 B A
C
or
f or [*]
f or [*]
A
B
Rule for Field Writes: Example
void doit(int M, int N) {
v = new Elevator
tmp1 = new Object[]
v.floors = tmp1
tmp2 = new Object[]
v.events = tmp2
f = new Floor
tmp3 = v.floors
tmp3[*] = f
e = new Event
tmp4 = v.events
tmp4[*] = e
}
Elevato
r
v
Object[
]
Object[
]
Floor Event
f e
floors
event
s
tmp
1
tmp
2
Rule for Field Reads
A v2 B B C
v2 B B C
After:
Before:
C
A
v1 = v2.f
v1 = v2[*]
or
f or [*]
f or [*]
v1
v1
Rule for Field Reads: Example
void doit(int M, int N) {
v = new Elevator
tmp1 = new Object[]
v.floors = tmp1
tmp2 = new Object[]
v.events = tmp2
f = new Floor
tmp3 = v.floors
tmp3[*] = f
e = new Event
tmp4 = v.events
tmp4[*] = e
}
Elevato
r
v
Object[
]
Object[
]
Floor Event
f e
floors
event
s
tmp
1
tmp
2
tmp
3
tmp
4
Continuing the Pointer Analysis: Example
Elevato
r
v
Object[
]
Object[
]
Floor Event
f e
floors
event
s
tmp
1
tmp
2
tmp
3
tmp
4
[*] [*]
void doit(int M, int N) {
v = new Elevator
tmp1 = new Object[]
v.floors = tmp1
tmp2 = new Object[]
v.events = tmp2
f = new Floor
tmp3 = v.floors
tmp3[*] = f
e = new Event
tmp4 = v.events
tmp4[*] = e
}
class Node {
int data;
Node next, prev;
}
Node h = null;
for (...) {
Node v = new Node();
if (h != null) {
v.next = h;
h.prev = v;
}
h = v;
}
Pointer Analysis Example
Choose the points-to graph for
the shown program.
Node
h
nex
t
pre
v
v
Node
h
nex
t
pre
v
v
Node
h
nex
t
pre
v
v Node
h
nex
t
pre
v
v
Pointer Analysis Example
Node
h
next
prev
v
class Node {
int data;
Node next, prev;
}
Node h = null;
for (...) {
Node v = new Node();
if (h != null) {
v.next = h;
h.prev = v;
}
h = v;
}
Classifying Pointer Analysis Algorithms
•Is it flow-sensitive?
•Is it context-sensitive?
•What heap abstraction scheme is used?
•How are aggregate data types modeled?
Flow Sensitivity
•How to model control-flow within a procedure
•Two kinds: flow-insensitive vs. flow-sensitive
•Flow-insensitive == weak updates
• Suffices for may-alias analysis
•Flow-sensitive == strong updates
• Required for must-alias analysis
Context Sensitivity
• How to model control-flow across procedures
• Two kinds: context-insensitive vs. context-sensitive
• Context-insensitive: analyze each procedure once
• Context-sensitive: analyze each procedure possibly
multiple times, once per abstract calling context
Heap Abstraction
• Scheme to partition unbounded set of concrete
objects into finitely many abstract objects (oval
nodes in points-to graph)
• Ensures that pointer analysis terminates
• Many sound schemes, varying in precision & efficiency
• Too few abstract objects => efficient but imprecise
• Too many abstract objects => expensive but precise
Scheme #1: Allocation-Site Based
One abstract object per allocation site
Allocation site identified by:
• new keyword in Java/C++
• malloc() call in C
Finitely many allocation sites in a
program
=> finitely many abstract objects
Elevator
v
Object[] Object[]
Floor Event
f e
floors events
[*] [*]
Scheme #2: Type Based
• Allocation-site based scheme can be costly
- Large programs
- Clients needing quick turnaround time
- Overly fine granularity of sites
• One abstract object per type
• Finitely many types in a program
=> finitely many abstract objects
Elevator
v
Object[]
Floor Event
f e
[*] [*]
floors events
Scheme #3: Heap-Insensitive
Single abstract object representing entire heap
Popular for languages with primarily
stack-directed pointers (e.g. C)
Unsuitable for languages with only
heap-directed pointers (e.g. Java)
v
floors,
events,
[*]
f e
[*]
Tradeoffs in Heap Abstraction Schemes
More Efficient
More Precise
Allocation-site
based
Type based Heap-
insensitive
v
floors,
events,
[*]
f e
Elevator
v
Object[] Object[]
Floor Event
f e
floors events
[*]
Elevator
v
Object[]
Floor Event
f e
[*] [*]
floors events
Modeling Aggregate Data Types: Arrays
• Common choice: single field [*] to represent all array elements
• Cannot distinguish different elements of same array
• More sophisticated representations that make such distinctions are
employed by array dependence analyses
• Used to parallelize sequential loops by parallelizing compilers
Modeling Aggregate Data Types: Records
Three choices:
1. Field-insensitive: merge all fields of each
record object
2. Field-based: merge each field of all
record objects
3. Field-sensitive: keep each field of each
(abstract) record object separate
f1 f2
a1
a2
f1 f2
a1
a2
f1 f2
a1
a2
Pointer Analysis Classification
Classify the pointer analysis algorithm we learned
in this lesson.
Flow-sensitive?
Context-sensitive?
Distinguishes fields of object?
Distinguishes elements of array?
What kind of heap abstraction?
A. Yes B. No
A. Yes B. No
A. Yes B. No
A. Yes B. No
A. Allocation- B. Type
site based based
Pointer Analysis Classification
Flow-sensitive? B
Context-sensitive? B
Distinguishes fields of object? A
Distinguishes elements of array? B
What kind of heap abstraction? A
A. Yes B. No
A. Yes B. No
A. Allocation- B. Type
site based based
A. Yes B. No
A. Yes B. No
Classify the pointer analysis algorithm we learned
in this lesson.

More Related Content

Similar to SEC5261_SAT_Week08_Spring22.pdf

Scala Functional Patterns
Scala Functional PatternsScala Functional Patterns
Scala Functional Patterns
league
 
ECMAScript 6 major changes
ECMAScript 6 major changesECMAScript 6 major changes
ECMAScript 6 major changes
hayato
 
Principles of functional progrmming in scala
Principles of functional progrmming in scalaPrinciples of functional progrmming in scala
Principles of functional progrmming in scala
ehsoon
 
Fp in scala part 2
Fp in scala part 2Fp in scala part 2
Fp in scala part 2
Hang Zhao
 
Social network-analysis-in-python
Social network-analysis-in-pythonSocial network-analysis-in-python
Social network-analysis-in-python
Joe OntheRocks
 
Perspective in Informatics 3 - Assignment 1 - Answer Sheet
Perspective in Informatics 3 - Assignment 1 - Answer SheetPerspective in Informatics 3 - Assignment 1 - Answer Sheet
Perspective in Informatics 3 - Assignment 1 - Answer Sheet
Hoang Nguyen Phong
 
Python Programming Homework Help.pptx
Python Programming Homework Help.pptxPython Programming Homework Help.pptx
Python Programming Homework Help.pptx
Python Homework Help
 
chapter1.ppt
chapter1.pptchapter1.ppt
chapter1.ppt
chetanvchaudhari
 
chapter1.ppt
chapter1.pptchapter1.ppt
chapter1.ppt
SankarTerli
 
Create a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfCreate a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdf
arihantmobileselepun
 
b. (10 pts) Implement the rotate left method for AVL trees.c. (10 .pdf
b. (10 pts) Implement the rotate left method for AVL trees.c. (10 .pdfb. (10 pts) Implement the rotate left method for AVL trees.c. (10 .pdf
b. (10 pts) Implement the rotate left method for AVL trees.c. (10 .pdf
akanshanawal
 
Introduction to Neural Networks and Deep Learning from Scratch
Introduction to Neural Networks and Deep Learning from ScratchIntroduction to Neural Networks and Deep Learning from Scratch
Introduction to Neural Networks and Deep Learning from Scratch
Ahmed BESBES
 
Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]
Palak Sanghani
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
Abdullah Al-hazmy
 
Signals and Systems Homework Help.pptx
Signals and Systems Homework Help.pptxSignals and Systems Homework Help.pptx
Signals and Systems Homework Help.pptx
Matlab Assignment Experts
 
The Essence of the Iterator Pattern (pdf)
The Essence of the Iterator Pattern (pdf)The Essence of the Iterator Pattern (pdf)
The Essence of the Iterator Pattern (pdf)
Eric Torreborre
 
Cs580
Cs580Cs580
Csci101 lect09 vectorized_code
Csci101 lect09 vectorized_codeCsci101 lect09 vectorized_code
Csci101 lect09 vectorized_code
Elsayed Hemayed
 
Frequency Response with MATLAB Examples.pdf
Frequency Response with MATLAB Examples.pdfFrequency Response with MATLAB Examples.pdf
Frequency Response with MATLAB Examples.pdf
Sunil Manjani
 
Functional and reactive u is gwt.create 2015
Functional and reactive u is gwt.create 2015Functional and reactive u is gwt.create 2015
Functional and reactive u is gwt.create 2015
hezamu
 

Similar to SEC5261_SAT_Week08_Spring22.pdf (20)

Scala Functional Patterns
Scala Functional PatternsScala Functional Patterns
Scala Functional Patterns
 
ECMAScript 6 major changes
ECMAScript 6 major changesECMAScript 6 major changes
ECMAScript 6 major changes
 
Principles of functional progrmming in scala
Principles of functional progrmming in scalaPrinciples of functional progrmming in scala
Principles of functional progrmming in scala
 
Fp in scala part 2
Fp in scala part 2Fp in scala part 2
Fp in scala part 2
 
Social network-analysis-in-python
Social network-analysis-in-pythonSocial network-analysis-in-python
Social network-analysis-in-python
 
Perspective in Informatics 3 - Assignment 1 - Answer Sheet
Perspective in Informatics 3 - Assignment 1 - Answer SheetPerspective in Informatics 3 - Assignment 1 - Answer Sheet
Perspective in Informatics 3 - Assignment 1 - Answer Sheet
 
Python Programming Homework Help.pptx
Python Programming Homework Help.pptxPython Programming Homework Help.pptx
Python Programming Homework Help.pptx
 
chapter1.ppt
chapter1.pptchapter1.ppt
chapter1.ppt
 
chapter1.ppt
chapter1.pptchapter1.ppt
chapter1.ppt
 
Create a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfCreate a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdf
 
b. (10 pts) Implement the rotate left method for AVL trees.c. (10 .pdf
b. (10 pts) Implement the rotate left method for AVL trees.c. (10 .pdfb. (10 pts) Implement the rotate left method for AVL trees.c. (10 .pdf
b. (10 pts) Implement the rotate left method for AVL trees.c. (10 .pdf
 
Introduction to Neural Networks and Deep Learning from Scratch
Introduction to Neural Networks and Deep Learning from ScratchIntroduction to Neural Networks and Deep Learning from Scratch
Introduction to Neural Networks and Deep Learning from Scratch
 
Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
 
Signals and Systems Homework Help.pptx
Signals and Systems Homework Help.pptxSignals and Systems Homework Help.pptx
Signals and Systems Homework Help.pptx
 
The Essence of the Iterator Pattern (pdf)
The Essence of the Iterator Pattern (pdf)The Essence of the Iterator Pattern (pdf)
The Essence of the Iterator Pattern (pdf)
 
Cs580
Cs580Cs580
Cs580
 
Csci101 lect09 vectorized_code
Csci101 lect09 vectorized_codeCsci101 lect09 vectorized_code
Csci101 lect09 vectorized_code
 
Frequency Response with MATLAB Examples.pdf
Frequency Response with MATLAB Examples.pdfFrequency Response with MATLAB Examples.pdf
Frequency Response with MATLAB Examples.pdf
 
Functional and reactive u is gwt.create 2015
Functional and reactive u is gwt.create 2015Functional and reactive u is gwt.create 2015
Functional and reactive u is gwt.create 2015
 

More from NishaVatwani

Quality Laggards.pdf
Quality Laggards.pdfQuality Laggards.pdf
Quality Laggards.pdf
NishaVatwani
 
Software Defects.pdf
Software Defects.pdfSoftware Defects.pdf
Software Defects.pdf
NishaVatwani
 
SEC5261_SAT_Week07_Spring22.pdf
SEC5261_SAT_Week07_Spring22.pdfSEC5261_SAT_Week07_Spring22.pdf
SEC5261_SAT_Week07_Spring22.pdf
NishaVatwani
 
SEC5 delta debugging
SEC5 delta debugging SEC5 delta debugging
SEC5 delta debugging
NishaVatwani
 
Software analysis and testing
Software analysis and testing Software analysis and testing
Software analysis and testing
NishaVatwani
 
m08mish152006ppwc07-100622022709-phpapp01 (1).pptx
m08mish152006ppwc07-100622022709-phpapp01 (1).pptxm08mish152006ppwc07-100622022709-phpapp01 (1).pptx
m08mish152006ppwc07-100622022709-phpapp01 (1).pptx
NishaVatwani
 

More from NishaVatwani (6)

Quality Laggards.pdf
Quality Laggards.pdfQuality Laggards.pdf
Quality Laggards.pdf
 
Software Defects.pdf
Software Defects.pdfSoftware Defects.pdf
Software Defects.pdf
 
SEC5261_SAT_Week07_Spring22.pdf
SEC5261_SAT_Week07_Spring22.pdfSEC5261_SAT_Week07_Spring22.pdf
SEC5261_SAT_Week07_Spring22.pdf
 
SEC5 delta debugging
SEC5 delta debugging SEC5 delta debugging
SEC5 delta debugging
 
Software analysis and testing
Software analysis and testing Software analysis and testing
Software analysis and testing
 
m08mish152006ppwc07-100622022709-phpapp01 (1).pptx
m08mish152006ppwc07-100622022709-phpapp01 (1).pptxm08mish152006ppwc07-100622022709-phpapp01 (1).pptx
m08mish152006ppwc07-100622022709-phpapp01 (1).pptx
 

Recently uploaded

Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024
Yara Milbes
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
Preparing Non - Technical Founders for Engaging a Tech Agency
Preparing Non - Technical Founders for Engaging  a  Tech AgencyPreparing Non - Technical Founders for Engaging  a  Tech Agency
Preparing Non - Technical Founders for Engaging a Tech Agency
ISH Technologies
 
ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.
Maitrey Patel
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Paul Brebner
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
ShulagnaSarkar2
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
Patrick Weigel
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
ervikas4
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
dakas1
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
Tier1 app
 

Recently uploaded (20)

Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
Preparing Non - Technical Founders for Engaging a Tech Agency
Preparing Non - Technical Founders for Engaging  a  Tech AgencyPreparing Non - Technical Founders for Engaging  a  Tech Agency
Preparing Non - Technical Founders for Engaging a Tech Agency
 
ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
 

SEC5261_SAT_Week08_Spring22.pdf

  • 3. [x == 1] Introducing Pointers x = 1; y = x; assert(y == 1) x = new Circle(); x.radius = 1; y = x.radius; assert(y == 1) Example without pointers [y == 1] Same example with pointers
  • 4. [x == 1] Introducing Pointers x = 1; y = x; assert(y == 1) x = new Circle(); x.radius = 1; y = x.radius; assert(y == 1) Example without pointers [y == 1] Same example with pointers [y == 1] [x.radius == 1]
  • 5. Pointer Aliasing • Situation in which same address referred to in different ways Circle x = new Circle(); Circle z = ? x.radius = 1; z.radius = 2; y = x.radius; assert(y == 1) x = new Circle(); x.radius = 1; y = x.radius; assert(y == 1) [x.radius == 1] [x.radius == ?] [x.radius == 1] [y == 1]
  • 6. May-Alias Analysis Circle x = new Circle(); Circle z = new Circle(); x.radius = 1; z.radius = 2; y = x.radius; assert(y == 1) May-Alias Analysis == Pointer Analysis [x.radius == 1, x != z] [x.radius == 1] [y == 1] [x != z]
  • 7. Circle x = new Circle(); Circle z = x; x.radius = 1; z.radius = 2; y = x.radius; assert(y == 1) Must-Alias Analysis • May-Alias and Must-Alias are dual problems • Must-Alias more advanced, less useful in practice • Focus of this Lesson: May-Alias Analysis [x.radius == 2] [y == 2] [x.radius == 1, x == z] [x == z] y == 2
  • 8. h.data h.next.prev.data h.next.next.prev.prev.data h.next.prev.next.prev.data And many more ... Why Is Pointer Analysis Hard? class Node { int data; Node next, prev; } Node h = null; for (...) { Node v = new Node(); if (h != null) { v.next = h; h.prev = v; } h = v; } n1 n2 next n3 prev next prev h
  • 9. Approximation to the Rescue •Pointer analysis problem is undecidable => We must sacrifice some combination of: Soundness, Completeness, Termination •We are going to sacrifice completeness => False positives but no false negatives
  • 10. What False Positives Mean Circle x = new Circle(); Circle z = new Circle(); x.radius = 1; z.radius = 2; y = x.radius; assert(y == 1) Pointer analysis answers questions of form: MayAlias(x, z)? No => x and z are not aliased in any run Yes => Can’t tell if x and z are aliased in some run [x.radius == 1, x == z or x != z] No Yes [x == z or x != z] [x.radius == 1 or x.radius == 2] [y == 1 or y == 2] False Positive! [x.radius == 1, x != z] [x.radius == 1] [y == 1] [x != z]
  • 11. Approximation to the Rescue •Many sound approximate algorithms for pointer analysis •Varying levels of precision •Differ in two key aspects: • How to abstract the heap (i.e. dynamically allocated data) • How to abstract control-flow
  • 12. Example Java Program void doit(int M, int N) { Elevator v = new Elevator(); v.floors = new Object[M]; v.events = new Object[N]; for (int i = 0; i < M; i++) { Floor f = new Floor(); v.floors[i] = f; } for (int i = 0; i < N; i++) { Event e = new Event(); v.events[i] = e; } } class Elevator { Object[] floors; Object[] events; }
  • 13. A Run of the Program void doit(int M, int N) { Elevator v = new Elevator(); v.floors = new Object[M]; v.events = new Object[N]; for (int i = 0; i < M; i++) { Floor f = new Floor(); v.floors[i] = f; } for (int i = 0; i < N; i++) { Event e = new Event(); v.events[i] = e; } } doit(3, 2) v
  • 14. Abstracting the Heap void doit(int M, int N) { Elevator v = new Elevator(); v.floors = new Object[M]; v.events = new Object[N]; for (int i = 0; i < M; i++) { Floor f = new Floor(); v.floors[i] = f; } for (int i = 0; i < N; i++) { Event e = new Event(); v.events[i] = e; } } v
  • 15. Result of Heap Abstraction: Points-to Graph Elevator v Object[] Object[] Floor Event f e floors [*] [*] event s v
  • 16. Abstracting Control-Flow void doit(int M, int N) { Elevator v = new Elevator(); v.floors = new Object[M]; v.events = new Object[N]; for (int i = 0; i < M; i++) { Floor f = new Floor(); v.floors[i] = f; } for (int i = 0; i < N; i++) { Event e = new Event(); v.events[i] = e; } } Elevator v Object[ ] Object[ ] Floor Event f e floors [*] [*] events
  • 17. Flow Insensitivity void doit(int M, int N) { Elevator v = new Elevator(); v.floors = new Object[M]; v.events = new Object[N]; for (int i = 0; i < M; i++) { Floor f = new Floor(); v.floors[i] = f; } for (int i = 0; i < N; i++) { Event e = new Event(); v.events[i] = e; } } void doit(int M, int N) { v = new Elevator v.floors = new Object[] v.events = new Object[] f = new Floor v.floors[*] = f e = new Event v.events[*] = e } - Notice that all control-flow features have been removed, including constructs like for-loops and also semicolons indicating sequentially ordered statements. - All statements that do not affect pointers have also been removed. For example, the approximated code no longer has statements setting the integer i equal to 0 and incrementing i. - Finally, array indices are replaced by nondeterministic choice, denoted by the asterisk symbol. This is similar to how conditions at branch points in dataflow analysis were replaced by nondeterministic choice.
  • 18. Chaotic Iteration Algorithm graph = empty repeat: for (each statement s in set) apply rule corresponding to s on graph until graph stops changing
  • 19. Kinds of Statements (statement) s ::= v = new … | v = v2 | v2 = v.f | v.f = v2 | v2 = v[*] | v[*] = v2 (pointer-type variable) v (pointer-type field) f
  • 20. Is This Grammar Enough? v.events = new Object[] tmp = new Object[] v.events = tmp v.events[*] = e tmp = v.events tmp[*] = e v = new … | v = v2 | v2 = v.f | v.f = v2 | v2 = v[*] | v[*] = v2
  • 21. Example Program in Normal Form void doit(int M, int N) { v = new Elevator v.floors = new Object[] v.events = new Object[] f = new Floor v.floors[*] = f e = new Event v.events[*] = e } void doit(int M, int N) { v = new Elevator tmp1 = new Object[] v.floors = tmp1 tmp2 = new Object[] v.events = tmp2 f = new Floor tmp3 = v.floors tmp3[*] = f e = new Event tmp4 = v.events tmp4[*] = e }
  • 22. Normal Form of Programs v1.f.g = v2.h v1.f = v2.f v = new … | v = v2 | v2 = v.f | v.f = v2 | v2 = v[*] | v[*] = v2 Convert each of these two expressions to normal form:
  • 23. Normal Form of Programs v1.f.g = v2.h v1.f = v2.f tmp1 = v1.f tmp2 = v2.h tmp1.g = tmp2 tmp = v2.f v1.f = tmp v = new … | v = v2 | v2 = v.f | v.f = v2 | v2 = v[*] | v[*] = v2 Convert each of these two expressions to normal form:
  • 24. Rule for Object Allocation Sites v = new B After: v Before: v A A B
  • 25. Rule for Object Allocation Sites: Example void doit(int M, int N) { v = new Elevator tmp1 = new Object[] v.floors = tmp1 tmp2 = new Object[] v.events = tmp2 f = new Floor tmp3 = v.floors tmp3[*] = f e = new Event tmp4 = v.events tmp4[*] = e } Elevator v Object[] Object[] Floor Event f e tmp 1 tmp 2
  • 26. Rule for Object Copy v1 = v2 A v1 v2 v1 v2 B After: Before: A B B
  • 27. Rule for Field Writes f or [*] After: Before: v1 . f = v2 v1[*] = v2 v1 A v2 B A C v1 v2 B A C or f or [*] f or [*] A B
  • 28. Rule for Field Writes: Example void doit(int M, int N) { v = new Elevator tmp1 = new Object[] v.floors = tmp1 tmp2 = new Object[] v.events = tmp2 f = new Floor tmp3 = v.floors tmp3[*] = f e = new Event tmp4 = v.events tmp4[*] = e } Elevato r v Object[ ] Object[ ] Floor Event f e floors event s tmp 1 tmp 2
  • 29. Rule for Field Reads A v2 B B C v2 B B C After: Before: C A v1 = v2.f v1 = v2[*] or f or [*] f or [*] v1 v1
  • 30. Rule for Field Reads: Example void doit(int M, int N) { v = new Elevator tmp1 = new Object[] v.floors = tmp1 tmp2 = new Object[] v.events = tmp2 f = new Floor tmp3 = v.floors tmp3[*] = f e = new Event tmp4 = v.events tmp4[*] = e } Elevato r v Object[ ] Object[ ] Floor Event f e floors event s tmp 1 tmp 2 tmp 3 tmp 4
  • 31. Continuing the Pointer Analysis: Example Elevato r v Object[ ] Object[ ] Floor Event f e floors event s tmp 1 tmp 2 tmp 3 tmp 4 [*] [*] void doit(int M, int N) { v = new Elevator tmp1 = new Object[] v.floors = tmp1 tmp2 = new Object[] v.events = tmp2 f = new Floor tmp3 = v.floors tmp3[*] = f e = new Event tmp4 = v.events tmp4[*] = e }
  • 32. class Node { int data; Node next, prev; } Node h = null; for (...) { Node v = new Node(); if (h != null) { v.next = h; h.prev = v; } h = v; } Pointer Analysis Example Choose the points-to graph for the shown program. Node h nex t pre v v Node h nex t pre v v Node h nex t pre v v Node h nex t pre v v
  • 33. Pointer Analysis Example Node h next prev v class Node { int data; Node next, prev; } Node h = null; for (...) { Node v = new Node(); if (h != null) { v.next = h; h.prev = v; } h = v; }
  • 34. Classifying Pointer Analysis Algorithms •Is it flow-sensitive? •Is it context-sensitive? •What heap abstraction scheme is used? •How are aggregate data types modeled?
  • 35. Flow Sensitivity •How to model control-flow within a procedure •Two kinds: flow-insensitive vs. flow-sensitive •Flow-insensitive == weak updates • Suffices for may-alias analysis •Flow-sensitive == strong updates • Required for must-alias analysis
  • 36. Context Sensitivity • How to model control-flow across procedures • Two kinds: context-insensitive vs. context-sensitive • Context-insensitive: analyze each procedure once • Context-sensitive: analyze each procedure possibly multiple times, once per abstract calling context
  • 37. Heap Abstraction • Scheme to partition unbounded set of concrete objects into finitely many abstract objects (oval nodes in points-to graph) • Ensures that pointer analysis terminates • Many sound schemes, varying in precision & efficiency • Too few abstract objects => efficient but imprecise • Too many abstract objects => expensive but precise
  • 38. Scheme #1: Allocation-Site Based One abstract object per allocation site Allocation site identified by: • new keyword in Java/C++ • malloc() call in C Finitely many allocation sites in a program => finitely many abstract objects Elevator v Object[] Object[] Floor Event f e floors events [*] [*]
  • 39. Scheme #2: Type Based • Allocation-site based scheme can be costly - Large programs - Clients needing quick turnaround time - Overly fine granularity of sites • One abstract object per type • Finitely many types in a program => finitely many abstract objects Elevator v Object[] Floor Event f e [*] [*] floors events
  • 40. Scheme #3: Heap-Insensitive Single abstract object representing entire heap Popular for languages with primarily stack-directed pointers (e.g. C) Unsuitable for languages with only heap-directed pointers (e.g. Java) v floors, events, [*] f e
  • 41. [*] Tradeoffs in Heap Abstraction Schemes More Efficient More Precise Allocation-site based Type based Heap- insensitive v floors, events, [*] f e Elevator v Object[] Object[] Floor Event f e floors events [*] Elevator v Object[] Floor Event f e [*] [*] floors events
  • 42. Modeling Aggregate Data Types: Arrays • Common choice: single field [*] to represent all array elements • Cannot distinguish different elements of same array • More sophisticated representations that make such distinctions are employed by array dependence analyses • Used to parallelize sequential loops by parallelizing compilers
  • 43. Modeling Aggregate Data Types: Records Three choices: 1. Field-insensitive: merge all fields of each record object 2. Field-based: merge each field of all record objects 3. Field-sensitive: keep each field of each (abstract) record object separate f1 f2 a1 a2 f1 f2 a1 a2 f1 f2 a1 a2
  • 44. Pointer Analysis Classification Classify the pointer analysis algorithm we learned in this lesson. Flow-sensitive? Context-sensitive? Distinguishes fields of object? Distinguishes elements of array? What kind of heap abstraction? A. Yes B. No A. Yes B. No A. Yes B. No A. Yes B. No A. Allocation- B. Type site based based
  • 45. Pointer Analysis Classification Flow-sensitive? B Context-sensitive? B Distinguishes fields of object? A Distinguishes elements of array? B What kind of heap abstraction? A A. Yes B. No A. Yes B. No A. Allocation- B. Type site based based A. Yes B. No A. Yes B. No Classify the pointer analysis algorithm we learned in this lesson.