[JSR308] Resolution of optimization issue

Michael Ernst mernst at csail.mit.edu
Mon Jun 4 13:04:22 EDT 2007


I had asked whether optimizations by Java-to-bytecode compilers that might
interfere with retaining, in the class file, all annotations that appear in
the source code.  No one came up with any examples, so I plan to add the
following text to the JSR 308 working document.

  If a programmer places an annotation (with class file or runtime
  retention) on the type of a value, then the compiler is required to
  preserve that annotation in the compiled class file.  This restriction is
  unobjectionable for several reasons.

  First, Java-to-bytecode compilers rarely perform sophisticated
  optimizations, since the bytecode-to-native (JIT) compiler is the major
  determinant in Java program performance.

  Second, it seems unlikely that two identical, non-trivial expressions
  would be differently annotated.

  Third, the compiler workarounds are simple.  Suppose that a compiler
  performs common subexpression elimination on two expressions that are
  identical except for their type annotations.  Three implementation
  strategies are for the compiler to not perform the optimization when the
  annotations differ, to create a single expression with both of the
  annotations, or to create an unannotated expression and copy its value
  into two variables with differently-annotated types.

                    -Mike



More information about the JSR308 mailing list