FIX: JIT: ArrayIndexOutOfBoundsException Improperly Thrown

ID: Q191933

The information in this article applies to:

SYMPTOMS

When using threads and arrays you will see the following errors:

   java.lang.ArrayIndexOutOfBoundsException: nnn

   java.lang.IllegalMonitorStateException

   The instruction at "0xnnnnnnnn" referenced memory at "0xnnnnnnnn." The
   memory could not be "read."

CAUSE

This is caused by a bug in the JIT compiler.

RESOLUTION

Update your virtual machine to the latest version. If you cannot upgrade your virtual machine, it is also possible to disable the JIT compiler. In Internet Explorer 4.01 the JIT setting can be found under View, Internet Options, Advanced, Java JIT compiler enabled.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug has been corrected in the virtual machine that ships with Internet Explorer 4.01-SP1, SDK for Java 2.02, and SDK for Java 3.0.

MORE INFORMATION

Steps to Reproduce Behavior

Save the following as test.java.

   import java.lang.Runtime;
   import java.util.Vector;

   class memtest implements Runnable{
   private Vector v = new Vector();
   private int nextThread = 1;
   memtest ()
   {
   }

   public synchronized int getThreadNo()
   {
      return nextThread++;
   }

   public void run()
   {
      int threadNo = getThreadNo();

      Runtime rt = Runtime.getRuntime();

      for (int i=0;;i++)
      {

         long freeMem = rt.freeMemory();
         long totalMem = rt.totalMemory();

         System.out.println(     "Thread: " + threadNo
                            + ", Iteration: " + i
                        + ", Free Memory: " + freeMem
                        + ", Total Memory: " + totalMem);

         String s = new String("");

         for (int j = 0; j < 1000; j++)
         {
            s = s + ".";
         }

         try
         {
            Thread.sleep(1000);
         }
         catch (Exception ex)
         {
         }
      }}

   public void _main()
   {
      for (int i = 0; i < 100; i++)
      {
         Thread t = new Thread(this);
         v.addElement(t);
         t.start();
         try
         {
            Thread.sleep(100);
         }
         catch (Exception ex)
         {
         }
      }
   }

   public static void main( String [] args )
   {
      memtest b = new memtest();
      b._main();
   }

   }

Compile the above code. Open a console window and run JVIEW test > nul

You will see the following errors on your console:

   java.lang.ArrayIndexOutOfBoundsException: nnn
   java.lang.IllegalMonitorStateException

   The instruction at "0xnnnnnnnn" referenced memory at "0xnnnnnnnn." The
   memory could not be "read."

REFERENCES

For the latest Knowledge Base articles and other support information on Visual J++ and the SDK for Java, see the following pages on the Microsoft Technical Support site:

   http://support.microsoft.com/support/visualj/ 
   http://support.microsoft.com/support/java/ 

Additional query words:
Keywords          : kbJava 
Version           : WINDOWS:1.0,1.1,1.5,1.51,2.0,2.01
Platform          : WINDOWS
Issue type        : kbbug
Solution Type     : kbfix

Last Reviewed: September 2, 1998