CPU constant calculation produces drastically different results on Java 9.
Performing "Options -> Recalculate CPU constant" on an idle system on Java 9:
Each robot will be allowed a maximum of 1780688 nanoseconds per turn on this system.
On Java 8u144:
Each robot will be allowed a maximum of 6320512 nanoseconds per turn on this system.
And robots skip many turns on Java 9:
========================= Round 1 of 10 ========================= SYSTEM: Neuromancer 5.8 (2) skipped turn 257 SYSTEM: Neuromancer 5.8 (2) skipped turn 309 SYSTEM: Neuromancer 5.8 (2) skipped turn 321 SYSTEM: Neuromancer 5.8 (2) skipped turn 322 SYSTEM: Neuromancer 5.8 (2) skipped turn 477 SYSTEM: Neuromancer 5.8 (2) skipped turn 491 SYSTEM: Neuromancer 5.8 (2) skipped turn 610 SYSTEM: Neuromancer 5.8 (2) skipped turn 864 SYSTEM: Neuromancer 5.8 (2) skipped turn 877 SYSTEM: Neuromancer 5.8 (2) skipped turn 889 SYSTEM: Neuromancer 5.8 (2) skipped turn 903 SYSTEM: Neuromancer 5.8 (2) skipped turn 966 SYSTEM: Neuromancer 5.8 (2) skipped turn 1015 SYSTEM: Neuromancer 5.8 (2) skipped turn 1031 SYSTEM: Neuromancer 5.8 (2) skipped turn 1037 SYSTEM: Neuromancer 5.8 (2) skipped turn 1052 SYSTEM: Neuromancer 5.8 (2) skipped turn 1081 SYSTEM: Neuromancer 5.8 (2) skipped turn 1139 SYSTEM: Neuromancer 5.8 (2) skipped turn 1173 SYSTEM: Neuromancer 5.8 (2) skipped turn 1262 SYSTEM: Neuromancer 5.8 (2) skipped turn 1381 SYSTEM: jk.melee.Neuromancer 5.8 (2) has died
This does not happen on Java 8.
This is all on Robocode 1.9.2.6 on Windows 10.
The CpuConstant is calculated with the CpuConstant class in Robocode. The calculation is performed with this loop:
I did some benchmarking on the Math operations for both Java 8 and 9. Here is the results.
Java 8:
random(): 241
atan(x): 111
log(x): 1234
abs(x): 16
sqrt(x): 43
cbrt(x): 115
exp(x): 9144
Java 9:
random(): 246
atan(x): 120
log(x): 81
abs(x): 17
sqrt(x): 44
cbrt(x): 36
exp(x): 75
So... log(x), cbrt(), and exp() seems to be incredible optimized on Java 9, and hence the CpuConstant score gets higher with Java 9, as Robocode thinks the machine power is greater.
I will have to figure out how to perform a new benchmarking, which is compatible with the one from Java 8.
A fix has been made. The CPU benchmark uses mathematical functions. Two of those functions are Math.log() and Math.exp(), which have been greatly optimized in Java 9, meaning that they run faster.
The fix compensates for the faster functions for Java 9, so the CPU constant will be the same under Java 8 and 9.
I have tested this under Wndows 10 with 4 cores with hyber-threading, and Debian Linux with only 2 cores. The fix seems to work under both systems.
Last edit: Flemming N. Larsen 2017-10-06
Looks like an acceptable fix.
With the latest git master version of Robocode, on Windows 10, on Java 8:
On Java 9: