corda/sgx-jvm/avian/test/extra/Tails.java
Andras Slemmer 9bb3d6b972 Add 'sgx-jvm/avian/' from commit '09e4fe60d01f4f4bfb6b2976973bb4913ef61edc'
git-subtree-dir: sgx-jvm/avian
git-subtree-mainline: f978eab8d1
git-subtree-split: 09e4fe60d0
2017-03-13 12:18:24 +00:00

50 lines
1.0 KiB
Java

package extra;
public class Tails {
private static final int Limit = 1000000;
private static void expect(boolean v) {
if (! v) throw new RuntimeException();
}
private static int staticMethod(Interface i, int n) {
if (n < Limit) {
return i.interfaceMethod(n + 1);
} else {
return leafMethod(n);
}
}
private static int leafMethod(int n) {
expect(new Throwable().getStackTrace().length == 2);
return n;
}
public static void main(String[] args) {
expect(staticMethod(new Foo(), 0) == Limit);
}
private interface Interface {
public int interfaceMethod(int n);
}
private static class Foo implements Interface {
public int interfaceMethod(int n) {
if (n < Limit) {
return virtualMethod(n + 1, 1, 2, 3, 4, 5);
} else {
return leafMethod(n);
}
}
public int virtualMethod(int n, int a, int b, int c, int d, int e) {
if (n < Limit) {
return staticMethod(this, n + 1);
} else {
return leafMethod(n);
}
}
}
}