src/java.base/share/classes/java/util/ArraysParallelSortHelpers.java
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 47216 71c04702a3d5
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
     1 /*
     1 /*
     2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    85     /**
    85     /**
    86      * A placeholder task for Sorters, used for the lowest
    86      * A placeholder task for Sorters, used for the lowest
    87      * quartile task, that does not need to maintain array state.
    87      * quartile task, that does not need to maintain array state.
    88      */
    88      */
    89     static final class EmptyCompleter extends CountedCompleter<Void> {
    89     static final class EmptyCompleter extends CountedCompleter<Void> {
       
    90         @java.io.Serial
    90         static final long serialVersionUID = 2446542900576103244L;
    91         static final long serialVersionUID = 2446542900576103244L;
    91         EmptyCompleter(CountedCompleter<?> p) { super(p); }
    92         EmptyCompleter(CountedCompleter<?> p) { super(p); }
    92         public final void compute() { }
    93         public final void compute() { }
    93     }
    94     }
    94 
    95 
    95     /**
    96     /**
    96      * A trigger for secondary merge of two merges
    97      * A trigger for secondary merge of two merges
    97      */
    98      */
    98     static final class Relay extends CountedCompleter<Void> {
    99     static final class Relay extends CountedCompleter<Void> {
       
   100         @java.io.Serial
    99         static final long serialVersionUID = 2446542900576103244L;
   101         static final long serialVersionUID = 2446542900576103244L;
   100         final CountedCompleter<?> task;
   102         final CountedCompleter<?> task;
   101         Relay(CountedCompleter<?> task) {
   103         Relay(CountedCompleter<?> task) {
   102             super(null, 1);
   104             super(null, 1);
   103             this.task = task;
   105             this.task = task;
   109     }
   111     }
   110 
   112 
   111     /** Object + Comparator support class */
   113     /** Object + Comparator support class */
   112     static final class FJObject {
   114     static final class FJObject {
   113         static final class Sorter<T> extends CountedCompleter<Void> {
   115         static final class Sorter<T> extends CountedCompleter<Void> {
   114             static final long serialVersionUID = 2446542900576103244L;
   116             @java.io.Serial
   115             final T[] a, w;
   117             static final long serialVersionUID = 2446542900576103244L;
       
   118             @SuppressWarnings("serial") // Not statically typed as Serializable
       
   119             final T[] a;
       
   120             @SuppressWarnings("serial") // Not statically typed as Serializable
       
   121             final T[] w;
   116             final int base, size, wbase, gran;
   122             final int base, size, wbase, gran;
       
   123             @SuppressWarnings("serial") // Not statically typed as Serializable
   117             Comparator<? super T> comparator;
   124             Comparator<? super T> comparator;
   118             Sorter(CountedCompleter<?> par, T[] a, T[] w, int base, int size,
   125             Sorter(CountedCompleter<?> par, T[] a, T[] w, int base, int size,
   119                    int wbase, int gran,
   126                    int wbase, int gran,
   120                    Comparator<? super T> comparator) {
   127                    Comparator<? super T> comparator) {
   121                 super(par);
   128                 super(par);
   146                 s.tryComplete();
   153                 s.tryComplete();
   147             }
   154             }
   148         }
   155         }
   149 
   156 
   150         static final class Merger<T> extends CountedCompleter<Void> {
   157         static final class Merger<T> extends CountedCompleter<Void> {
   151             static final long serialVersionUID = 2446542900576103244L;
   158             @java.io.Serial
   152             final T[] a, w; // main and workspace arrays
   159             static final long serialVersionUID = 2446542900576103244L;
       
   160              // main and workspace arrays
       
   161             @SuppressWarnings("serial") // Not statically typed as Serializable
       
   162             final T[] a;
       
   163             @SuppressWarnings("serial") // Not statically typed as Serializable
       
   164             final T[] w;
   153             final int lbase, lsize, rbase, rsize, wbase, gran;
   165             final int lbase, lsize, rbase, rsize, wbase, gran;
       
   166             @SuppressWarnings("serial") // Not statically typed as Serializable
   154             Comparator<? super T> comparator;
   167             Comparator<? super T> comparator;
   155             Merger(CountedCompleter<?> par, T[] a, T[] w,
   168             Merger(CountedCompleter<?> par, T[] a, T[] w,
   156                    int lbase, int lsize, int rbase,
   169                    int lbase, int lsize, int rbase,
   157                    int rsize, int wbase, int gran,
   170                    int rsize, int wbase, int gran,
   158                    Comparator<? super T> comparator) {
   171                    Comparator<? super T> comparator) {
   231     } // FJObject
   244     } // FJObject
   232 
   245 
   233     /** byte support class */
   246     /** byte support class */
   234     static final class FJByte {
   247     static final class FJByte {
   235         static final class Sorter extends CountedCompleter<Void> {
   248         static final class Sorter extends CountedCompleter<Void> {
       
   249             @java.io.Serial
   236             static final long serialVersionUID = 2446542900576103244L;
   250             static final long serialVersionUID = 2446542900576103244L;
   237             final byte[] a, w;
   251             final byte[] a, w;
   238             final int base, size, wbase, gran;
   252             final int base, size, wbase, gran;
   239             Sorter(CountedCompleter<?> par, byte[] a, byte[] w, int base,
   253             Sorter(CountedCompleter<?> par, byte[] a, byte[] w, int base,
   240                    int size, int wbase, int gran) {
   254                    int size, int wbase, int gran) {
   264                 s.tryComplete();
   278                 s.tryComplete();
   265             }
   279             }
   266         }
   280         }
   267 
   281 
   268         static final class Merger extends CountedCompleter<Void> {
   282         static final class Merger extends CountedCompleter<Void> {
       
   283             @java.io.Serial
   269             static final long serialVersionUID = 2446542900576103244L;
   284             static final long serialVersionUID = 2446542900576103244L;
   270             final byte[] a, w; // main and workspace arrays
   285             final byte[] a, w; // main and workspace arrays
   271             final int lbase, lsize, rbase, rsize, wbase, gran;
   286             final int lbase, lsize, rbase, rsize, wbase, gran;
   272             Merger(CountedCompleter<?> par, byte[] a, byte[] w,
   287             Merger(CountedCompleter<?> par, byte[] a, byte[] w,
   273                    int lbase, int lsize, int rbase,
   288                    int lbase, int lsize, int rbase,
   342     } // FJByte
   357     } // FJByte
   343 
   358 
   344     /** char support class */
   359     /** char support class */
   345     static final class FJChar {
   360     static final class FJChar {
   346         static final class Sorter extends CountedCompleter<Void> {
   361         static final class Sorter extends CountedCompleter<Void> {
       
   362             @java.io.Serial
   347             static final long serialVersionUID = 2446542900576103244L;
   363             static final long serialVersionUID = 2446542900576103244L;
   348             final char[] a, w;
   364             final char[] a, w;
   349             final int base, size, wbase, gran;
   365             final int base, size, wbase, gran;
   350             Sorter(CountedCompleter<?> par, char[] a, char[] w, int base,
   366             Sorter(CountedCompleter<?> par, char[] a, char[] w, int base,
   351                    int size, int wbase, int gran) {
   367                    int size, int wbase, int gran) {
   375                 s.tryComplete();
   391                 s.tryComplete();
   376             }
   392             }
   377         }
   393         }
   378 
   394 
   379         static final class Merger extends CountedCompleter<Void> {
   395         static final class Merger extends CountedCompleter<Void> {
       
   396             @java.io.Serial
   380             static final long serialVersionUID = 2446542900576103244L;
   397             static final long serialVersionUID = 2446542900576103244L;
   381             final char[] a, w; // main and workspace arrays
   398             final char[] a, w; // main and workspace arrays
   382             final int lbase, lsize, rbase, rsize, wbase, gran;
   399             final int lbase, lsize, rbase, rsize, wbase, gran;
   383             Merger(CountedCompleter<?> par, char[] a, char[] w,
   400             Merger(CountedCompleter<?> par, char[] a, char[] w,
   384                    int lbase, int lsize, int rbase,
   401                    int lbase, int lsize, int rbase,
   453     } // FJChar
   470     } // FJChar
   454 
   471 
   455     /** short support class */
   472     /** short support class */
   456     static final class FJShort {
   473     static final class FJShort {
   457         static final class Sorter extends CountedCompleter<Void> {
   474         static final class Sorter extends CountedCompleter<Void> {
       
   475             @java.io.Serial
   458             static final long serialVersionUID = 2446542900576103244L;
   476             static final long serialVersionUID = 2446542900576103244L;
   459             final short[] a, w;
   477             final short[] a, w;
   460             final int base, size, wbase, gran;
   478             final int base, size, wbase, gran;
   461             Sorter(CountedCompleter<?> par, short[] a, short[] w, int base,
   479             Sorter(CountedCompleter<?> par, short[] a, short[] w, int base,
   462                    int size, int wbase, int gran) {
   480                    int size, int wbase, int gran) {
   486                 s.tryComplete();
   504                 s.tryComplete();
   487             }
   505             }
   488         }
   506         }
   489 
   507 
   490         static final class Merger extends CountedCompleter<Void> {
   508         static final class Merger extends CountedCompleter<Void> {
       
   509             @java.io.Serial
   491             static final long serialVersionUID = 2446542900576103244L;
   510             static final long serialVersionUID = 2446542900576103244L;
   492             final short[] a, w; // main and workspace arrays
   511             final short[] a, w; // main and workspace arrays
   493             final int lbase, lsize, rbase, rsize, wbase, gran;
   512             final int lbase, lsize, rbase, rsize, wbase, gran;
   494             Merger(CountedCompleter<?> par, short[] a, short[] w,
   513             Merger(CountedCompleter<?> par, short[] a, short[] w,
   495                    int lbase, int lsize, int rbase,
   514                    int lbase, int lsize, int rbase,
   564     } // FJShort
   583     } // FJShort
   565 
   584 
   566     /** int support class */
   585     /** int support class */
   567     static final class FJInt {
   586     static final class FJInt {
   568         static final class Sorter extends CountedCompleter<Void> {
   587         static final class Sorter extends CountedCompleter<Void> {
       
   588             @java.io.Serial
   569             static final long serialVersionUID = 2446542900576103244L;
   589             static final long serialVersionUID = 2446542900576103244L;
   570             final int[] a, w;
   590             final int[] a, w;
   571             final int base, size, wbase, gran;
   591             final int base, size, wbase, gran;
   572             Sorter(CountedCompleter<?> par, int[] a, int[] w, int base,
   592             Sorter(CountedCompleter<?> par, int[] a, int[] w, int base,
   573                    int size, int wbase, int gran) {
   593                    int size, int wbase, int gran) {
   597                 s.tryComplete();
   617                 s.tryComplete();
   598             }
   618             }
   599         }
   619         }
   600 
   620 
   601         static final class Merger extends CountedCompleter<Void> {
   621         static final class Merger extends CountedCompleter<Void> {
       
   622             @java.io.Serial
   602             static final long serialVersionUID = 2446542900576103244L;
   623             static final long serialVersionUID = 2446542900576103244L;
   603             final int[] a, w; // main and workspace arrays
   624             final int[] a, w; // main and workspace arrays
   604             final int lbase, lsize, rbase, rsize, wbase, gran;
   625             final int lbase, lsize, rbase, rsize, wbase, gran;
   605             Merger(CountedCompleter<?> par, int[] a, int[] w,
   626             Merger(CountedCompleter<?> par, int[] a, int[] w,
   606                    int lbase, int lsize, int rbase,
   627                    int lbase, int lsize, int rbase,
   675     } // FJInt
   696     } // FJInt
   676 
   697 
   677     /** long support class */
   698     /** long support class */
   678     static final class FJLong {
   699     static final class FJLong {
   679         static final class Sorter extends CountedCompleter<Void> {
   700         static final class Sorter extends CountedCompleter<Void> {
       
   701             @java.io.Serial
   680             static final long serialVersionUID = 2446542900576103244L;
   702             static final long serialVersionUID = 2446542900576103244L;
   681             final long[] a, w;
   703             final long[] a, w;
   682             final int base, size, wbase, gran;
   704             final int base, size, wbase, gran;
   683             Sorter(CountedCompleter<?> par, long[] a, long[] w, int base,
   705             Sorter(CountedCompleter<?> par, long[] a, long[] w, int base,
   684                    int size, int wbase, int gran) {
   706                    int size, int wbase, int gran) {
   708                 s.tryComplete();
   730                 s.tryComplete();
   709             }
   731             }
   710         }
   732         }
   711 
   733 
   712         static final class Merger extends CountedCompleter<Void> {
   734         static final class Merger extends CountedCompleter<Void> {
       
   735             @java.io.Serial
   713             static final long serialVersionUID = 2446542900576103244L;
   736             static final long serialVersionUID = 2446542900576103244L;
   714             final long[] a, w; // main and workspace arrays
   737             final long[] a, w; // main and workspace arrays
   715             final int lbase, lsize, rbase, rsize, wbase, gran;
   738             final int lbase, lsize, rbase, rsize, wbase, gran;
   716             Merger(CountedCompleter<?> par, long[] a, long[] w,
   739             Merger(CountedCompleter<?> par, long[] a, long[] w,
   717                    int lbase, int lsize, int rbase,
   740                    int lbase, int lsize, int rbase,
   786     } // FJLong
   809     } // FJLong
   787 
   810 
   788     /** float support class */
   811     /** float support class */
   789     static final class FJFloat {
   812     static final class FJFloat {
   790         static final class Sorter extends CountedCompleter<Void> {
   813         static final class Sorter extends CountedCompleter<Void> {
       
   814             @java.io.Serial
   791             static final long serialVersionUID = 2446542900576103244L;
   815             static final long serialVersionUID = 2446542900576103244L;
   792             final float[] a, w;
   816             final float[] a, w;
   793             final int base, size, wbase, gran;
   817             final int base, size, wbase, gran;
   794             Sorter(CountedCompleter<?> par, float[] a, float[] w, int base,
   818             Sorter(CountedCompleter<?> par, float[] a, float[] w, int base,
   795                    int size, int wbase, int gran) {
   819                    int size, int wbase, int gran) {
   819                 s.tryComplete();
   843                 s.tryComplete();
   820             }
   844             }
   821         }
   845         }
   822 
   846 
   823         static final class Merger extends CountedCompleter<Void> {
   847         static final class Merger extends CountedCompleter<Void> {
       
   848             @java.io.Serial
   824             static final long serialVersionUID = 2446542900576103244L;
   849             static final long serialVersionUID = 2446542900576103244L;
   825             final float[] a, w; // main and workspace arrays
   850             final float[] a, w; // main and workspace arrays
   826             final int lbase, lsize, rbase, rsize, wbase, gran;
   851             final int lbase, lsize, rbase, rsize, wbase, gran;
   827             Merger(CountedCompleter<?> par, float[] a, float[] w,
   852             Merger(CountedCompleter<?> par, float[] a, float[] w,
   828                    int lbase, int lsize, int rbase,
   853                    int lbase, int lsize, int rbase,
   897     } // FJFloat
   922     } // FJFloat
   898 
   923 
   899     /** double support class */
   924     /** double support class */
   900     static final class FJDouble {
   925     static final class FJDouble {
   901         static final class Sorter extends CountedCompleter<Void> {
   926         static final class Sorter extends CountedCompleter<Void> {
       
   927             @java.io.Serial
   902             static final long serialVersionUID = 2446542900576103244L;
   928             static final long serialVersionUID = 2446542900576103244L;
   903             final double[] a, w;
   929             final double[] a, w;
   904             final int base, size, wbase, gran;
   930             final int base, size, wbase, gran;
   905             Sorter(CountedCompleter<?> par, double[] a, double[] w, int base,
   931             Sorter(CountedCompleter<?> par, double[] a, double[] w, int base,
   906                    int size, int wbase, int gran) {
   932                    int size, int wbase, int gran) {
   930                 s.tryComplete();
   956                 s.tryComplete();
   931             }
   957             }
   932         }
   958         }
   933 
   959 
   934         static final class Merger extends CountedCompleter<Void> {
   960         static final class Merger extends CountedCompleter<Void> {
       
   961             @java.io.Serial
   935             static final long serialVersionUID = 2446542900576103244L;
   962             static final long serialVersionUID = 2446542900576103244L;
   936             final double[] a, w; // main and workspace arrays
   963             final double[] a, w; // main and workspace arrays
   937             final int lbase, lsize, rbase, rsize, wbase, gran;
   964             final int lbase, lsize, rbase, rsize, wbase, gran;
   938             Merger(CountedCompleter<?> par, double[] a, double[] w,
   965             Merger(CountedCompleter<?> par, double[] a, double[] w,
   939                    int lbase, int lsize, int rbase,
   966                    int lbase, int lsize, int rbase,