I\'m about to upgrade a tomcat installation from version 6.0 to version 8.5, and also upgrading the JVM from 6 to 8. Our java code is compiled with java 6 as for now.
I
Is anything gained by compiling java 6 code with a java 8 compiler targeted to java 6 compared to if the code was compiled with a java 6 compiler?
No.
There is absolutely no performance gain, since the java compiler don't perform any kind of optimization, not even obvious ones.
Any optimization that could be performed on the bytecode produced by javac
is done by the JIT engine once your application is running.
Edit: Look at pveentjer comment, a few simple optimizations (e.g. constant resolution) are performed by javac. But i'm still confident that the answer regarding the differences between 6 and 8 is still "no".
As you already know, there is no real requirement for compiling Java code with the latest versions of the language. It is up to you.
Common points to consider:
I would (and I encourage you) to check the release notes to see what changes, improvements, compatibility constraints etc. are introduced in the new JVM version.