Skip to content

Commit 19d622b

Browse files
committed
Add tests to verify that synthetic method removal is performed
These check that direct and indirect clinit wrappers, as well as stub class synthetic static initialisers, are removed if they are generated but not subsequently called.
1 parent adc9fd4 commit 19d622b

18 files changed

+122
-0
lines changed
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
public class Test {
2+
3+
// Refers to, but never instantiates or refers to static fields of, Unused.
4+
// Thus a clinit-wrapper for Unused should be created, but subsequently
5+
// discarded.
6+
Unused u;
7+
8+
public static void main() {
9+
10+
}
11+
12+
}
13+
14+
class Unused {
15+
16+
static int x;
17+
18+
static {
19+
x = 1;
20+
}
21+
22+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CORE
2+
Test.class
3+
--show-goto-functions
4+
java::Unused::clinit_wrapper
5+
Unused\.<clinit>\(\)
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CORE
2+
Test.class
3+
--lazy-methods --show-goto-functions
4+
--
5+
java::Unused::clinit_wrapper
6+
Unused\.<clinit>\(\)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CORE
2+
Test.class
3+
--lazy-methods
4+
VERIFICATION SUCCESSFUL
5+
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
public class Test {
2+
3+
// Refers to, but never instantiates or refers to static fields of, Unused.
4+
// Thus a clinit-wrapper for Unused should be created, but subsequently
5+
// discarded.
6+
Unused1 u;
7+
8+
public static void main() {
9+
10+
}
11+
12+
}
13+
14+
class Unused1 extends Unused2 {
15+
16+
}
17+
18+
class Unused2 {
19+
20+
static int x;
21+
22+
static {
23+
x = 1;
24+
}
25+
26+
}
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
Test.class
3+
--show-goto-functions
4+
java::Unused1::clinit_wrapper
5+
java::Unused2::clinit_wrapper
6+
Unused2\.<clinit>\(\)
7+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
Test.class
3+
--lazy-methods --show-goto-functions
4+
--
5+
java::Unused1::clinit_wrapper
6+
java::Unused2::clinit_wrapper
7+
Unused2\.<clinit>\(\)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CORE
2+
Test.class
3+
--lazy-methods
4+
VERIFICATION SUCCESSFUL
5+
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
public class Test {
2+
3+
public static void main() {
4+
5+
}
6+
7+
public static Opaque unused() {
8+
9+
// Should cause jbmc to create a synthetic static initialiser for Opaque,
10+
// but because this function isn't called by main() it should then be
11+
// cleaned up as unused.
12+
return Opaque.field;
13+
14+
}
15+
16+
}
17+
18+
class Opaque {
19+
20+
public static Opaque field;
21+
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CORE
2+
Test.class
3+
--show-goto-functions
4+
java::Opaque\.<clinit>:\(\)V
5+
java::Opaque::clinit_wrapper
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CORE
2+
Test.class
3+
--lazy-methods --show-goto-functions
4+
--
5+
java::Opaque\.<clinit>:\(\)V
6+
java::Opaque::clinit_wrapper
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CORE
2+
Test.class
3+
--lazy-methods
4+
VERIFICATION SUCCESSFUL
5+

0 commit comments

Comments
 (0)