Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4750681
Votes 0
Synopsis Bad exception in the copying loop
Category hotspot:compiler2
Reported Against 1.4.1 , mantis
Release Fixed 1.4.0_04, 1.4.1_02(Bug ID:2058830) , 1.4.2(mantis) (Bug ID:2058831)
State 10-Fix Delivered, bug
Priority: 1-Very High
Related Bugs 4629512 , 4752235
Submit Date 20-SEP-2002
Description
The 1.4.2 server VM throws a bad ArrayIndexOutOfBoundsException in the copying loop (similar to the previously fixed problem - 4629512 ). 

The test case below exits because of the ArrayIndexOutOfBoundsException inside the copying loop on 32 bit solaris in the server mode. Same test case runs correctly (without exiting) with the client compiler. The problem didn't exist in 1.3.1 and 1.2.2

public class ReadTest {

        private Buffer _current;
        private final int BYTE_SIZE = 1;
        private int _offsetInChunk;

        public static void main(String[] args) {
                final String _data = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
                Buffer in = new Buffer(_data);
                ReadTest test = new ReadTest(in);
                char[] value = new char[10];
                int offset = 0;
                int length = 10;
                while (true) {
                        for(int i=0; i<6; i++) {
                                test.testMethod(value, offset, length);
                                System.out.println(value);
                        }
                        Buffer in2 = new Buffer(_data);
                        in.next = in2;
                        in = in2;
                }
        }

        private ReadTest(Buffer buffer) {
                _current = buffer;
        }

        private void testMethod(char[] value, int offset, int length) {

                if((value == null) || (value.length-offset < length)) {
                        System.out.println("### ERROR1 ###");
                        return;
                }

                int inLengthInBytes = length * BYTE_SIZE;
                int numBytesToCopy = 0;

                while(inLengthInBytes > 0) {
                        if (_offsetInChunk >= _current.dataEndOffset) {
                                _offsetInChunk -= _current.dataEndOffset;
                                if(_current.next == null) {
                                        System.out.println("### ERROR2 ###");
                                        return;
                                }
                                _current = _current.next;
                                _offsetInChunk += _current.dataStartOffset;
                        }

                        numBytesToCopy = _current.dataEndOffset - _offsetInChunk;
                        if (inLengthInBytes < numBytesToCopy) {
                                numBytesToCopy = inLengthInBytes;
                        }

                        int i = 0, max = 0;
                        try {
                                for(i = offset, max = numBytesToCopy; max > 0; i++, max -= BYTE_SIZE) {
                                        value[i] = (char)(_current.data[_offsetInChunk++] & 0xff);
                                        if (value[i] == 0) {
                                                System.out.println("### ERROR3 ###");
                                                return;
                                        }
                                }
                        } catch(ArrayIndexOutOfBoundsException aioobe) {
                                System.out.println("+++++++++++++++++++++++++++++");
                                System.out.println(" value          = " + new String(value));
                                System.out.println(" value's length = " + value.length);
                                System.out.println(" value's i      = " + i);
                                System.out.println(" max            = " + max);
                                System.out.println(" numBytesToCopy = " + numBytesToCopy);
                                System.out.println(" BYTE_SIZE      = " + BYTE_SIZE);
                                System.out.println(" offset         = " + offset);
                                System.out.println("+++++++++++++++++++++++++++++");
                                System.exit(1);
                        }
                        inLengthInBytes -= numBytesToCopy;
                        offset += numBytesToCopy / BYTE_SIZE;
                }
        }

}

class Buffer {

        public byte[] data;
        public int dataStartOffset;
        public int dataEndOffset;
        public Buffer next;

        public Buffer(String _data) {
                int chunkSize = dataEndOffset = _data.length();
                data = _data.getBytes();
        }
}

Output:

bash-2.00$ /java/re/jdk/1.4.2/promoted/latest/binaries/solaris-sparc/bin/java_g -XX:CompileOnly=ReadTest.testMethod -server ReadTest
VM option 'CompileOnly=ReadTest.testMethod'
ABCDEFGHIJ
KLMNOPQRST
..........
+++++++++++++++++++++++++++++
 value          = 34567890AB
 value's length = 10
 value's i      = 10
 max            = 0
 numBytesToCopy = 2
 BYTE_SIZE      = 1
 offset         = 8
+++++++++++++++++++++++++++++
Work Around
There was no failure when I ran the testcase with development flag "-XX:-RangeCheckElimination" option in 1.4.0.

sree-  xxxxx@xxxxx   2002-09-24
Evaluation
  xxxxx@xxxxx   2002-09-20
Reproduces with current c2_baseline.
----- -----
I simplified the test file somewhat.
Reproduces with -Xbatch -Xcomp -XX:+PrintOpto -XX:CompileOnly=.testMethod -XX:LoopUnrollLimit=80 ReadTest on both sparc & intel.
  xxxxx@xxxxx   2002-09-23

Testcase didn't failed with option "-XX:LoopUnrollLimit=" set to 45. I tested with 1.4.1 and 1.4.2 on Solaris and with 1.4.0-rc on Intel. If I increase the LoopUnrollLimit testcase starts failing again.
sree-  xxxxx@xxxxx   2002-09-27

OBOB in the Range Check Elimination code; negative stride*scale handling case (which triggers in a variety of loop shapes, not just count-down loops or count-up loops with negative scale).  In the long comments starting around line 784 loopTransform.cpp, there is an assumption: ASSUME: (I % stride_con) == 0.
This assumption is almost but not quite right: ((I-I_initial) % stride_con) == 0.  I cut short the derivation of the min/max equations and end up with a tiny bit more code run and compile-time and approximately the same code generated but with the OBOB fixed.
  xxxxx@xxxxx   2002-10-03

Fix backported to 1.4.1_02. Bugtraq is not allowing me to save with Resp Eng as "cliffc", so changing it to default.

sree-  xxxxx@xxxxx   2002-12-11
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang