I've been digging through Java lambda expression bytecode as compiled by my OpenJDK compiler, and I'm wondering, can lambda expression bytecode vary by compiler/runtime? I'd like to know that my inspection logic will work across platforms, or not.
-
2What exactly are you trying to inspect? Note in particular that if the Groovy 3 compiler gets off the ground, with its support for Java 8-style lambdas, it's likely to emit significantly different bytecode.chrylis -cautiouslyoptimistic-– chrylis -cautiouslyoptimistic-2016-10-16 02:36:56 +00:00Commented Oct 16, 2016 at 2:36
-
openjdk's javac is not the only java compiler in existence, ecj is a commonly used alternative for example.the8472– the84722016-10-16 19:24:28 +00:00Commented Oct 16, 2016 at 19:24
1 Answer
can lambda expression bytecode vary by compiler/runtime?
In theory yes. The JLS does NOT specify that particular bytecodes / sequences must be generated.
You would need to check the bytecodes emitted by existing Java 8 & Java 9 compilers to see how much they differ. (And that doesn't tell you about compilers / versions that are yet to be written!)
I'd like to know that my inspection logic will work across platforms, or not.
The solution should be to build a comprehensive set of test cases and run them against the code produced by all Java compilers that you want to support.
In short: test it.