Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2058831 | 1.4.2 | Btplusnull User | P1 | Resolved | Fixed | mantis |
JDK-2058830 | 1.4.1_02 | Btplusnull User | P1 | Resolved | Fixed | 02 |
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
+++++++++++++++++++++++++++++
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
+++++++++++++++++++++++++++++
- backported by
-
JDK-2058830 Bad exception in the copying loop
- Resolved
-
JDK-2058831 Bad exception in the copying loop
- Resolved
- duplicates
-
JDK-4752235 Server compiler does not check the loop exit condition correctly
- Closed
- relates to
-
JDK-4629512 Bad exception in trivial loop on Sparc 32b -server
- Resolved