Skip to content

Commit 0e1a50a

Browse files
[GR-54853] [GR-60663] Fix compilation bailouts when the debugger is enabled.
PullRequest: graal/19636
2 parents 8d2de22 + 048ee0a commit 0e1a50a

File tree

6 files changed

+237
-293
lines changed

6 files changed

+237
-293
lines changed

espresso/mx.espresso/mx_espresso.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def _run_espresso(args=None, cwd=None, nonZeroIsFatal=True, out=None, err=None,
130130

131131
def _run_espresso_meta(args, nonZeroIsFatal=True, timeout=None):
132132
"""Run Espresso (standalone) on Espresso (launcher)"""
133-
return _run_espresso_launcher([
133+
return _run_espresso([
134134
'--vm.Xss4m',
135135
] + _espresso_standalone_command(args, allow_jacoco=False), nonZeroIsFatal=nonZeroIsFatal, timeout=timeout)
136136

espresso/src/com.oracle.truffle.espresso.jdwp/src/com/oracle/truffle/espresso/jdwp/api/ErrorCodes.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public final class ErrorCodes {
5050
public static final int ABSENT_INFORMATION = 101;
5151
public static final int INVALID_EVENT_TYPE = 102;
5252
public static final int INTERNAL = 113;
53+
public static final int INVALID_INDEX = 503;
5354
public static final int INVALID_LENGTH = 504;
5455
public static final int INVALID_STRING = 506;
5556
public static final int INVALID_CLASS_LOADER = 507;

espresso/src/com.oracle.truffle.espresso.jdwp/src/com/oracle/truffle/espresso/jdwp/impl/JDWP.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,8 +2111,7 @@ static CommandResult createReply(Packet packet, DebuggerController controller) {
21112111
}
21122112

21132113
int startFrame = input.readInt();
2114-
int length = input.readInt();
2115-
final int requestedLength = length;
2114+
int requestedLength = input.readInt();
21162115

21172116
controller.fine(() -> "requesting frames for thread: " + controller.getContext().getThreadName(thread));
21182117
controller.fine(() -> "startFrame requested: " + startFrame);
@@ -2127,13 +2126,21 @@ static CommandResult createReply(Packet packet, DebuggerController controller) {
21272126
}
21282127

21292128
CallFrame[] frames = suspendedInfo.getStackFrames();
2130-
2131-
if (length == -1 || length > frames.length) {
2132-
length = frames.length;
2129+
if (startFrame < 0 || startFrame >= frames.length) {
2130+
reply.errorCode(ErrorCodes.INVALID_INDEX);
2131+
return new CommandResult(reply);
2132+
}
2133+
int length;
2134+
if (requestedLength == -1) {
2135+
length = frames.length - startFrame;
2136+
} else if (requestedLength < 0 || startFrame + requestedLength > frames.length) {
2137+
reply.errorCode(ErrorCodes.INVALID_LENGTH);
2138+
return new CommandResult(reply);
2139+
} else {
2140+
length = requestedLength;
21332141
}
21342142
reply.writeInt(length);
2135-
final int finalLength = length;
2136-
controller.fine(() -> "returning " + finalLength + " frames for thread: " + controller.getContext().getThreadName(thread));
2143+
controller.fine(() -> "returning " + length + " frames for thread: " + controller.getContext().getThreadName(thread));
21372144

21382145
for (int i = startFrame; i < startFrame + length; i++) {
21392146
CallFrame frame = frames[i];

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)