Hi All,
Quick question about optimizing JVM bytecode. Suppose I have the
following Java code:
public static void main(String[] args) {
int a[] = new int[42];
for (int i=0; i < a.length; ++i)
a[i] = 1;
int sum = 0;
for (int i=0; i < a.length; ++i)
sum = sum + a[i] ;
System.out.println(sum);
}
Would it be okay if I wrote an optimizer that pre-evaluated the code
and just generated byte-code that output the value 42? In other words,
did not even bother allocating the array, if it could avoid it? Would
it violate the Java virtual machine spec, or the language spec? If it
is okay, does anyone know of optimizers that do such a pre-
evaluation?
Any guidance would be much appreciated!
Christopher Diggins
http://www.cdiggins.com