I am writing my own copy of the JVM and would like to test its behavior on some simple numerical operations such as additions, subtractions, numeric overflows, etc. Instead of writing bytecode manually, I thought it would be a good idea to just write simple Java code, javaccompile it to bytecode, and then check the JVM for that bytecode.
The problem is that it javacdoes a lot (very reasonable!) Of built-in optimizations that do not allow testing the code, which I would like to check. For example, one test attempts to verify that integral overflows are handled correctly for all types. Here is one snapshot:
byte min = (byte)-128;
byte max = (byte) 127;
assertTrue((byte)(max + 1) == min);
The generated file .classhas a ((byte)max + 1)hardcoded result as (byte) -128, which completely defeats the test point.
My question is this: is there a way to turn off optimization injavac ? I couldn't find a command line switch for this, although maybe I just didn't look complicated enough. If there is no way to do this, is there another Java compiler that has the ability to compile all optimizations turned off?
source
share