Skip to content

Instantly share code, notes, and snippets.

@jordansissel
Created October 26, 2017 18:36
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jordansissel/fd7a4ea295760b5657e2e8f2dcae1e85 to your computer and use it in GitHub Desktop.
public class Main {
public static void main(String[] args) {
X x = new X();
Long value = 500L;
if (args.length != 1) {
System.out.println("Usage: Main <iterations>");
System.exit(1);
}
int count = Integer.parseInt(args[0]);
for (int i = 0; i < 1000000; i++) {
x.set(value); // dynamic inference
x.setLong(value);
}
}
}
% javac Main.java && java -XX:+PrintCompilation -XX:+UnlockDiagnosticVMOptions -XX:+PrintInlining Main 1000000 | grep X::set
     64   16       3       X::set (6 bytes)
     64   17       3       X::setLong (6 bytes)
     64   18       1       X::set (6 bytes)
     64   19       1       X::setLong (6 bytes)
     64   16       3       X::set (6 bytes)   made not entrant
     65   17       3       X::setLong (6 bytes)   made not entrant
                              @ 51   X::set (6 bytes)
                              @ 56   X::setLong (6 bytes)
                              @ 51   X::set (6 bytes)
                              @ 56   X::setLong (6 bytes)
                              @ 51   X::set (6 bytes)   inline (hot)
                              @ 56   X::setLong (6 bytes)   inline (hot)
public class X {
private Object value;
public <T> void set(T value) {
this.value = value;
}
public void setLong(Long value) {
this.value = value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment