We are going to update our CI system that creates builds from Java 7 to Java 8. Later we would like to migrate projects to Java 8 one by one. Of course, we would like to be able to create bugfix releases for older versions that still use Java 7.
Can we be sure that no issues will appear if we transfer building same source, target version and source version from JDK 7 to JDK 8? We did testing on development machines without any issues.
Before that, we are also gradually updating deployment servers from JRE 7 to JRE 8.
Note that we would like to keep single Java JDK installation on CI system, it gets complicated otherwise.
To make it more clear: I am more interested in same execution outcome, not so much about the same bytecode. Same bytecode would just confirm the first (running on same JRE), if I understand that correctly.
We will not use Java 8 features in code until we have all deployments running on Java 8. So compatibility is not an issue.
Does compiling Java with different versions of JDK and same target and source version produce same bytecode?
There are no guarantees.
Indeed, two .class files created from the same source code using the same compiler with the same options on the same hardware will have the same bytecode, but the files may still be different because of embedded compilation timestamp attributes.
However, if you wanted to compare notionally equivalent bytecode files, this Q&A offers some possible leads:
I expect that you will find that there are some differences between the bytecodes generated by Java 7 and Java 8 compilers, but that this won't matter.
As specified in this blog@https://blogs.oracle.com/darcy/entry/source_target_class_file_version.
Given the same source code, compilers from different releases configured to use the same source and same target (and same bootclasspath!), can still generate different class files because of bug fixes or changes to compiler-internal contracts.
But this problem will not happen to you since you have the same compiler that compiles to different target versions. It just have to emit the specific magic number and byte code compatible for that version. It looks like keeping your version in 1.8 and specifying the target that is either a lower or equal version would work. Looking at this past defect that was addressed, it appears it should work and Oracle works to fix such incompatibilities. http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4175911
Additional resources that should help:
yeah!! it actually depends on the code. in some cases it might generate a different bytecode but normally it generate the same bytecode in normal cases.
Different JDKs will have different Java compilers which may emit different bytecodes for the same source code. The javac compiler has evolved over time.
Different major versions of the Java often emit class files that conform to different versions of the classfile specification.
Even if you restrict yourself to one JDK installation, two runs of the compiler on the same source file will produce non-identical .class files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With