Skip to content

Commit

Permalink
Add tests to verify that synthetic method removal is performed
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
smowton committed Feb 14, 2018
1 parent adc9fd4 commit 19d622b
Show file tree
Hide file tree
Showing 18 changed files with 122 additions and 0 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
public class Test {

// Refers to, but never instantiates or refers to static fields of, Unused.
// Thus a clinit-wrapper for Unused should be created, but subsequently
// discarded.
Unused u;

public static void main() {

}

}

class Unused {

static int x;

static {
x = 1;
}

}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CORE
Test.class
--show-goto-functions
java::Unused::clinit_wrapper
Unused\.<clinit>\(\)

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CORE
Test.class
--lazy-methods --show-goto-functions
--
java::Unused::clinit_wrapper
Unused\.<clinit>\(\)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CORE
Test.class
--lazy-methods
VERIFICATION SUCCESSFUL

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
public class Test {

// Refers to, but never instantiates or refers to static fields of, Unused.
// Thus a clinit-wrapper for Unused should be created, but subsequently
// discarded.
Unused1 u;

public static void main() {

}

}

class Unused1 extends Unused2 {

}

class Unused2 {

static int x;

static {
x = 1;
}

}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CORE
Test.class
--show-goto-functions
java::Unused1::clinit_wrapper
java::Unused2::clinit_wrapper
Unused2\.<clinit>\(\)

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CORE
Test.class
--lazy-methods --show-goto-functions
--
java::Unused1::clinit_wrapper
java::Unused2::clinit_wrapper
Unused2\.<clinit>\(\)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CORE
Test.class
--lazy-methods
VERIFICATION SUCCESSFUL

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
public class Test {

public static void main() {

}

public static Opaque unused() {

// Should cause jbmc to create a synthetic static initialiser for Opaque,
// but because this function isn't called by main() it should then be
// cleaned up as unused.
return Opaque.field;

}

}

class Opaque {

public static Opaque field;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CORE
Test.class
--show-goto-functions
java::Opaque\.<clinit>:\(\)V
java::Opaque::clinit_wrapper
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CORE
Test.class
--lazy-methods --show-goto-functions
--
java::Opaque\.<clinit>:\(\)V
java::Opaque::clinit_wrapper
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CORE
Test.class
--lazy-methods
VERIFICATION SUCCESSFUL

0 comments on commit 19d622b

Please sign in to comment.