Bug 117120

Summary: [compiler] VerifyError: Expecting to find integer on stack
Product: [Eclipse Project] JDT Reporter: Art Dyer <art.dyer>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1.2   
Hardware: PC   
OS: Windows 2000   
Whiteboard:
Attachments:
Description Flags
patch for HEAD none

Description Art Dyer CLA 2005-11-18 13:40:37 EST
Found on 3.1, still present in 3.2M3 (Nov 02).

public class Foo
{
  public static float f0;
  
  public static void main(String[] args)
  {
    long l11 = -26;
    
    System.out.println(
        (((l11 < f0++) || true) != ((true && true) && (!(false || true)))));
  }
}

java reports:

java.lang.VerifyError: (class: Foo, method: main signature: 
([Ljava/lang/String;)V) Expecting to find integer on stack

At offset 22, there should be a PrintStream and an int (boolean) on the stack, 
but there is only a PrintStream:

public static void main(java.lang.String[]);
  Code:
   0:	ldc2_w	#15; //long -26l
   3:	lstore_1
   4:	getstatic	#17; //Field java/lang/System.out:Ljava/io/PrintStream;
   7:	lload_1
   8:	l2f
   9:	getstatic	#23; //Field f0:F
   12:	dup
   13:	fconst_1
   14:	fadd
   15:	putstatic	#23; //Field f0:F
   18:	fcmpg
   19:	iflt	22
   22:	invokevirtual	#25; //Method java/io/PrintStream.println:(Z)V
   25:	return
Comment 1 Art Dyer CLA 2005-11-18 13:56:08 EST
FWIW, Jikes elides the floating-point compare entirely since it has no bearing 
on the value of the expression, which is always true:

   0:	ldc2_w	#11; //long -26l
   3:	lstore_1
   4:	getstatic	#18; //Field java/lang/System.out:Ljava/io/PrintStream;
   7:	getstatic	#20; //Field f0:F
   10:	fconst_1
   11:	fadd
   12:	putstatic	#20; //Field f0:F
   15:	iconst_1
   16:	invokevirtual	#26; //Method java/io/PrintStream.println:(Z)V
   19:	return

Javac does this (correct, but amusing):
   ...
   18:	fcmpg
   19:	iflt	22  // if less, goto 22, else goto 22 anyway
   22:	iconst_1    // put 1 on the stack ...
   23:	ifeq	30  // ... and see if it's equal to zero
   26:	iconst_1
   27:	goto	31
   30:	iconst_0    // this is unreachable
   31:	invokevirtual	#6; //Method java/io/PrintStream.println:(Z)V
Comment 2 Philipe Mulet CLA 2005-11-21 06:56:59 EST
Added BooleanTest#test018
Comment 3 Philipe Mulet CLA 2005-11-24 09:08:50 EST
Indeed, our boolean optimization failed in this case. Tuned implementation and now we produce same as jikes:

public static void main(String[] args);
     0  ldc2_w <Long -26> [18]
     3  lstore_1 [l11]
     4  getstatic System.out : PrintStream [20]
     7  getstatic X.f0 : float [26]
    10  fconst_1
    11  fadd
    12  putstatic X.f0 : float [26]
    15  iconst_1
    16  invokevirtual PrintStream.println(boolean) : void [28]
    19  return

Comment 4 Philipe Mulet CLA 2005-11-24 09:09:23 EST
Created attachment 30549 [details]
patch for HEAD
Comment 5 Philipe Mulet CLA 2005-11-24 09:11:19 EST
Added BooleanTest#test018-test030
Comment 6 Philipe Mulet CLA 2005-11-25 12:52:12 EST
Fixed both in HEAD and 3.1.2 stream. Rewrote boolean codegen to take out the flag OnlyValueRequiredMASK which was causing grief. 
Comment 7 Olivier Thomann CLA 2005-12-13 10:33:26 EST
Verified for 3.2M4 in I20051212-2000
Comment 8 Olivier Thomann CLA 2006-01-09 11:17:06 EST
Verified for 3.1.2 in M20060109-0800.