Hi,
xalan performs 1.4 million char array clones per iteration of the normal
size DaCapo benchmark. All of the character array clones are coming from
java.lang.String. The attached patch changes the use of char[].clone
(which maps to java.lang.Object.clone) to a helper method that allocates
the character array and then array copies from the source to the new
array. On the Jikes RVM I get the following performance results from 10
iterations of DaCapo using the large data set size:
current java.lang.String using char[].clone:
run 1: 99157ms
run 2: 98700ms
run 3: 97927ms
patched java.lang.String using the helper routine:
run 1: 97710ms
run 2: 97406ms
run 3: 96762ms
The speed up is between 0.22% and 1.2%. Do people think using the helper
is a sensible change?
Thanks,
Ian
--- java/lang/String.java 2008-01-23 09:01:02.000000000 +0000
+++ java/lang/String.java 2008-02-04 13:43:02.000000000 +0000
@@ -1284,6 +1284,13 @@
return new String(newStr, 0, newStr.length, true);
}
+ private static char[] cloneCharArray(char[] src)
+ {
+ char[] copy = new char[src.length];
+ VMSystem.arraycopy(src, 0, copy, 0, src.length);
+ return copy;
+ }
+
/**
* Replaces every instance of a character in this String with a new
* character. If no replacements occur, this is returned.
@@ -1303,7 +1310,7 @@
break;
if (i < 0)
return this;
- char[] newStr = (char[]) value.clone();
+ char[] newStr = cloneCharArray(value);
newStr[x] = newChar;
while (--i >= 0)
if (value[++x] == oldChar)
@@ -1450,7 +1457,7 @@
// Now we perform the conversion. Fortunately, there are no multi-character
// lowercase expansions in Unicode 3.0.0.
- char[] newStr = (char[]) value.clone();
+ char[] newStr = cloneCharArray(value);
do
{
char ch = value[x];
@@ -1504,7 +1511,7 @@
// Now we perform the conversion. Fortunately, there are no
// multi-character lowercase expansions in Unicode 3.0.0.
- char[] newStr = (char[]) value.clone();
+ char[] newStr = cloneCharArray(value);
do
{
char ch = value[x];
@@ -1557,7 +1564,7 @@
i = count;
if (expand == 0)
{
- char[] newStr = (char[]) value.clone();
+ char[] newStr = cloneCharArray(value);
while (--i >= 0)
{
char ch = value[x];
@@ -1642,7 +1649,7 @@
i = count;
if (expand == 0)
{
- char[] newStr = (char[]) value.clone();
+ char[] newStr = cloneCharArray(value);
while (--i >= 0)
{
char ch = value[x];
@@ -1731,7 +1738,7 @@
public char[] toCharArray()
{
if (count == value.length)
- return (char[]) value.clone();
+ return cloneCharArray(value);
char[] copy = new char[count];
VMSystem.arraycopy(value, offset, copy, 0, count);