Search code examples
javastringjava-6

JVM ACCESS_VIOLATION_EXCEPTION when constructing String from array on obsolete JVM


I've run into a really weird case - I have the following code:

new String(data, position, len, Charset.forName("windows-1255"));

where data is a byte[], and position and len are ints.
When I run it on jdk 1.6.0_38, it runs really slow (for a set iteration 411 seconds), and when I run this:

new String(data, position, len);

it runs the same iteration in less than 1 sec. Some more data:

  • When I debug it, upon entering the Constructor (with the Charset) it throws a JVM ACCESS_VIOLATION_EXCEPTION and dies.
  • When I run it on jdk 1.7.0_10 it runs fine (less than 1 sec)

can anyone explain this weird behavior?


Solution

  • I think you ran into this issue. The article claims that the constructor you are using is inefficient, because it always makes a defensive copy of the provided byte[] buffer, which then can lead to frequent GCing. I guess if you do a long enough iteration, the performance differences can become that visible - just like it is mentioned in the article's summary.

    As for the access vialoation, it seems to be this problem.