corda/test/Subroutine.java

43 lines
1.0 KiB
Java
Raw Normal View History

public class Subroutine {
private static void expect(boolean v) {
if (! v) throw new RuntimeException();
}
// This test is intended to cover the jsr and ret instructions.
// However, recent Sun javac versions avoid generating these
// instructions by default, so we must compile this class using
// -source 1.2 -target 1.1 -XDjsrlimit=0.
//
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4381996
//
2008-11-17 15:21:20 +00:00
private static void test(boolean throw_, boolean predicate) {
int x = 42;
int y = 99;
int a = 0;
try {
try {
int z = x + y;
if (throw_) throw new DummyException();
2008-11-17 15:21:20 +00:00
if (predicate) {
return;
}
Integer.valueOf(z).toString();
} finally {
a = x + y;
System.gc();
}
expect(a == x + y);
} catch (DummyException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
2008-11-17 15:21:20 +00:00
test(false, false);
test(false, true);
test(true, false);
}
private static class DummyException extends RuntimeException { }
}