This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: switch constant issue
- From: Jeff Sturm <jsturm at one-point dot com>
- To: Andrew Haley <aph at redhat dot com>
- Cc: steve <steve at netfuel dot com>, <java at gcc dot gnu dot org>
- Date: Mon, 9 Jun 2003 13:51:37 -0400 (EDT)
- Subject: Re: switch constant issue
On Mon, 9 Jun 2003, Andrew Haley wrote:
> > http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/class.c.diff?r1=1.150&r2=1.151&f=h
>
> I guess this is OK, but I'm not sure. It does rather break
> -fno-assume-compiled in that the constant uses early binding, so we
> might up with a different value for a constant that the one in its
> definition.
Good point. However, javac does an equivalent optimization:
[jsturm@triton tmp]$ cat Constants.java
public class Constants {
public static final int DEBUG = 1;
}
[jsturm@triton tmp]$ cat Main.java
public class Main {
public static void main(String[] args) {
System.out.println(Constants.DEBUG);
}
}
[jsturm@triton tmp]$ javac Main.java
[jsturm@triton tmp]$ javap -c Main
...
Method void main(java.lang.String[])
0 getstatic #2 <Field java.io.PrintStream out>
--> 3 iconst_1
4 invokevirtual #3 <Method void println(int)>
7 return
My guess is they wanted to support pseudo-conditional compilation with
this common idiom:
public static final boolean DEBUG = false;
...
if (DEBUG) {
...
}
Jeff