Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.