Bug 68440 - [1.5] VerifyError with new for loop
Summary: [1.5] VerifyError with new for loop
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.1 M1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-06-23 20:36 EDT by Igor Fedorenko CLA
Modified: 2005-01-11 11:02 EST (History)
0 users

See Also:


Attachments
ForEachTest.class (689 bytes, application/octet-stream)
2004-06-28 23:37 EDT, Igor Fedorenko CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Igor Fedorenko CLA 2004-06-23 20:36:35 EDT
Executing the following code results in java.lang.VerifyError: (class:
test/cheetah/ForEachTest, method: test signature: ()V) Expecting to find array
of objects or arrays on stack

cheetah from CVS as of June 23, 8:20pm EDT. Sun JDK 1.5 beta2.

=========================================
package test.cheetah;
public class ForEachTest {
    Object[] array = {
    };
    void test() {
        for (Object object : array) {
            String str = object.toString();
        }
    }
    public static void main(String[] args) {
        new ForEachTest().test();
    }
}
=========================================
Comment 1 Olivier Thomann CLA 2004-06-28 21:23:41 EDT
I cannot reproduce with HEAD contents.
Comment 2 Olivier Thomann CLA 2004-06-28 22:18:23 EDT
Closing as WORKSFORME.
Please reopen if you still get it with a new cheetah drop.
Comment 3 Igor Fedorenko CLA 2004-06-28 23:37:07 EDT
You meant "latest from JDK_1_5 branch", right? I can reproduce this problem with
the latest from JDK_1_5 branch and with both SUN 1.5 beta2 and b57. See bug
68133 for the description of my environment.
Comment 4 Igor Fedorenko CLA 2004-06-28 23:37:40 EDT
Created attachment 12875 [details]
ForEachTest.class
Comment 5 Olivier Thomann CLA 2004-06-29 04:16:20 EDT
I will continue to investigate.
Comment 6 Olivier Thomann CLA 2004-06-29 04:57:04 EDT
If I run it using the command line, it works fine. If I do it in self-hosting,
it fails. I will investigate this issue.
Comment 7 Olivier Thomann CLA 2004-06-29 05:01:14 EDT
The bug occurs if I have -perserveAllLocals on the command line. If I don't, it
works fine.
Comment 8 Olivier Thomann CLA 2004-06-29 05:15:57 EDT
The problem comes from the fact that str and the secret local variable are
sharing the same spot.
  // Method descriptor  #8 ()V
  // Stack: 2, Locals: 5
  void test();
     0  aload_0
     1  getfield #13 <Field ForEachTest.array [Ljava/lang/Object;>
     4  astore 4 <==== Index 4 for the array local variable.
     6  iconst_0
     7  istore_2
     8  aload 4
    10  arraylength
    11  istore_3
    12  goto 37
    15  aload 4
    17  iload_2
    18  aaload
    19  astore_1
    20  aload_1
    21  invokevirtual #22 <Method java/lang/Object.toString()Ljava/lang/String;>
    24  astore 4
    26  getstatic #28 <Field java/lang/System.out Ljava/io/PrintStream;>
    29  aload 4
    31  invokevirtual #34 <Method java/io/PrintStream.println(Ljava/lang/String;)V>
    34  iinc 2 1
    37  iload_2
    38  iload_3
    39  if_icmplt 15
    42  return
      Line numbers:
        [pc: 0, line: 5]
        [pc: 20, line: 6]
        [pc: 26, line: 7]
        [pc: 34, line: 5]
        [pc: 42, line: 9]
      Local variable table:
        [pc: 0, pc: 43] local: this index: 0 type: LForEachTest;
        [pc: 20, pc: 42] local: object index: 1 type: Ljava/lang/Object;
        [pc: 26, pc: 34] local: str index: 4 type: Ljava/lang/String; <=== index
4 for str

I need to check how this spot can be shared.
Comment 9 Philipe Mulet CLA 2004-06-29 06:54:47 EDT
#array secret variable was incorrectly inserted after the block had been 
resolved, and thus was (incorrectly) assumed to be shareable.

Added regression test: ForeachStatementTest#test026.