diff --git a/src/share/classes/java/util/ComparableTimSort.java b/src/share/classes/java/util/ComparableTimSort.java index 6237b3fd2e6ec72de36bc70682cd07f61402916e..36c8d90f0f26e89d2714c95cd6422e8108799ae4 100644 --- a/src/share/classes/java/util/ComparableTimSort.java +++ b/src/share/classes/java/util/ComparableTimSort.java @@ -144,6 +144,10 @@ class ComparableTimSort { * large) stack lengths for smaller arrays. The "magic numbers" in the * computation below must be changed if MIN_MERGE is decreased. See * 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 : len < 1542 ? 10 : diff --git a/src/share/classes/java/util/TimSort.java b/src/share/classes/java/util/TimSort.java index af66d8092c59e973fea3079c3093b050a7db4c1f..ea0d58f5a8569a72c34d49c56db63d9f58c8414b 100644 --- a/src/share/classes/java/util/TimSort.java +++ b/src/share/classes/java/util/TimSort.java @@ -174,6 +174,10 @@ class TimSort { * large) stack lengths for smaller arrays. The "magic numbers" in the * computation below must be changed if MIN_MERGE is decreased. See * 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 : len < 1542 ? 10 : diff --git a/test/java/util/Arrays/TimSortStackSize2.java b/test/java/util/Arrays/TimSortStackSize2.java index 86194320f59ada56b66085536939fc4bd24d7eeb..c2971b14a6e317c07e398649eb46f84d536ec58b 100644 --- a/test/java/util/Arrays/TimSortStackSize2.java +++ b/test/java/util/Arrays/TimSortStackSize2.java @@ -24,10 +24,10 @@ /* * @test * @bug 8072909 - * @run main/othervm TimSortStackSize2 67108864 + * @run main/othervm -Xmx385m TimSortStackSize2 67108864 * not for regular execution on all platforms: * 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 */ import java.util.ArrayList; @@ -41,22 +41,30 @@ public class TimSortStackSize2 { int lengthOfTest = Integer.parseInt(args[0]); boolean passed = true; try { - Arrays.sort(new TimSortStackSize2(lengthOfTest).createArray(), - new Comparator() { + Integer [] a = new TimSortStackSize2(lengthOfTest).createArray(); + long begin = System.nanoTime(); + Arrays.sort(a, new Comparator() { @SuppressWarnings("unchecked") public int compare(Object first, Object second) { return ((Comparable)first).compareTo(second); } }); - System.out.println("TimSort OK"); + long end = System.nanoTime(); + System.out.println("TimSort: " + (end - begin)); + a = null; } catch (ArrayIndexOutOfBoundsException e){ - System.out.println("TimSort broken"); + System.out.println("TimSort broken:"); e.printStackTrace(); passed = false; } + try { - Arrays.sort(new TimSortStackSize2(lengthOfTest).createArray()); - System.out.println("ComparableTimSort OK"); + Integer [] a = new TimSortStackSize2(lengthOfTest).createArray(); + long begin = System.nanoTime(); + Arrays.sort(a); + long end = System.nanoTime(); + System.out.println("ComparableTimSort: " + (end - begin)); + a = null; } catch (ArrayIndexOutOfBoundsException e){ System.out.println("ComparableTimSort broken:"); e.printStackTrace();