-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathHBEvent.java
More file actions
177 lines (151 loc) · 5.01 KB
/
HBEvent.java
File metadata and controls
177 lines (151 loc) · 5.01 KB
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
package engine.racedetectionengine.hb;
import engine.racedetectionengine.RaceDetectionEvent;
import util.vectorclock.VectorClock;
public class HBEvent extends RaceDetectionEvent<HBState> {
public HBEvent() {
super();
}
public boolean Handle(HBState state, int verbosity){
return this.HandleSub(state, verbosity);
}
/**************Pretty Printing*******************/
@Override
public void printRaceInfoLockType(HBState state, int verbosity){
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.HBThread, this.getThread());
str += C_t.toString();
str += "|";
str += this.getThread().getName();
System.out.println(str);
}
}
@Override
public void printRaceInfoAccessType(HBState state, int verbosity){
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.HBThread, this.getThread());
str += C_t.toString();
str += "|";
str += this.getThread().getName();
System.out.println(str);
}
}
@Override
public void printRaceInfoExtremeType(HBState state, int verbosity){
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.HBThread, this.getThread());
str += C_t.toString();
str += "|";
str += this.getThread().getName();
System.out.println(str);
}
}
/************************************************/
/**************Acquire/Release*******************/
@Override
public boolean HandleSubAcquire(HBState state, int verbosity){
VectorClock C_t = state.getVectorClock(state.HBThread, 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(HBState state, int verbosity) {
VectorClock C_t = state.getVectorClock(state.HBThread, this.getThread());
VectorClock L_l = state.getVectorClock(state.lastReleaseLock, this.getLock());
L_l.copyFrom(C_t);
state.incClockThread(getThread());
this.printRaceInfo(state, verbosity);
return false;
}
/************************************************/
/****************Read/Write**********************/
@Override
public boolean HandleSubRead(HBState state, int verbosity) {
boolean raceDetected = false;
VectorClock C_t = state.getVectorClock(state.HBThread, this.getThread());
VectorClock R_v = state.getVectorClock(state.readVariable, getVariable());
VectorClock W_v = state.getVectorClock(state.writeVariable, getVariable());
this.printRaceInfo(state, verbosity);
if (!(W_v.isLessThanOrEqual(C_t))) {
raceDetected = true;
}
R_v.updateWithMax(R_v, C_t);
return raceDetected;
}
@Override
public boolean HandleSubWrite(HBState state, int verbosity) {
boolean raceDetected = false;
VectorClock C_t = state.getVectorClock(state.HBThread, 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(C_t))) {
raceDetected = true;
}
if (!(W_v.isLessThanOrEqual(C_t))) {
raceDetected = true;
}
W_v.updateWithMax(W_v, C_t);
return raceDetected;
}
/************************************************/
/*****************Fork/Join**********************/
@Override
public boolean HandleSubFork(HBState state,int verbosity) {
if (state.isThreadRelevant(this.getTarget())) {
VectorClock C_t = state.getVectorClock(state.HBThread, this.getThread());
VectorClock C_tc = state.getVectorClock(state.HBThread, this.getTarget());
C_tc.updateWithMax(C_tc, C_t);
state.incClockThread(this.getThread());
this.printRaceInfo(state, verbosity);
}
return false;
}
@Override
public boolean HandleSubJoin(HBState state,int verbosity) {
if (state.isThreadRelevant(this.getTarget())) {
VectorClock C_t = state.getVectorClock(state.HBThread, this.getThread());
VectorClock C_tc = state.getVectorClock(state.HBThread, this.getTarget());
C_t.updateWithMax(C_t, C_tc);
this.printRaceInfo(state, verbosity);
}
return false;
}
/************************************************/
@Override
public void printRaceInfoTransactionType(HBState state, int verbosity) {
// TODO Auto-generated method stub
}
@Override
public boolean HandleSubBegin(HBState state, int verbosity) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean HandleSubEnd(HBState state, int verbosity) {
// TODO Auto-generated method stub
return false;
}
}