Skip to content

Commit 5e64bd6

Browse files
Use a single statementIndex
Otherwise this causes a state explosiong in merge-explode
1 parent 7456cd5 commit 5e64bd6

File tree

2 files changed

+96
-79
lines changed

2 files changed

+96
-79
lines changed

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/bytecode/MapperBCI.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ private int lookup(int targetBCI) {
102102
throw EspressoError.shouldNotReachHere();
103103
}
104104

105+
/**
106+
* Lookup the index of the largest element which is smaller or equal to {@code targetBCI}.
107+
*/
108+
public int lookupBucket(int targetBCI) {
109+
int res = slowLookup(targetBCI, 0, length);
110+
if (res >= 0) {
111+
return res;
112+
}
113+
return -res - 1;
114+
}
115+
105116
public int lookup(int curIndex, int curBCI, int targetBCI) {
106117
int res;
107118
int start;
@@ -117,7 +128,7 @@ public int lookup(int curIndex, int curBCI, int targetBCI) {
117128
if (res >= 0) {
118129
return res;
119130
}
120-
return -res - 2;
131+
return -res - 1;
121132
}
122133

123134
public int checkNext(int curIndex, int targetBCI) {
@@ -128,20 +139,20 @@ public int checkNext(int curIndex, int targetBCI) {
128139
}
129140

130141
/**
131-
* inlined binary search. No bounds checks.
142+
* Inlined binary search. No bounds checks.
132143
*
133144
* @see Arrays#binarySearch(int[], int, int, int)
145+
* @return either the index of the element that is equal to {@code targetBCI} or a negative
146+
* number {@code -(i + 1)} where i is the index of the largest element which is smaller
147+
* than {@code targetBCI}.
134148
*/
135149
@ExplodeLoop(kind = ExplodeLoop.LoopExplosionKind.FULL_EXPLODE)
136150
private int slowLookup(int targetBCI, int start, int end) {
137-
// Our usage should not see an out of bounds
138151
int low = start;
139152
int high = end - 1;
140-
141153
while (low <= high) {
142154
int mid = (low + high) >>> 1;
143155
int midVal = bcis[mid];
144-
145156
if (midVal < targetBCI) {
146157
low = mid + 1;
147158
} else if (midVal > targetBCI) {
@@ -150,7 +161,7 @@ private int slowLookup(int targetBCI, int start, int end) {
150161
return mid;
151162
}
152163
}
153-
return -(low + 1); // key not found.
164+
return -low;
154165
}
155166

156167
}

0 commit comments

Comments
 (0)