Java Magazine, May/June 2018
ORACLE COM JAVAMAGAZINE MAY JUNE 2018 83 inside the jvm In the following JMH benchmark the test methods allocate nonescaping arrays of 63 64 and 65 elements The array size of 63 is tested to ensure that 64 is not faster than 65 simply because of memory alignment In each test only the first two array elements a 0 and a 1 are used Note however that the limitation on escape analysis is dependent only on the array length not on how many elements of the array are actually used @ State Scope Thread @ BenchmarkMode Mode Throughput @ OutputTimeUnit TimeUnit SECONDS public class EscapeTestArraySize private java util Random random new java util Random @ Benchmark public long arraySize63 int a new int 63 a 0 random nextInt a 1 random nextInt return a 0 a 1 @ Benchmark public long arraySize64 int a new int 64 a 0 random nextInt a 1 random nextInt
You must have JavaScript enabled to view digital editions.