Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Machine > Optimization qu...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 790 of 803
Post > Topic >>

Optimization question

by Christopher Diggins <cdiggins@[EMAIL PROTECTED] > Sep 22, 2007 at 02:55 PM

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




 3 Posts in Topic:
Optimization question
Christopher Diggins <c  2007-09-22 14:55:05 
Re: Optimization question
Joshua Cranmer <Pidgeo  2007-09-22 23:01:53 
Re: Optimization question
glen herrmannsfeldt <g  2007-09-27 18:06:08 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed May 14 5:59:02 CDT 2008.