Skip to content

Commit b711de0

Browse files
committed
refactor one callsite sensitive points-to
1 parent 4471af9 commit b711de0

3 files changed

Lines changed: 18 additions & 115 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-callsite-sensitive-pt.dl"
33

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

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

logic/inputDeclaration.dl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
.type Field <: symbol
77
.type Method <: symbol
88
.type Class <: symbol
9-
.type Context = symbol
109

1110
// load data from facts
1211
// class

logic/one-callsite-sensitive-pt.dl

Lines changed: 16 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,22 @@
11
#pragma once
2-
#include "utils.dl"
2+
#include "abstract-context-sensitive-pt.dl"
33

4-
.comp OneCallsiteSensitivePT{
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 = Insn
5+
.type Context = Insn
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-
calleeCtx = insn,
74-
SpecialMethodInvocation(insn, _, callee, _, caller).
75-
76-
Reachable(callee, calleeCtx, n+1),
77-
CallGraph(insn, caller, callerCtx, callee, calleeCtx) :-
78-
Reachable(caller, callerCtx, n),
79-
n < MAXSTEP,
80-
calleeCtx = insn,
81-
StaticMethodInvocation(insn, _, callee, caller).
82-
83-
Reachable(callee, calleeCtx, n+1),
84-
CallGraph(insn, caller, callerCtx, callee, calleeCtx) :-
85-
Reachable(caller, callerCtx, n),
86-
n < MAXSTEP,
87-
VirtualMethodInvocation(insn, _, method, base, caller),
88-
calleeCtx = insn,
89-
VarPointsTo(baseHeap, _, base, callerCtx),
90-
NormalHeap(baseHeap, class),
91-
MethodInfo(method, simplename, _, _, _, descriptor, _),
92-
Dispatch(simplename, descriptor, class, callee).
93-
94-
// param
95-
VarPointsTo(heap, hctx, param, calleeCtx) :-
96-
CallGraph(insn, _, callerCtx, callee, calleeCtx),
97-
ActualParam(n, insn, arg),
98-
FormalParam(n, callee, param),
99-
VarPointsTo(heap, hctx, arg, callerCtx),
100-
NormalHeap(heap, _).
101-
102-
// return
103-
VarPointsTo(heap, hctx, return, callerCtx) :-
104-
CallGraph(insn, _, callerCtx, callee, calleeCtx),
105-
Return(_, _, var, callee),
106-
AssignReturnValue(insn, return),
107-
VarPointsTo(heap, hctx, var, calleeCtx).
108-
109-
// this
110-
VarPointsTo(heap, hctx, this, calleeCtx) :-
111-
CallGraph(insn, _, callerCtx, callee, calleeCtx),
7+
.comp OneCallsiteSensitivePT<HContext, Context> : AbstractContextSensitivePT<HContext, Context>{
8+
.override SelectInvocationContext
9+
SelectInvocationContext(callerCtx, insn, baseHeap, hctx, calleeCtx) :-
10+
Reachable(caller, callerCtx, _),
11211
(
113-
VirtualMethodInvocation(insn, _, _, base, _);
114-
SpecialMethodInvocation(insn, _, _, base, _)
12+
SpecialMethodInvocation(insn, _, _, base, caller);
13+
VirtualMethodInvocation(insn, _, _, base, caller)
11514
),
116-
ThisVar(callee, this),
117-
VarPointsTo(heap, hctx, base, callerCtx).
15+
VarPointsTo(baseHeap, hctx, base, callerCtx),
16+
calleeCtx = insn.
17+
18+
SelectStaticInvocationContext(callerCtx, insn, calleeCtx) :-
19+
Reachable(caller, callerCtx, _),
20+
StaticMethodInvocation(insn, _, _, caller),
21+
calleeCtx = insn.
11822
}

0 commit comments

Comments
 (0)