2008-11-12 17:07:30 +00:00
|
|
|
public class Subroutine {
|
|
|
|
private static void expect(boolean v) {
|
|
|
|
if (! v) throw new RuntimeException();
|
|
|
|
}
|
|
|
|
|
2009-06-11 00:11:27 +00:00
|
|
|
// These tests are intended to cover the jsr and ret instructions.
|
2008-11-12 17:07:30 +00:00
|
|
|
// 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
|
|
|
|
//
|
2009-06-11 00:11:27 +00:00
|
|
|
|
2008-11-17 15:21:20 +00:00
|
|
|
private static void test(boolean throw_, boolean predicate) {
|
2008-11-12 17:07:30 +00:00
|
|
|
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;
|
|
|
|
}
|
2008-11-12 17:07:30 +00:00
|
|
|
Integer.valueOf(z).toString();
|
|
|
|
} finally {
|
|
|
|
a = x + y;
|
2008-11-14 00:59:21 +00:00
|
|
|
System.gc();
|
2008-11-12 17:07:30 +00:00
|
|
|
}
|
|
|
|
expect(a == x + y);
|
2008-11-14 00:59:21 +00:00
|
|
|
} catch (DummyException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2008-11-12 17:07:30 +00:00
|
|
|
}
|
|
|
|
|
2009-06-11 00:11:27 +00:00
|
|
|
private static Object test2(int path) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
switch (path) {
|
|
|
|
case 1:
|
|
|
|
return new Object();
|
|
|
|
|
|
|
|
case 2: {
|
|
|
|
int a = 42;
|
|
|
|
return Integer.valueOf(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
throw new DummyException();
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
System.gc();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
} catch (DummyException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-13 23:49:15 +00:00
|
|
|
private static Object test3(int path1, int path2, int path3) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
switch (path1) {
|
|
|
|
case 1:
|
|
|
|
return new Object();
|
|
|
|
|
|
|
|
case 2: {
|
|
|
|
int a = 42;
|
|
|
|
return Integer.valueOf(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
throw new DummyException();
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
try {
|
|
|
|
switch (path2) {
|
|
|
|
case 1:
|
|
|
|
return new Object();
|
|
|
|
|
|
|
|
case 2: {
|
|
|
|
int a = 42;
|
|
|
|
return Integer.valueOf(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
throw new DummyException();
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
try {
|
|
|
|
switch (path3) {
|
|
|
|
case 1:
|
|
|
|
return new Object();
|
|
|
|
|
|
|
|
case 2: {
|
|
|
|
int a = 42;
|
|
|
|
return Integer.valueOf(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
throw new DummyException();
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
System.gc();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
} catch (DummyException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-12 17:07:30 +00:00
|
|
|
public static void main(String[] args) {
|
2008-11-17 15:21:20 +00:00
|
|
|
test(false, false);
|
|
|
|
test(false, true);
|
|
|
|
test(true, false);
|
2009-06-11 00:11:27 +00:00
|
|
|
|
2009-06-26 21:36:04 +00:00
|
|
|
String.valueOf(test2(1));
|
|
|
|
String.valueOf(test2(2));
|
|
|
|
String.valueOf(test2(3));
|
2009-07-13 23:49:15 +00:00
|
|
|
|
|
|
|
String.valueOf(test3(1, 1, 1));
|
|
|
|
String.valueOf(test3(2, 1, 1));
|
|
|
|
String.valueOf(test3(3, 1, 1));
|
|
|
|
|
|
|
|
String.valueOf(test3(1, 2, 1));
|
|
|
|
String.valueOf(test3(2, 2, 1));
|
|
|
|
String.valueOf(test3(3, 2, 1));
|
|
|
|
|
|
|
|
String.valueOf(test3(1, 3, 1));
|
|
|
|
String.valueOf(test3(2, 3, 1));
|
|
|
|
String.valueOf(test3(3, 3, 1));
|
|
|
|
|
|
|
|
String.valueOf(test3(1, 1, 2));
|
|
|
|
String.valueOf(test3(2, 1, 2));
|
|
|
|
String.valueOf(test3(3, 1, 2));
|
|
|
|
|
|
|
|
String.valueOf(test3(1, 2, 2));
|
|
|
|
String.valueOf(test3(2, 2, 2));
|
|
|
|
String.valueOf(test3(3, 2, 2));
|
|
|
|
|
|
|
|
String.valueOf(test3(1, 3, 2));
|
|
|
|
String.valueOf(test3(2, 3, 2));
|
|
|
|
String.valueOf(test3(3, 3, 2));
|
|
|
|
|
|
|
|
String.valueOf(test3(1, 1, 3));
|
|
|
|
String.valueOf(test3(2, 1, 3));
|
|
|
|
String.valueOf(test3(3, 1, 3));
|
|
|
|
|
|
|
|
String.valueOf(test3(1, 2, 3));
|
|
|
|
String.valueOf(test3(2, 2, 3));
|
|
|
|
String.valueOf(test3(3, 2, 3));
|
|
|
|
|
|
|
|
String.valueOf(test3(1, 3, 3));
|
|
|
|
String.valueOf(test3(2, 3, 3));
|
|
|
|
String.valueOf(test3(3, 3, 3));
|
2008-11-12 17:07:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static class DummyException extends RuntimeException { }
|
|
|
|
}
|