Skip to content

Commit 5f15b43

Browse files
committed
refactor one type sensitive points-to
1 parent 18cecc4 commit 5f15b43

2 files changed

Lines changed: 14 additions & 118 deletions

File tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#define MAXSTEP 8
22
#include "../logic/one-type-sensitive-pt.dl"
33

4-
.init typeDemo1 = OneTypeSensitivePT
4+
.init typeDemo1 = OneTypeSensitivePT<HContext, Context>
55
typeDemo1.Reachable("<com.bytecodedl.benchmark.demo.ContextSensitiveDemo1: void main(java.lang.String[])>", "initCtx", 0).
66
.output typeDemo1.VarPointsTo
77

8-
.init typeDemo2 = OneTypeSensitivePT
8+
.init typeDemo2 = OneTypeSensitivePT<HContext, Context>
99
typeDemo2.Reachable("<com.bytecodedl.benchmark.demo.ContextSensitiveDemo2: void main(java.lang.String[])>", "initCtx", 0).
1010
.output typeDemo2.VarPointsTo

logic/one-type-sensitive-pt.dl

Lines changed: 12 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,19 @@
11
#pragma once
2-
#include "utils.dl"
2+
#include "abstract-context-sensitive-pt.dl"
33

4-
.comp OneTypeSensitivePT{
5-
.decl VarPointsTo(heap:Heap, hctx:Context, var:Var, vCtx:Context)
6-
.decl InstanceFieldPointsTo(heap:Heap, hctx:Context, baseHeap:Heap, bhCtx:Context, field:Field)
7-
.decl StaticFieldPointsTo(heap:Heap, hctx:Context, field:Field)
8-
.decl ArrayIndexPointsTo(heap:Heap, hctx:Context, baseHeap:Heap, bhCtx:Context)
9-
.decl Reachable(method:Method, ctx:Context, n:number)
10-
.decl CallGraph(insn:Insn, caller:Method, callerCtx:Context, callee:Method, calleeCtx:Context)
4+
.type HContext = Class
5+
.type Context = Class
116

12-
// new
13-
VarPointsTo(heap, ctx, var, ctx) :-
14-
Reachable(method, ctx, _),
15-
AssignHeapAllocation(_, _, heap, var, method, _).
16-
17-
// assign
18-
VarPointsTo(heap, hctx, to, ctx) :-
19-
Reachable(method, ctx, _),
20-
VarPointsTo(heap, hctx, from, ctx),
21-
AssignLocal(_, _, from, to, method).
22-
23-
// cast
24-
VarPointsTo(heap, hctx, to, ctx) :-
25-
Reachable(method, ctx, _),
26-
AssignCast(_, _, from, to, _, method),
27-
VarPointsTo(heap, hctx, from, ctx).
28-
29-
// load field
30-
VarPointsTo(heap, hctx, to, ctx) :-
31-
Reachable(method, ctx, _),
32-
LoadInstanceField(_, _, to, base, field, method),
33-
VarPointsTo(baseHeap, bhCtx, base, ctx),
34-
InstanceFieldPointsTo(heap, hctx, baseHeap, bhCtx, field).
35-
36-
// store field
37-
InstanceFieldPointsTo(heap, hctx, baseHeap, bhCtx, field) :-
38-
Reachable(method, ctx, _),
39-
StoreInstanceField(_, _, from, base, field, method),
40-
VarPointsTo(heap, hctx, from, ctx),
41-
VarPointsTo(baseHeap, bhCtx, base, ctx).
42-
43-
// load staic field
44-
VarPointsTo(heap, hctx, to, ctx) :-
45-
Reachable(method, ctx, _),
46-
LoadStaticField(_, _, to, field, method),
47-
StaticFieldPointsTo(heap, hctx, field).
48-
49-
// store static field
50-
StaticFieldPointsTo(heap, hctx, field) :-
51-
Reachable(method, ctx, _),
52-
StoreStaticField(_, _, from, field, method),
53-
VarPointsTo(heap, hctx, from, ctx).
54-
55-
// load from array
56-
VarPointsTo(heap, hctx, to, ctx) :-
57-
Reachable(method, ctx, _),
58-
LoadArrayIndex(_, _, to, base, method),
59-
VarPointsTo(baseHeap, bhCtx, base, ctx),
60-
ArrayIndexPointsTo(heap, hctx, baseHeap, bhCtx).
61-
62-
// store into array
63-
ArrayIndexPointsTo(heap, hctx, baseHeap, bhCtx) :-
64-
Reachable(method, ctx, _),
65-
StoreArrayIndex(_, _, from, base, method),
66-
VarPointsTo(heap, hctx, from, ctx),
67-
VarPointsTo(baseHeap, bhCtx, base, ctx).
68-
69-
Reachable(callee, calleeCtx, n+1),
70-
CallGraph(insn, caller, callerCtx, callee, calleeCtx) :-
71-
Reachable(caller, callerCtx, n),
72-
n < MAXSTEP,
73-
SpecialMethodInvocation(insn, _, callee, base, caller),
74-
VarPointsTo(baseHeap, _, base, callerCtx),
75-
AssignHeapAllocation(_, _, baseHeap, _, inmethod, _),
76-
MethodInfo(inmethod, _, _, inType, _, _, _),
77-
calleeCtx = inType.
78-
79-
Reachable(callee, calleeCtx, n+1),
80-
CallGraph(insn, caller, callerCtx, callee, calleeCtx) :-
81-
Reachable(caller, callerCtx, n),
82-
n < MAXSTEP,
83-
StaticMethodInvocation(insn, _, callee, caller),
84-
calleeCtx = insn. // maybe have bug
85-
86-
Reachable(callee, calleeCtx, n+1),
87-
CallGraph(insn, caller, callerCtx, callee, calleeCtx) :-
88-
Reachable(caller, callerCtx, n),
89-
n < MAXSTEP,
90-
VirtualMethodInvocation(insn, _, method, base, caller),
91-
VarPointsTo(baseHeap, _, base, callerCtx),
92-
NormalHeap(baseHeap, class),
93-
MethodInfo(method, simplename, _, _, _, descriptor, _),
94-
Dispatch(simplename, descriptor, class, callee),
7+
.comp OneTypeSensitivePT<HContext, Context> : AbstractContextSensitivePT<HContext, Context>{
8+
.override SelectInvocationContext
9+
SelectInvocationContext(callerCtx, insn, baseHeap, hctx, calleeCtx) :-
10+
Reachable(caller, callerCtx, _),
11+
(
12+
SpecialMethodInvocation(insn, _, _, base, caller);
13+
VirtualMethodInvocation(insn, _, _, base, caller)
14+
),
15+
VarPointsTo(baseHeap, hctx, base, callerCtx),
9516
AssignHeapAllocation(_, _, baseHeap, _, inmethod, _),
9617
MethodInfo(inmethod, _, _, inType, _, _, _),
9718
calleeCtx = inType.
98-
99-
// param
100-
VarPointsTo(heap, hctx, param, calleeCtx) :-
101-
CallGraph(insn, _, callerCtx, callee, calleeCtx),
102-
ActualParam(n, insn, arg),
103-
FormalParam(n, callee, param),
104-
VarPointsTo(heap, hctx, arg, callerCtx),
105-
NormalHeap(heap, _).
106-
107-
// return
108-
VarPointsTo(heap, hctx, return, callerCtx) :-
109-
CallGraph(insn, _, callerCtx, callee, calleeCtx),
110-
Return(_, _, var, callee),
111-
AssignReturnValue(insn, return),
112-
VarPointsTo(heap, hctx, var, calleeCtx).
113-
114-
// this
115-
VarPointsTo(heap, hctx, this, calleeCtx) :-
116-
CallGraph(insn, _, callerCtx, callee, calleeCtx),
117-
(
118-
VirtualMethodInvocation(insn, _, _, base, _);
119-
SpecialMethodInvocation(insn, _, _, base, _)
120-
),
121-
ThisVar(callee, this),
122-
VarPointsTo(heap, hctx, base, callerCtx).
12319
}

0 commit comments

Comments
 (0)