jdk/test/java/util/Arrays/TimSortStackSize2.java
changeset 28971 53e56ca0e39d
parent 28871 d04fa3bde1d0
child 29124 b8f3a6579ab2
equal deleted inserted replaced
28970:aaec841a1a3c 28971:53e56ca0e39d
    22  */
    22  */
    23 
    23 
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @bug 8072909
    26  * @bug 8072909
    27  * @run main/othervm TimSortStackSize2 67108864
    27  * @run main/othervm -Xmx385m TimSortStackSize2 67108864
    28  * not for regular execution on all platforms:
    28  * not for regular execution on all platforms:
    29  * run main/othervm -Xmx8g TimSortStackSize2 1073741824
    29  * run main/othervm -Xmx8g TimSortStackSize2 1073741824
    30  * run main/othervm -Xmx32g TimSortStackSize2 2147483644
    30  * run main/othervm -Xmx16g TimSortStackSize2 2147483644
    31  * @summary Test TimSort stack size on big arrays
    31  * @summary Test TimSort stack size on big arrays
    32  */
    32  */
    33 import java.util.ArrayList;
    33 import java.util.ArrayList;
    34 import java.util.Arrays;
    34 import java.util.Arrays;
    35 import java.util.Comparator;
    35 import java.util.Comparator;
    39 
    39 
    40     public static void main(String[] args) {
    40     public static void main(String[] args) {
    41         int lengthOfTest = Integer.parseInt(args[0]);
    41         int lengthOfTest = Integer.parseInt(args[0]);
    42         boolean passed = true;
    42         boolean passed = true;
    43         try {
    43         try {
    44             Arrays.sort(new TimSortStackSize2(lengthOfTest).createArray(),
    44             Integer [] a = new TimSortStackSize2(lengthOfTest).createArray();
    45                 new Comparator<Object>() {
    45             long begin = System.nanoTime();
       
    46             Arrays.sort(a, new Comparator<Object>() {
    46                     @SuppressWarnings("unchecked")
    47                     @SuppressWarnings("unchecked")
    47                     public int compare(Object first, Object second) {
    48                     public int compare(Object first, Object second) {
    48                         return ((Comparable<Object>)first).compareTo(second);
    49                         return ((Comparable<Object>)first).compareTo(second);
    49                     }
    50                     }
    50                 });
    51                 });
    51             System.out.println("TimSort OK");
    52             long end = System.nanoTime();
       
    53             System.out.println("TimSort: " + (end - begin));
       
    54             a = null;
    52         } catch (ArrayIndexOutOfBoundsException e){
    55         } catch (ArrayIndexOutOfBoundsException e){
    53             System.out.println("TimSort broken");
    56             System.out.println("TimSort broken:");
    54             e.printStackTrace();
    57             e.printStackTrace();
    55             passed = false;
    58             passed = false;
    56         }
    59         }
       
    60 
    57         try {
    61         try {
    58             Arrays.sort(new TimSortStackSize2(lengthOfTest).createArray());
    62             Integer [] a = new TimSortStackSize2(lengthOfTest).createArray();
    59             System.out.println("ComparableTimSort OK");
    63             long begin = System.nanoTime();
       
    64             Arrays.sort(a);
       
    65             long end = System.nanoTime();
       
    66             System.out.println("ComparableTimSort: " + (end - begin));
       
    67             a = null;
    60         } catch (ArrayIndexOutOfBoundsException e){
    68         } catch (ArrayIndexOutOfBoundsException e){
    61             System.out.println("ComparableTimSort broken:");
    69             System.out.println("ComparableTimSort broken:");
    62             e.printStackTrace();
    70             e.printStackTrace();
    63             passed = false;
    71             passed = false;
    64         }
    72         }