-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathFHBEvent.java
199 lines (166 loc) · 5.52 KB
/
FHBEvent.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package engine.racedetectionengine.fhb;
import engine.racedetectionengine.RaceDetectionEvent;
import util.vectorclock.VectorClock;
public class FHBEvent extends RaceDetectionEvent<FHBState> {
@Override
public boolean Handle(FHBState state, int verbosity) {
return this.HandleSub(state, verbosity);
}
@Override
public void printRaceInfoLockType(FHBState state, int verbosity) {
if (this.getType().isLockType()) {
if (verbosity >= 2) {
String str = "#";
str += Integer.toString(getLocId());
str += "|";
str += this.getType().toString();
str += "|";
str += this.getLock().toString();
str += "|";
VectorClock C_t = state.getVectorClock(state.clockThread,
this.getThread());
str += C_t.toString();
str += "|";
str += this.getThread().getName();
System.out.println(str);
}
}
}
@Override
public void printRaceInfoAccessType(FHBState state, int verbosity) {
if (this.getType().isAccessType()) {
if (verbosity >= 2) {
String str = "#";
str += Integer.toString(getLocId());
str += "|";
str += this.getType().toString();
str += "|";
str += this.getVariable().getName();
str += "|";
VectorClock C_t = state.getVectorClock(state.clockThread,
this.getThread());
str += C_t.toString();
str += "|";
str += this.getThread().getName();
str += "@" + state.getThreadIndex(this.getThread());
str += "|";
str += this.getAuxId();
System.out.println(str);
}
}
}
@Override
public void printRaceInfoExtremeType(FHBState state, int verbosity) {
if (this.getType().isExtremeType()) {
if (verbosity >= 2) {
String str = "#";
str += Integer.toString(getLocId());
str += "|";
str += this.getType().toString();
str += "|";
str += this.getTarget().toString();
str += "|";
VectorClock C_t = state.getVectorClock(state.clockThread,
this.getThread());
str += C_t.toString();
str += "|";
str += this.getThread().getName();
System.out.println(str);
}
}
}
@Override
public void printRaceInfoTransactionType(FHBState state, int verbosity) {
}
@Override
public boolean HandleSubAcquire(FHBState state, int verbosity) {
VectorClock C_t = state.getVectorClock(state.clockThread, this.getThread());
VectorClock L_l = state.getVectorClock(state.lastReleaseLock, this.getLock());
C_t.updateWithMax(C_t, L_l);
this.printRaceInfo(state, verbosity);
return false;
}
@Override
public boolean HandleSubRelease(FHBState state, int verbosity) {
VectorClock C_t = state.getVectorClock(state.clockThread, this.getThread());
VectorClock L_l = state.getVectorClock(state.lastReleaseLock, this.getLock());
L_l.copyFrom(C_t);
this.printRaceInfo(state, verbosity);
state.incClockThread(getThread());
return false;
}
@Override
public boolean HandleSubRead(FHBState state, int verbosity) {
boolean raceDetected = false;
VectorClock C_t = state.getVectorClock(state.clockThread, this.getThread());
VectorClock W_v = state.getVectorClock(state.writeVariable, getVariable());
this.printRaceInfo(state, verbosity);
if (!(W_v.isLessThanOrEqual(C_t))) {
raceDetected = true;
state.addLocPair(state.getLWLocId(this.getVariable()), this.getLocId());
// Force order
C_t.updateWithMax(C_t, W_v);
}
this.printRaceInfo(state, verbosity);
VectorClock R_v = state.getVectorClock(state.readVariable, getVariable());
R_v.updateWithMax(R_v, C_t);
state.setLastReadData(this.getVariable(), this.getThread(), this.getLocId(), C_t);
state.incClockThread(getThread());
return raceDetected;
}
@Override
public boolean HandleSubWrite(FHBState state, int verbosity) {
boolean raceDetected = false;
VectorClock C_t = state.getVectorClock(state.clockThread, this.getThread());
VectorClock R_v = state.getVectorClock(state.readVariable, getVariable());
VectorClock W_v = state.getVectorClock(state.writeVariable, getVariable());
this.printRaceInfo(state, verbosity);
if (R_v.isLessThanOrEqual(W_v)) {
if (!(W_v.isLessThanOrEqual(C_t))) {
raceDetected = true;
state.addLocPair(state.getLWLocId(this.getVariable()), this.getLocId());
}
} else {
raceDetected = state.checkRaceWithReadsAndAddLocPairs(this.getThread(),
this.getVariable(), C_t, this.getLocId());
}
C_t.updateWithMax(C_t, W_v, R_v);
this.printRaceInfo(state, verbosity);
W_v.copyFrom(C_t);
state.setLWLocId(this.getVariable(), this.getLocId());
state.incClockThread(getThread());
return raceDetected;
}
@Override
public boolean HandleSubFork(FHBState state, int verbosity) {
if (state.isThreadRelevant(this.getTarget())) {
VectorClock C_t = state.getVectorClock(state.clockThread, this.getThread());
VectorClock C_tc = state.getVectorClock(state.clockThread, this.getTarget());
C_tc.copyFrom(C_t);
state.setIndex(C_tc, this.getTarget(), 1);
this.printRaceInfo(state, verbosity);
state.incClockThread(getThread());
}
return false;
}
@Override
public boolean HandleSubJoin(FHBState state, int verbosity) {
if (state.isThreadRelevant(this.getTarget())) {
VectorClock C_t = state.getVectorClock(state.clockThread, this.getThread());
VectorClock C_tc = state.getVectorClock(state.clockThread, this.getTarget());
C_t.updateWithMax(C_t, C_tc);
this.printRaceInfo(state, verbosity);
}
return false;
}
@Override
public boolean HandleSubBegin(FHBState state, int verbosity) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean HandleSubEnd(FHBState state, int verbosity) {
// TODO Auto-generated method stub
return false;
}
}