Re: JVM verifier vs. naive code generator

glen herrmannsfeldt <gah@ugcs.caltech.edu>
Mon, 21 Mar 2011 04:46:34 +0000 (UTC)

          From comp.compilers

Related articles
JVM verifier vs. naive code generator sandmann@cs.au.dk (Soeren Sandmann) (2011-03-20)
Re: JVM verifier vs. naive code generator gah@ugcs.caltech.edu (glen herrmannsfeldt) (2011-03-21)
Re: JVM verifier vs. naive code generator Pidgeot18@verizon.invalid (Joshua Cranmer) (2011-03-21)
| List of all articles for this month |

From: glen herrmannsfeldt <gah@ugcs.caltech.edu>
Newsgroups: comp.compilers
Date: Mon, 21 Mar 2011 04:46:34 +0000 (UTC)
Organization: A noiseless patient Spider
References: 11-03-048
Keywords: Java, code
Posted-Date: 21 Mar 2011 22:08:47 EDT

Soeren Sandmann <sandmann@cs.au.dk> wrote:
> Consider this fragment of Java code:


> int i, j;
> i = 100;
> for (i >= 0 && (j = 10) == 10)
> i = j;


> This is correct; j is not used without being initialized, and the
> Java compiler accepts it without complaints.


(snip about JVM code that might or will fail verification)


> Is there a standard way to get around this problem? Ie., a
> systematic way to ensure that the code generated will not only be
> correct, but also verifiable?


The usual way is to put an initializer on the declaration. I
sometimes add a comment that it is due to a compiler that can't
reliably detect that it is actually correct, but usually not.


I do sometimes wonder why they didn't just initialize local variables
to zero (like they do arrays). It would seem easier than the whole
testing process. My guess is to force people to go back and look at
the code, to be sure that it really does what they expect.


Then again, some may just put the initializer on and not reread
the code.


Did you try something like:


  if(any boolean) i=1;
  else i=2;


It might be better now, but didn't always figure that one out.


-- glen


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.