-
-
Save jpbempel/b40e5081b98d9021116f845d8adf0be1 to your computer and use it in GitHub Desktop.
Evidence of Safepoint bias for AsyncGetCallTrace (AsyncProfiler)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Profile { | |
static byte[] buffer = new byte[1234]; | |
static byte[] dst = new byte[1234]; | |
static boolean result; | |
public static void main(String[] args) throws Exception { | |
int res = 0; | |
for (int i = 0; i < 2_000_000_000; i++) { | |
res += noLoopBench(i); | |
} | |
if (res > 0 && System.currentTimeMillis() > 0) { | |
System.out.println("done: " + res); | |
} | |
Thread.sleep(1000); | |
} | |
public static int bench(int idx) { | |
byte b = 0; | |
for (int i = 0; i < buffer.length; i++) { | |
dst[i] = buffer[i]; | |
} | |
return dst[buffer.length-1] == 1 ? buffer[0] : buffer[1]; | |
} | |
public static int inlinedBench(int idx) { | |
int res = 0; | |
res += compute1(idx); | |
res += compute1(res); | |
res += compute1(res); | |
res += compute1(res); | |
res += compute1(res); | |
res += compute1(res); | |
res += compute1(res); | |
res += compute1(res); | |
res += compute1(res); | |
res += compute1(res); | |
res += compute1(res); | |
res += compute1(res); | |
res += compute1(res); | |
res += compute1(res); | |
res += compute1(res); | |
res += compute1(res); | |
res += compute1(res); | |
res += compute1(res); | |
res += compute1(res); | |
res += compute1(res); | |
res += compute1(res); | |
res += compute1(res); | |
res += compute1(res); | |
res += compute1(res); | |
res += compute1(res); | |
res += compute1(res); | |
res += compute1(res); | |
res += compute1(res); | |
return res; | |
} | |
private static int compute1(int value) { | |
return (value % 7) + value * 31 + compute2(value); | |
} | |
private static int compute2(int value) { | |
return (value * 53) % 13 - value + compute3(value); | |
} | |
private static int compute3(int value) { | |
return value * 1003 - (value * 13 % 7); | |
} | |
public static int loopsBench(int idx) { | |
int res = 0; | |
for (int i = 0; i < 5; i++) { | |
dst[i] = buffer[i]; | |
} | |
res += dst[buffer.length-1] == 1 ? buffer[0] : buffer[1]; | |
for (int i = 0; i < 5; i++) { | |
dst[i] = buffer[i]; | |
} | |
res += dst[buffer.length-1] == 1 ? buffer[0] : buffer[1]; | |
for (int i = 0; i < 5; i++) { | |
dst[i] = buffer[i]; | |
} | |
res += dst[buffer.length-1] == 1 ? buffer[0] : buffer[1]; | |
for (int i = 0; i < 5; i++) { | |
dst[i] = buffer[i]; | |
} | |
res += dst[buffer.length-1] == 1 ? buffer[0] : buffer[1]; | |
for (int i = 0; i < 5; i++) { | |
dst[i] = buffer[i]; | |
} | |
res += dst[buffer.length-1] == 1 ? buffer[0] : buffer[1]; | |
for (int i = 0; i < 5; i++) { | |
dst[i] = buffer[i]; | |
} | |
res += dst[buffer.length-1] == 1 ? buffer[0] : buffer[1]; | |
for (int i = 0; i < 5; i++) { | |
dst[i] = buffer[i]; | |
} | |
res += dst[buffer.length-1] == 1 ? buffer[0] : buffer[1]; | |
for (int i = 0; i < 5; i++) { | |
dst[i] = buffer[i]; | |
} | |
res += dst[buffer.length-1] == 1 ? buffer[0] : buffer[1]; | |
for (int i = 0; i < 5; i++) { | |
dst[i] = buffer[i]; | |
} | |
res += dst[buffer.length-1] == 1 ? buffer[0] : buffer[1]; | |
for (int i = 0; i < 5; i++) { | |
dst[i] = buffer[i]; | |
} | |
res += dst[buffer.length-1] == 1 ? buffer[0] : buffer[1]; | |
return res; | |
} | |
public static int noLoopBench(int idx) { | |
int res = idx * idx; | |
res += (res % 7) + idx * 31; | |
res -= (res * 53) % 13 - idx; | |
res += res * 1003 - (idx * 13 % 7); | |
res += (res % 19) + idx * 37; | |
res -= (res * 71) % 7 - idx; | |
res += res * 97 - (idx * 53 % 29); | |
res += (res % 7) + idx * 31; | |
res -= (res * 53) % 13 - idx; | |
res += res * 1003 - (idx * 13 % 7); | |
res += (res % 19) + idx * 37; | |
res -= (res * 71) % 7 - idx; | |
res += res * 97 - (idx * 53 % 29); | |
res += (res % 7) + idx * 31; | |
res -= (res * 53) % 13 - idx; | |
res += res * 1003 - (idx * 13 % 7); | |
res += (res % 19) + idx * 37; | |
res -= (res * 71) % 7 - idx; | |
res += res * 97 - (idx * 53 % 29); | |
res += (res % 7) + idx * 31; | |
res -= (res * 53) % 13 - idx; | |
res += res * 1003 - (idx * 13 % 7); | |
res += (res % 19) + idx * 37; | |
res -= (res * 71) % 7 - idx; | |
res += res * 97 - (idx * 53 % 29); | |
res += (res % 7) + idx * 31; | |
res -= (res * 53) % 13 - idx; | |
res += res * 1003 - (idx * 13 % 7); | |
res += (res % 19) + idx * 37; | |
res -= (res * 71) % 7 - idx; | |
res += res * 97 - (idx * 53 % 29); | |
res += (res % 7) + idx * 31; | |
res -= (res * 53) % 13 - idx; | |
res += res * 1003 - (idx * 13 % 7); | |
res += (res % 19) + idx * 37; | |
res -= (res * 71) % 7 - idx; | |
res += res * 97 - (idx * 53 % 29); | |
res += (res % 7) + idx * 31; | |
res -= (res * 53) % 13 - idx; | |
res += res * 1003 - (idx * 13 % 7); | |
res += (res % 19) + idx * 37; | |
res -= (res * 71) % 7 - idx; | |
res += res * 97 - (idx * 53 % 29); | |
res += (res % 7) + idx * 31; | |
res -= (res * 53) % 13 - idx; | |
res += res * 1003 - (idx * 13 % 7); | |
res += (res % 19) + idx * 37; | |
res -= (res * 71) % 7 - idx; | |
res += res * 97 - (idx * 53 % 29); | |
return res; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment