• Keine Ergebnisse gefunden

(2) Values of Variables:

N/A
N/A
Protected

Academic year: 2022

Aktie "(2) Values of Variables:"

Copied!
25
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

(2) Values of Variables:

• Extend the set Expr of expressions by occurring loads M[e] .

• Extend the Effects of Edges:

[[x = M[e];]] V e =





{x} if e = M[e]

∅ if e = e V e\{x} otherwise [[M[e1] = e2;]] V e =

( ∅ if e ∈ {e1, e2} V e otherwise

(2)

(3) Constant Propagation:

• Extend the abstract state by an abstract store M

• Execute accesses to known memory locations!

[[x = M[e];]] (D, M) =





(D ⊕ {x 7→ M a}, M) if

[[e]] D = a⊏⊤ (D ⊕ {x 7→ ⊤}, M) otherwise

[[M[e1] = e2;]] (D, M) =





(D,M ⊕ {a 7→ [[e2]]D}) if

[[e1]] D = a⊏⊤

(D,⊤) otherwise where

⊤a = ⊤ (a ∈ N)

363

(3)

Problems:

• Addresses are from N :-(

There are no infinite strictly ascending chains, but ...

• Exact addresses at compile-time are rarely known :-(

• At the same program point, typically different addresses are accessed ...

• Storing at an unknown address destroys all information M :-(

==⇒ constant propagation fails :-(

(4)

Simplification:

• We consider pointers to the beginning of blocks A which allow indexed accesses A[i] :-)

• We ignore well-typedness of the blocks.

• New statements:

x = new(); // allocation of a new block

x = y[e]; // indexed read access to a block y[e1] = e2; // indexed write access to a block

• Blocks are possibly infinite :-)

• For simplicity, all pointers point to the beginning of a block.

365

(5)

Simple Example:

x = new();

y = new();

x[0] = y;

y[1] = 7;

y[1] = 7;

x[0] = y; 1

y = new();

2 3 4 0

x = new();

(6)

The Semantics:

y x

367

(7)

The Semantics:

y

x 1

0

(8)

The Semantics:

y x

0 1

0 1

369

(9)

The Semantics:

y x

0 1

0 1

(10)

The Semantics:

y x

7 0

1

0 1

371

(11)

More Complex Example:

r = Null;

while (t 6= Null) { h = t;

t = t[0];

h[0] = r;

r = h;

}

r = Null;

Pos(t 6= Null) Neg(t 6= Null)

7

r = h;

3 4 5 2

h = t; 1

0

t = t[0];

h[0] = r;

(12)

Concrete Semantics:

A store consists of a finite collection of blocks.

After h new-operations we obtain:

Addrh = {ref a | 0 ≤ a < h} // addresses

Valh = Addrh ∪ Z // values

Storeh = (Addrh × N0) → Valh // store Stateh = (Vars → Valh) × Storeh // states For simplicity, we set: 0 = Null

373

(13)

Let (ρ, µ) ∈ Stateh . Then we obtain for the new edges:

[[x = new();]] (ρ, µ) = (ρ ⊕ {x 7→ ref h},

µ ⊕ {(ref h, i) 7→ 0 | i ∈ N0}) [[x = y[e];]] (ρ, µ) = (ρ ⊕ {x 7→ µ(ρy, [[e]]ρ)}, µ) [[y[e1] = e2;]] (ρ, µ) = (ρ, µ ⊕ {(ρy, [[e1]]ρ) 7→ [[e2]]ρ})

(14)

Caveat:

This semantics is too detailled in that it computes with absolute Addresses. Accordingly, the two programs:

x = new();

y = new();

y = new();

x = new();

are not considered as equivalent !!?

Possible Solution:

Define equivalence only up to permutation of addresses :-)

375

(15)

Alias Analysis 1. Idea:

• Distinguish finitely many classes of blocks.

• Collect all addresses of a block into one set!

• Use sets of addresses as abstract values!

==⇒ Points-to-Analysis

Addr = Edges // creation edges

Val = 2Addr // abstract values

Store = Addr → Val // abstract store State = (Vars → Val) × Store // abstract states

(16)

... in the Simple Example:

y[1] = 7;

x[0] = y; 1

y = new();

2 3 4 0

x = new(); x y (0, 1)

0 ∅ ∅ ∅

1 {(0, 1)} ∅ ∅

2 {(0, 1)} {(1,2)} ∅ 3 {(0, 1)} {(1,2)} {(1, 2)}

4 {(0, 1)} {(1,2)} {(1, 2)}

377

(17)

The Effects of Edges:

[[(_,;, _)]] (D, M) = (D, M) [[(_,Pos(e),_)]] (D, M) = (D, M)

[[(_,x = y;, _)]] (D, M) = (D ⊕ {x 7→ D y}, M)

[[(_,x = e;,_)]] (D, M) = (D ⊕ {x 7→ ∅}, M) , e 6∈ Vars

[[(u, x = new();, v)]] (D, M) = (D ⊕ {x 7→ {(u, v)}}, M) [[(_,x = y[e];, _)]] (D, M) = (D ⊕ {x 7→ S

{M(f) | f ∈ D y}}, M) [[(_,y[e1] = x;,_)]] (D, M) = (D, M ⊕ {f 7→ (M f ∪ D x) | f ∈ D y})

(18)

Caveat:

• The value Null has been ignored. Dereferencing of Null or negative indices are not detected :-(

• Destructive updates are only possible for variables, not for blocks in storage!

==⇒ no information, if not all block entries are initialized before use :-((

• The effects now depend on the edge itself.

The analysis cannot be proven correct w.r.t. the reference semantics :-(

In order to prove correctness, we first instrument the concrete

semantics with extra information which records where a block has been created.

379

(19)

• ...

• We compute possible points-to information.

• From that, we can extract may-alias information.

• The analysis can be rather expensive — without finding very much :-(

• Separate information for each program point can perhaps be abandoned ??

(20)

Alias Analysis 2. Idea:

Compute for each variable and address a value which safely approximates the values at every program point simultaneously !

... in the Simple Example:

y[1] = 7;

x[0] = y; 1

y = new();

2 3 4 0

x = new();

x {(0, 1)}

y {(1, 2)}

(0,1) {(1, 2)}

(1,2) ∅

381

(21)

Each edge (u,lab,v) gives rise to constraints:

lab Constraint

x = y; P[x] ⊇ P[y]

x = new(); P[x] ⊇ {(u, v)}

x = y[e]; P[x] ⊇ S

{P[f] | f ∈ P[y]}

y[e1] = x; P[f] ⊇ (f ∈ P[y]) ?P[x] : ∅ for all f ∈ Addr

Other edges have no effect :-)

(22)

Discussion:

• The resulting constraint system has size O(k · n) for k abstract addresses and n edges :-(

• The number of necessary iterations is O(k˙(k + #Vars)) ...

• The computed information is perhaps still too zu precise !!?

• In order to prove correctness of a solution s ∈ States we show:

s s1

s [[k]]

383

(23)

Alias Analysis 3. Idea:

Determine one equivalence relation ≡ on variables x and memory accesses y[ ] with s1 ≡s2 whenever s1, s2 may contain the

same address at some u1, u2

... in the Simple Example:

x[0] = y; 1

y = new();

2 3 0

x = new();

≡ = {{x}, {y, x[ ]}, {y[ ]}}

(24)

Discussion:

→ We compute a single information fo the whole program.

→ The computation of this information maintains partitions π = {P1, . . . , Pm} :-)

→ Individual sets Pi are identified by means of representatives pi ∈ Pi.

→ The operations on a partition π are:

find (π, p) = pi if p ∈ Pi

// returns the representative

union(π, pi1, pi2) = {Pi1 ∪ Pi2} ∪ {Pj | i1 6= j 6= i2} // unions the represented classes

385

(25)

→ If x1, x2 ∈ Vars are equivalent, then also x1[ ] and x2[ ] must be equivalent :-)

→ If Pi ∩ Vars 6= ∅ , then we choose pi ∈ Vars . Then we can apply union recursively :

union (π, q1, q2) = let pi1 = find (π, q1) pi2 = find (π, q2) in if pi1 ==pi2 then π

else let π = union(π, pi1, pi2) in if pi1, pi2 ∈ Vars then

union (π, p [ ], p [ ])

Referenzen

ÄHNLICHE DOKUMENTE

For instance, McLachlan’s [7] “typicality indices” are just p-values π θ (X, D) sat- isfying (1.2) in the special case of multivariate gaussian distributions P θ ; see also

j t will have the following definitional balance identities (labor outflow = labor inflow) :.. a d b) The second concept is based on Marx's dual treatment of value product

of value judgment; or the results of risk analysis may include those value judgments and lead to more complete recommendations regarding the decision?. The decision

For the study of Bogner and Wiseman [17,41], for example, the attitudinal objects: environment and nature were regarded similarly: The exploitative Utilization of natural resources

Barnes 1980), and pseudo-spectral methods, constructs an interpo- lation of the magnetic field and then modifies the point values so that with the given interpolation scheme

Besides drawing on pathways that are already presented in the literature (via shared values and value content) we add a third, in which values influence the formation and change of

the existence of an organizational culture which supports and values thought and behavior processes conducive to learning and reinforces a structure open to

Keywords: environmental values, Nature, ethics, utilitarianism, rights, virtue, incommensurability, intrinsic value, economic valuation, moral considerability/standing, plural