Microsoft KB Archive/191933

= FIX: JIT: ArrayIndexOutOfBoundsException Improperly Thrown =

Article ID: 191933

Article Last Modified on 8/25/2005

-

APPLIES TO


 * Microsoft Visual J++ 1.0 Standard Edition
 * Microsoft Visual J++ 1.1 Standard Edition
 * Microsoft Software Development Kit for Java 1.0
 * Microsoft Software Development Kit for Java 1.5
 * Microsoft Software Development Kit for Java 1.51
 * Microsoft Software Development Kit for Java 2.02
 * Microsoft Software Development Kit for Java 2.01
 * Microsoft Java Virtual Machine

-



This article was previously published under Q191933



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.



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."

