Name: dgC58589 Date: 12/17/97
The following code works great when you use
javac, but produces unexpected results when using
javac -O
class Test
{
public static void main (String argc[])
{
System.out.println ("test (0) = " + test (0));
System.out.println ("test (1) = " + test (1));
System.out.println ("test (0) = " + test (0));
System.out.println ("test (1) = " + test (1));
}
private static String test (int i)
{
switch (i) {
case 0:
return ("found 0");
case 1:
return ("found 1");
}
return ("Error");
}
}
More specifically...
>> javac Test.java
>> java Test
test (0) = found 0
test (1) = found 1
test (0) = found 0
test (1) = found 1
Okay all is well, but then we try it with
optimizations.
>> javac -O Test.java
>> java Test
test (0) = Error
test (1) = found 0
test (0) = found 0
test (1) = found 0
Hmm, that doesn't look right.
Notice there is two problems.
The first result is wrong and
all of the rest return 0 which is the first case.
So we have three out of four incorrect.
Note: The results don't change if you return int
or anything else. It seems to have something to
do with argument passing and the stack.
-Paul Hill, ###@###.###
-Wade Rees, ###@###.###
(Review ID: 22047)
======================================================================
- duplicates
-
JDK-4118025 javac: Incorrect inlining code generated with -O flag
- Closed