提交 e060baef 编写于 作者: L lpriima

8073124: Tune test and document TimSort runs length stack size increase

Reviewed-by: dholmes
上级 a851f16e
...@@ -144,6 +144,10 @@ class ComparableTimSort { ...@@ -144,6 +144,10 @@ class ComparableTimSort {
* large) stack lengths for smaller arrays. The "magic numbers" in the * large) stack lengths for smaller arrays. The "magic numbers" in the
* computation below must be changed if MIN_MERGE is decreased. See * computation below must be changed if MIN_MERGE is decreased. See
* the MIN_MERGE declaration above for more information. * the MIN_MERGE declaration above for more information.
* The maximum value of 49 allows for an array up to length
* Integer.MAX_VALUE-4, if array is filled by the worst case stack size
* increasing scenario. More explanations are given in section 4 of:
* http://envisage-project.eu/wp-content/uploads/2015/02/sorting.pdf
*/ */
int stackLen = (len < 120 ? 5 : int stackLen = (len < 120 ? 5 :
len < 1542 ? 10 : len < 1542 ? 10 :
......
...@@ -174,6 +174,10 @@ class TimSort<T> { ...@@ -174,6 +174,10 @@ class TimSort<T> {
* large) stack lengths for smaller arrays. The "magic numbers" in the * large) stack lengths for smaller arrays. The "magic numbers" in the
* computation below must be changed if MIN_MERGE is decreased. See * computation below must be changed if MIN_MERGE is decreased. See
* the MIN_MERGE declaration above for more information. * the MIN_MERGE declaration above for more information.
* The maximum value of 49 allows for an array up to length
* Integer.MAX_VALUE-4, if array is filled by the worst case stack size
* increasing scenario. More explanations are given in section 4 of:
* http://envisage-project.eu/wp-content/uploads/2015/02/sorting.pdf
*/ */
int stackLen = (len < 120 ? 5 : int stackLen = (len < 120 ? 5 :
len < 1542 ? 10 : len < 1542 ? 10 :
......
...@@ -24,10 +24,10 @@ ...@@ -24,10 +24,10 @@
/* /*
* @test * @test
* @bug 8072909 * @bug 8072909
* @run main/othervm TimSortStackSize2 67108864 * @run main/othervm -Xmx385m TimSortStackSize2 67108864
* not for regular execution on all platforms: * not for regular execution on all platforms:
* run main/othervm -Xmx8g TimSortStackSize2 1073741824 * run main/othervm -Xmx8g TimSortStackSize2 1073741824
* run main/othervm -Xmx32g TimSortStackSize2 2147483644 * run main/othervm -Xmx16g TimSortStackSize2 2147483644
* @summary Test TimSort stack size on big arrays * @summary Test TimSort stack size on big arrays
*/ */
import java.util.ArrayList; import java.util.ArrayList;
...@@ -41,22 +41,30 @@ public class TimSortStackSize2 { ...@@ -41,22 +41,30 @@ public class TimSortStackSize2 {
int lengthOfTest = Integer.parseInt(args[0]); int lengthOfTest = Integer.parseInt(args[0]);
boolean passed = true; boolean passed = true;
try { try {
Arrays.sort(new TimSortStackSize2(lengthOfTest).createArray(), Integer [] a = new TimSortStackSize2(lengthOfTest).createArray();
new Comparator<Object>() { long begin = System.nanoTime();
Arrays.sort(a, new Comparator<Object>() {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public int compare(Object first, Object second) { public int compare(Object first, Object second) {
return ((Comparable<Object>)first).compareTo(second); return ((Comparable<Object>)first).compareTo(second);
} }
}); });
System.out.println("TimSort OK"); long end = System.nanoTime();
System.out.println("TimSort: " + (end - begin));
a = null;
} catch (ArrayIndexOutOfBoundsException e){ } catch (ArrayIndexOutOfBoundsException e){
System.out.println("TimSort broken"); System.out.println("TimSort broken:");
e.printStackTrace(); e.printStackTrace();
passed = false; passed = false;
} }
try { try {
Arrays.sort(new TimSortStackSize2(lengthOfTest).createArray()); Integer [] a = new TimSortStackSize2(lengthOfTest).createArray();
System.out.println("ComparableTimSort OK"); long begin = System.nanoTime();
Arrays.sort(a);
long end = System.nanoTime();
System.out.println("ComparableTimSort: " + (end - begin));
a = null;
} catch (ArrayIndexOutOfBoundsException e){ } catch (ArrayIndexOutOfBoundsException e){
System.out.println("ComparableTimSort broken:"); System.out.println("ComparableTimSort broken:");
e.printStackTrace(); e.printStackTrace();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册