jit

The output -1 becomes a slash in the loop

拥有回忆 提交于 2020-07-31 06:48:27
问题 Surprisingly, the following code outputs: / -1 The code: public class LoopOutPut { public static void main(String[] args) { LoopOutPut loopOutPut = new LoopOutPut(); for (int i = 0; i < 30000; i++) { loopOutPut.test(); } } public void test() { int i = 8; while ((i -= 3) > 0) ; String value = i + ""; if (!value.equals("-1")) { System.out.println(value); System.out.println(i); } } } I tried many times to determine how many times this would occur, but, unfortunately, it was ultimately uncertain,

“Loop unswitching” optimization is not working

拜拜、爱过 提交于 2020-07-07 06:37:46
问题 I heard that Java supports "Loop Unswitching", so I simply tested it in JMH. I thought they would be exactly the same after JIT. Why is this? private final int TIMES = 1_000_000; private boolean bool; private Random r = new Random(93); @Setup(Level.Invocation) public void fresh() { bool = r.nextBoolean(); } @Benchmark public void test1(Blackhole bh) { for (int i = 0; i < TIMES; i++) { if (bool) { bh.consume(1); } else { bh.consume(2); } } } @Benchmark public void test2(Blackhole bh) { if

“Loop unswitching” optimization is not working

﹥>﹥吖頭↗ 提交于 2020-07-07 06:37:40
问题 I heard that Java supports "Loop Unswitching", so I simply tested it in JMH. I thought they would be exactly the same after JIT. Why is this? private final int TIMES = 1_000_000; private boolean bool; private Random r = new Random(93); @Setup(Level.Invocation) public void fresh() { bool = r.nextBoolean(); } @Benchmark public void test1(Blackhole bh) { for (int i = 0; i < TIMES; i++) { if (bool) { bh.consume(1); } else { bh.consume(2); } } } @Benchmark public void test2(Blackhole bh) { if

“Loop unswitching” optimization is not working

半腔热情 提交于 2020-07-07 06:35:06
问题 I heard that Java supports "Loop Unswitching", so I simply tested it in JMH. I thought they would be exactly the same after JIT. Why is this? private final int TIMES = 1_000_000; private boolean bool; private Random r = new Random(93); @Setup(Level.Invocation) public void fresh() { bool = r.nextBoolean(); } @Benchmark public void test1(Blackhole bh) { for (int i = 0; i < TIMES; i++) { if (bool) { bh.consume(1); } else { bh.consume(2); } } } @Benchmark public void test2(Blackhole bh) { if

“Loop unswitching” optimization is not working

烂漫一生 提交于 2020-07-07 06:34:47
问题 I heard that Java supports "Loop Unswitching", so I simply tested it in JMH. I thought they would be exactly the same after JIT. Why is this? private final int TIMES = 1_000_000; private boolean bool; private Random r = new Random(93); @Setup(Level.Invocation) public void fresh() { bool = r.nextBoolean(); } @Benchmark public void test1(Blackhole bh) { for (int i = 0; i < TIMES; i++) { if (bool) { bh.consume(1); } else { bh.consume(2); } } } @Benchmark public void test2(Blackhole bh) { if