finally_alloc.sleela
impl/tests/runtime/pressure/finally_alloc.sleela · 33 line(s) · sleela
#sleela 3.1
class FinallyAlloc {
static int[] build(int n) {
int[] r = new int[n];
for (int i = 0; i < n; i++) { r[i] = i + 1; }
try {
return r;
} finally {
for (int k = 0; k < 6000; k++) { int[] junk = new int[3]; junk[0] = k; }
}
}
static int viaException(int n) {
try {
int[] t = new int[n];
t[0] = 41;
throw new RuntimeException("x");
} catch (RuntimeException e) {
int[] c = new int[4];
c[1] = 1;
return c[1] + 41;
} finally {
for (int k = 0; k < 6000; k++) { int[] junk = new int[2]; junk[1] = k; }
}
}
void main() {
int[] a = build(50);
int s = 0;
for (int i = 0; i < 50; i++) { s = s + a[i]; }
print("returned array intact " + s);
print(viaException(5));
}
}