Merge unixdomainchannels
authormichaelm
Wed, 13 Nov 2019 09:16:04 +0000
branchunixdomainchannels
changeset 59048 4c3eb05c0701
parent 59030 8555f68967d1 (current diff)
parent 59046 a8104278b4d0 (diff)
child 59052 15e9a570c6e6
Merge
test/jdk/java/util/Arrays/ParallelSorting.java
test/langtools/tools/javac/diags/examples/RestrictedTypeNotAllowedPreview.java
--- a/make/autoconf/hotspot.m4	Tue Nov 12 15:07:15 2019 +0000
+++ b/make/autoconf/hotspot.m4	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -351,7 +351,8 @@
   # Only enable ZGC on supported platforms
   AC_MSG_CHECKING([if zgc can be built])
   if (test "x$OPENJDK_TARGET_OS" = "xlinux" && test "x$OPENJDK_TARGET_CPU" = "xx86_64") || \
-     (test "x$OPENJDK_TARGET_OS" = "xlinux" && test "x$OPENJDK_TARGET_CPU" = "xaarch64"); then
+     (test "x$OPENJDK_TARGET_OS" = "xlinux" && test "x$OPENJDK_TARGET_CPU" = "xaarch64") ||
+     (test "x$OPENJDK_TARGET_OS" = "xmacosx" && test "x$OPENJDK_TARGET_CPU" = "xx86_64"); then
     AC_MSG_RESULT([yes])
   else
     DISABLED_JVM_FEATURES="$DISABLED_JVM_FEATURES zgc"
--- a/make/autoconf/toolchain.m4	Tue Nov 12 15:07:15 2019 +0000
+++ b/make/autoconf/toolchain.m4	Wed Nov 13 09:16:04 2019 +0000
@@ -481,7 +481,7 @@
     COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT | \
         $SED -e 's/ *Copyright .*//'`
     COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
-        $SED -e 's/^.* \(@<:@1-9@:>@\.@<:@0-9.@:>@*\)@<:@^0-9.@:>@.*$/\1/'`
+        $SED -e 's/^.* \(@<:@1-9@:>@<:@0-9@:>@*\.@<:@0-9.@:>@*\)@<:@^0-9.@:>@.*$/\1/'`
   elif test  "x$TOOLCHAIN_TYPE" = xclang; then
     # clang --version output typically looks like
     #    Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
--- a/src/hotspot/cpu/ppc/c1_CodeStubs_ppc.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/cpu/ppc/c1_CodeStubs_ppc.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -322,7 +322,7 @@
 void PatchingStub::emit_code(LIR_Assembler* ce) {
   // copy original code here
   assert(NativeGeneralJump::instruction_size <= _bytes_to_copy && _bytes_to_copy <= 0xFF,
-         "not enough room for call");
+         "not enough room for call, need %d", _bytes_to_copy);
   assert((_bytes_to_copy & 0x3) == 0, "must copy a multiple of four bytes");
 
   Label call_patch;
@@ -340,7 +340,7 @@
     __ load_const(_obj, addrlit, R0);
     DEBUG_ONLY( compare_with_patch_site(__ code_section()->start() + being_initialized_entry, _pc_start, _bytes_to_copy); )
   } else {
-    // Make a copy the code which is going to be patched.
+    // Make a copy of the code which is going to be patched.
     for (int i = 0; i < _bytes_to_copy; i++) {
       address ptr = (address)(_pc_start + i);
       int a_byte = (*ptr) & 0xFF;
--- a/src/hotspot/cpu/ppc/c1_LIRAssembler_ppc.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/cpu/ppc/c1_LIRAssembler_ppc.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -743,10 +743,11 @@
           if (UseCompressedOops && !wide) {
             // Encoding done in caller
             __ stw(from_reg->as_register(), offset, base);
+            __ verify_coop(from_reg->as_register(), FILE_AND_LINE);
           } else {
             __ std(from_reg->as_register(), offset, base);
+            __ verify_oop(from_reg->as_register(), FILE_AND_LINE);
           }
-          __ verify_oop(from_reg->as_register());
           break;
         }
       case T_FLOAT : __ stfs(from_reg->as_float_reg(), offset, base); break;
@@ -783,10 +784,11 @@
         if (UseCompressedOops && !wide) {
           // Encoding done in caller.
           __ stwx(from_reg->as_register(), base, disp);
+          __ verify_coop(from_reg->as_register(), FILE_AND_LINE); // kills R0
         } else {
           __ stdx(from_reg->as_register(), base, disp);
+          __ verify_oop(from_reg->as_register(), FILE_AND_LINE); // kills R0
         }
-        __ verify_oop(from_reg->as_register()); // kills R0
         break;
       }
     case T_FLOAT : __ stfsx(from_reg->as_float_reg(), base, disp); break;
@@ -831,7 +833,7 @@
           } else {
             __ ld(to_reg->as_register(), offset, base);
           }
-          __ verify_oop(to_reg->as_register());
+          __ verify_oop(to_reg->as_register(), FILE_AND_LINE);
           break;
         }
       case T_FLOAT:  __ lfs(to_reg->as_float_reg(), offset, base); break;
@@ -862,7 +864,7 @@
         } else {
           __ ldx(to_reg->as_register(), base, disp);
         }
-        __ verify_oop(to_reg->as_register());
+        __ verify_oop(to_reg->as_register(), FILE_AND_LINE);
         break;
       }
     case T_FLOAT:  __ lfsx(to_reg->as_float_reg() , base, disp); break;
@@ -1141,7 +1143,7 @@
   }
 
   if (addr->base()->type() == T_OBJECT) {
-    __ verify_oop(src);
+    __ verify_oop(src, FILE_AND_LINE);
   }
 
   PatchingStub* patch = NULL;
@@ -1238,7 +1240,7 @@
     ShouldNotReachHere();
   }
   if (is_reference_type(to_reg->type())) {
-    __ verify_oop(to_reg->as_register());
+    __ verify_oop(to_reg->as_register(), FILE_AND_LINE);
   }
 }
 
@@ -1265,7 +1267,7 @@
   }
 
   if (addr->base()->is_oop_register()) {
-    __ verify_oop(src);
+    __ verify_oop(src, FILE_AND_LINE);
   }
 
   PatchingStub* patch = NULL;
@@ -2321,7 +2323,7 @@
                      *op->stub()->entry());
 
   __ bind(*op->stub()->continuation());
-  __ verify_oop(op->obj()->as_register());
+  __ verify_oop(op->obj()->as_register(), FILE_AND_LINE);
 }
 
 
@@ -2546,7 +2548,7 @@
     Register Rtmp1 = op->tmp3()->as_register();
     bool should_profile = op->should_profile();
 
-    __ verify_oop(value);
+    __ verify_oop(value, FILE_AND_LINE);
     CodeStub* stub = op->stub();
     // Check if it needs to be profiled.
     ciMethodData* md = NULL;
@@ -3099,7 +3101,7 @@
   assert(do_null || do_update, "why are we here?");
   assert(!TypeEntries::was_null_seen(current_klass) || do_update, "why are we here?");
 
-  __ verify_oop(obj);
+  __ verify_oop(obj, FILE_AND_LINE);
 
   if (do_null) {
     if (!TypeEntries::was_null_seen(current_klass)) {
--- a/src/hotspot/cpu/ppc/c1_MacroAssembler_ppc.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/cpu/ppc/c1_MacroAssembler_ppc.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -44,7 +44,7 @@
   const Register temp_reg = R12_scratch2;
   Label Lmiss;
 
-  verify_oop(receiver);
+  verify_oop(receiver, FILE_AND_LINE);
   MacroAssembler::null_check(receiver, oopDesc::klass_offset_in_bytes(), &Lmiss);
   load_klass(temp_reg, receiver);
 
@@ -100,7 +100,7 @@
   // Load object header.
   ld(Rmark, oopDesc::mark_offset_in_bytes(), Roop);
 
-  verify_oop(Roop);
+  verify_oop(Roop, FILE_AND_LINE);
 
   // Save object being locked into the BasicObjectLock...
   std(Roop, BasicObjectLock::obj_offset_in_bytes(), Rbox);
@@ -157,7 +157,7 @@
   if (UseBiasedLocking) {
     // Load the object out of the BasicObjectLock.
     ld(Roop, BasicObjectLock::obj_offset_in_bytes(), Rbox);
-    verify_oop(Roop);
+    verify_oop(Roop, FILE_AND_LINE);
     biased_locking_exit(CCR0, Roop, R0, done);
   }
   // Test first it it is a fast recursive unlock.
@@ -167,7 +167,7 @@
   if (!UseBiasedLocking) {
     // Load object.
     ld(Roop, BasicObjectLock::obj_offset_in_bytes(), Rbox);
-    verify_oop(Roop);
+    verify_oop(Roop, FILE_AND_LINE);
   }
 
   // Check if it is still a light weight lock, this is is true if we see
@@ -316,7 +316,7 @@
 //         relocInfo::runtime_call_type);
   }
 
-  verify_oop(obj);
+  verify_oop(obj, FILE_AND_LINE);
 }
 
 
@@ -383,7 +383,7 @@
     //     relocInfo::runtime_call_type);
   }
 
-  verify_oop(obj);
+  verify_oop(obj, FILE_AND_LINE);
 }
 
 
@@ -399,8 +399,7 @@
   bne(CCR0, not_null);
   stop("non-null oop required");
   bind(not_null);
-  if (!VerifyOops) return;
-  verify_oop(r);
+  verify_oop(r, FILE_AND_LINE);
 }
 
 #endif // PRODUCT
--- a/src/hotspot/cpu/ppc/gc/g1/g1BarrierSetAssembler_ppc.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/cpu/ppc/gc/g1/g1BarrierSetAssembler_ppc.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -335,12 +335,12 @@
   __ ld(value, 0, tmp1);      // Resolve (untagged) jobject.
 
   __ beq(CCR0, not_weak);     // Test for jweak tag.
-  __ verify_oop(value);
+  __ verify_oop(value, FILE_AND_LINE);
   g1_write_barrier_pre(masm, IN_NATIVE | ON_PHANTOM_OOP_REF,
                        noreg, noreg, value,
                        tmp1, tmp2, needs_frame);
   __ bind(not_weak);
-  __ verify_oop(value);
+  __ verify_oop(value, FILE_AND_LINE);
   __ bind(done);
 }
 
--- a/src/hotspot/cpu/ppc/gc/shared/barrierSetAssembler_ppc.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/cpu/ppc/gc/shared/barrierSetAssembler_ppc.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -113,7 +113,7 @@
   __ clrrdi(tmp1, value, JNIHandles::weak_tag_size);
   __ ld(value, 0, tmp1);      // Resolve (untagged) jobject.
 
-  __ verify_oop(value);
+  __ verify_oop(value, FILE_AND_LINE);
   __ bind(done);
 }
 
--- a/src/hotspot/cpu/ppc/globalDefinitions_ppc.hpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/cpu/ppc/globalDefinitions_ppc.hpp	Wed Nov 13 09:16:04 2019 +0000
@@ -30,6 +30,10 @@
 #error "CC_INTERP is no longer supported. Removed in change 8145117."
 #endif
 
+#ifndef FILE_AND_LINE
+#define FILE_AND_LINE __FILE__ ":" XSTR(__LINE__)
+#endif
+
 // Size of PPC Instructions
 const int BytesPerInstWord = 4;
 
--- a/src/hotspot/cpu/ppc/interp_masm_ppc_64.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/cpu/ppc/interp_masm_ppc_64.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -2313,7 +2313,7 @@
 }
 
 void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) {
-  if (state == atos) { MacroAssembler::verify_oop(reg); }
+  if (state == atos) { MacroAssembler::verify_oop(reg, FILE_AND_LINE); }
 }
 
 // Local helper function for the verify_oop_or_return_address macro.
--- a/src/hotspot/cpu/ppc/macroAssembler_ppc.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/cpu/ppc/macroAssembler_ppc.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -3120,7 +3120,7 @@
   li(R0, 0);
   std(R0, in_bytes(JavaThread::vm_result_offset()), R16_thread);
 
-  verify_oop(oop_result);
+  verify_oop(oop_result, FILE_AND_LINE);
 }
 
 void MacroAssembler::get_vm_result_2(Register metadata_result) {
@@ -4917,6 +4917,13 @@
   }
 }
 
+void MacroAssembler::verify_coop(Register coop, const char* msg) {
+  if (!VerifyOops) { return; }
+  if (UseCompressedOops) { decode_heap_oop(coop); }
+  verify_oop(coop, msg);
+  if (UseCompressedOops) { encode_heap_oop(coop, coop); }
+}
+
 // READ: oop. KILL: R0. Volatile floats perhaps.
 void MacroAssembler::verify_oop(Register oop, const char* msg) {
   if (!VerifyOops) {
@@ -4926,6 +4933,9 @@
   address/* FunctionDescriptor** */fd = StubRoutines::verify_oop_subroutine_entry_address();
   const Register tmp = R11; // Will be preserved.
   const int nbytes_save = MacroAssembler::num_volatile_regs * 8;
+
+  BLOCK_COMMENT("verify_oop {");
+
   save_volatile_gprs(R1_SP, -nbytes_save); // except R0
 
   mr_if_needed(R4_ARG2, oop);
@@ -4942,6 +4952,8 @@
   pop_frame();
   restore_LR_CR(tmp);
   restore_volatile_gprs(R1_SP, -nbytes_save); // except R0
+
+  BLOCK_COMMENT("} verify_oop");
 }
 
 void MacroAssembler::verify_oop_addr(RegisterOrConstant offs, Register base, const char* msg) {
--- a/src/hotspot/cpu/ppc/macroAssembler_ppc.hpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/cpu/ppc/macroAssembler_ppc.hpp	Wed Nov 13 09:16:04 2019 +0000
@@ -914,6 +914,9 @@
   // Verify R16_thread contents.
   void verify_thread();
 
+  // Calls verify_oop. If UseCompressedOops is on, decodes the oop.
+  // Preserves reg.
+  void verify_coop(Register reg, const char*);
   // Emit code to verify that reg contains a valid oop if +VerifyOops is set.
   void verify_oop(Register reg, const char* s = "broken oop");
   void verify_oop_addr(RegisterOrConstant offs, Register base, const char* s = "contains broken oop");
--- a/src/hotspot/cpu/ppc/methodHandles_ppc.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/cpu/ppc/methodHandles_ppc.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -77,7 +77,7 @@
   Klass* klass = SystemDictionary::well_known_klass(klass_id);
   Label L_ok, L_bad;
   BLOCK_COMMENT("verify_klass {");
-  __ verify_oop(obj_reg);
+  __ verify_oop(obj_reg, FILE_AND_LINE);
   __ cmpdi(CCR0, obj_reg, 0);
   __ beq(CCR0, L_bad);
   __ load_klass(temp_reg, obj_reg);
@@ -172,16 +172,16 @@
   assert(method_temp == R19_method, "required register for loading method");
 
   // Load the invoker, as MH -> MH.form -> LF.vmentry
-  __ verify_oop(recv);
+  __ verify_oop(recv, FILE_AND_LINE);
   __ load_heap_oop(method_temp, NONZERO(java_lang_invoke_MethodHandle::form_offset_in_bytes()), recv,
                    temp2, noreg, false, IS_NOT_NULL);
-  __ verify_oop(method_temp);
+  __ verify_oop(method_temp, FILE_AND_LINE);
   __ load_heap_oop(method_temp, NONZERO(java_lang_invoke_LambdaForm::vmentry_offset_in_bytes()), method_temp,
                    temp2, noreg, false, IS_NOT_NULL);
-  __ verify_oop(method_temp);
+  __ verify_oop(method_temp, FILE_AND_LINE);
   __ load_heap_oop(method_temp, NONZERO(java_lang_invoke_MemberName::method_offset_in_bytes()), method_temp,
                    temp2, noreg, false, IS_NOT_NULL);
-  __ verify_oop(method_temp);
+  __ verify_oop(method_temp, FILE_AND_LINE);
   __ ld(method_temp, NONZERO(java_lang_invoke_ResolvedMethodName::vmtarget_offset_in_bytes()), method_temp);
 
   if (VerifyMethodHandles && !for_compiler_entry) {
@@ -318,7 +318,7 @@
 
     Register temp1_recv_klass = temp1;
     if (iid != vmIntrinsics::_linkToStatic) {
-      __ verify_oop(receiver_reg);
+      __ verify_oop(receiver_reg, FILE_AND_LINE);
       if (iid == vmIntrinsics::_linkToSpecial) {
         // Don't actually load the klass; just null-check the receiver.
         __ null_check_throw(receiver_reg, -1, temp1,
--- a/src/hotspot/cpu/ppc/sharedRuntime_ppc.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/cpu/ppc/sharedRuntime_ppc.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -1742,9 +1742,9 @@
         assert(r->is_valid(), "bad oop arg");
         if (r->is_stack()) {
           __ ld(temp_reg, reg2offset(r), R1_SP);
-          __ verify_oop(temp_reg);
+          __ verify_oop(temp_reg, FILE_AND_LINE);
         } else {
-          __ verify_oop(r->as_Register());
+          __ verify_oop(r->as_Register(), FILE_AND_LINE);
         }
       }
     }
@@ -2107,7 +2107,7 @@
 
   __ cmpdi(CCR0, R3_ARG1, 0);
   __ beq(CCR0, ic_miss);
-  __ verify_oop(R3_ARG1);
+  __ verify_oop(R3_ARG1, FILE_AND_LINE);
   __ load_klass(receiver_klass, R3_ARG1);
 
   __ cmpd(CCR0, receiver_klass, ic);
--- a/src/hotspot/cpu/ppc/stubGenerator_ppc.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/cpu/ppc/stubGenerator_ppc.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -440,7 +440,6 @@
     StubCodeMark mark(this, "StubRoutines", "forward_exception");
     address start = __ pc();
 
-#if !defined(PRODUCT)
     if (VerifyOops) {
       // Get pending exception oop.
       __ ld(R3_ARG1,
@@ -456,7 +455,6 @@
       }
       __ verify_oop(R3_ARG1, "StubRoutines::forward exception: not an oop");
     }
-#endif
 
     // Save LR/CR and copy exception pc (LR) into R4_ARG2.
     __ save_LR_CR(R4_ARG2);
@@ -702,9 +700,9 @@
 #if !defined(PRODUCT)
   // Wrapper which calls oopDesc::is_oop_or_null()
   // Only called by MacroAssembler::verify_oop
-  static void verify_oop_helper(const char* message, oop o) {
+  static void verify_oop_helper(const char* message, oopDesc* o) {
     if (!oopDesc::is_oop_or_null(o)) {
-      fatal("%s", message);
+      fatal("%s. oop: " PTR_FORMAT, message, p2i(o));
     }
     ++ StubRoutines::_verify_oop_count;
   }
@@ -725,7 +723,6 @@
     return start;
   }
 
-
   // -XX:+OptimizeFill : convert fill/copy loops into intrinsic
   //
   // The code is implemented(ported from sparc) as we believe it benefits JVM98, however
--- a/src/hotspot/cpu/sparc/interp_masm_sparc.hpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/cpu/sparc/interp_masm_sparc.hpp	Wed Nov 13 09:16:04 2019 +0000
@@ -321,6 +321,7 @@
   // Debugging
   void interp_verify_oop(Register reg, TosState state, const char * file, int line);    // only if +VerifyOops && state == atos
   void verify_oop_or_return_address(Register reg, Register rtmp); // for astore
+  void verify_FPU(int stack_depth, TosState state = ftos) {}      // No-op.
 
   // support for JVMTI/Dtrace
   typedef enum { NotifyJVMTI, SkipNotifyJVMTI } NotifyMethodExitMode;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/os/bsd/gc/z/zBackingFile_bsd.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -0,0 +1,183 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "precompiled.hpp"
+#include "gc/z/zBackingFile_bsd.hpp"
+#include "gc/z/zErrno.hpp"
+#include "gc/z/zGlobals.hpp"
+#include "gc/z/zLargePages.inline.hpp"
+#include "gc/z/zPhysicalMemory.inline.hpp"
+#include "logging/log.hpp"
+#include "runtime/globals.hpp"
+#include "runtime/os.hpp"
+#include "utilities/align.hpp"
+#include "utilities/debug.hpp"
+
+#include <mach/mach.h>
+#include <mach/mach_vm.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+
+static int vm_flags_superpage() {
+  if (!ZLargePages::is_explicit()) {
+    return 0;
+  }
+
+  const int page_size_in_megabytes = ZGranuleSize >> 20;
+  return page_size_in_megabytes << VM_FLAGS_SUPERPAGE_SHIFT;
+}
+
+static ZErrno mremap(uintptr_t from_addr, uintptr_t to_addr, size_t size) {
+  mach_vm_address_t remap_addr = to_addr;
+  vm_prot_t remap_cur_prot;
+  vm_prot_t remap_max_prot;
+
+  // Remap memory to an additional location
+  const kern_return_t res = mach_vm_remap(mach_task_self(),
+                                          &remap_addr,
+                                          size,
+                                          0 /* mask */,
+                                          VM_FLAGS_FIXED | VM_FLAGS_OVERWRITE | vm_flags_superpage(),
+                                          mach_task_self(),
+                                          from_addr,
+                                          FALSE /* copy */,
+                                          &remap_cur_prot,
+                                          &remap_max_prot,
+                                          VM_INHERIT_COPY);
+
+  return (res == KERN_SUCCESS) ? ZErrno(0) : ZErrno(EINVAL);
+}
+
+ZBackingFile::ZBackingFile() :
+    _base(0),
+    _size(0),
+    _initialized(false) {
+
+  // Reserve address space for virtual backing file
+  _base = (uintptr_t)os::reserve_memory(MaxHeapSize);
+  if (_base == 0) {
+    // Failed
+    log_error(gc)("Failed to reserve address space for virtual backing file");
+    return;
+  }
+
+  // Successfully initialized
+  _initialized = true;
+}
+
+bool ZBackingFile::is_initialized() const {
+  return _initialized;
+}
+
+size_t ZBackingFile::size() const {
+  return _size;
+}
+
+bool ZBackingFile::commit_inner(size_t offset, size_t length) {
+  assert(is_aligned(offset, os::vm_page_size()), "Invalid offset");
+  assert(is_aligned(length, os::vm_page_size()), "Invalid length");
+
+  log_trace(gc, heap)("Committing memory: " SIZE_FORMAT "M-" SIZE_FORMAT "M (" SIZE_FORMAT "M)",
+                      offset / M, (offset + length) / M, length / M);
+
+  const uintptr_t addr = _base + offset;
+  const void* const res = mmap((void*)addr, length, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+  if (res == MAP_FAILED) {
+    ZErrno err;
+    log_error(gc)("Failed to commit memory (%s)", err.to_string());
+    return false;
+  }
+
+  const size_t end = offset + length;
+  if (end > _size) {
+    // Record new virtual file size
+    _size = end;
+  }
+
+  // Success
+  return true;
+}
+
+size_t ZBackingFile::commit(size_t offset, size_t length) {
+  // Try to commit the whole region
+  if (commit_inner(offset, length)) {
+    // Success
+    return length;
+  }
+
+  // Failed, try to commit as much as possible
+  size_t start = offset;
+  size_t end = offset + length;
+
+  for (;;) {
+    length = align_down((end - start) / 2, ZGranuleSize);
+    if (length == 0) {
+      // Done, don't commit more
+      return start - offset;
+    }
+
+    if (commit_inner(start, length)) {
+      // Success, try commit more
+      start += length;
+    } else {
+      // Failed, try commit less
+      end -= length;
+    }
+  }
+}
+
+size_t ZBackingFile::uncommit(size_t offset, size_t length) {
+  assert(is_aligned(offset, os::vm_page_size()), "Invalid offset");
+  assert(is_aligned(length, os::vm_page_size()), "Invalid length");
+
+  log_trace(gc, heap)("Uncommitting memory: " SIZE_FORMAT "M-" SIZE_FORMAT "M (" SIZE_FORMAT "M)",
+                      offset / M, (offset + length) / M, length / M);
+
+  const uintptr_t start = _base + offset;
+  const void* const res = mmap((void*)start, length, PROT_NONE, MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE, -1, 0);
+  if (res == MAP_FAILED) {
+    ZErrno err;
+    log_error(gc)("Failed to uncommit memory (%s)", err.to_string());
+    return 0;
+  }
+
+  return length;
+}
+
+void ZBackingFile::map(uintptr_t addr, size_t size, uintptr_t offset) const {
+  const ZErrno err = mremap(_base + offset, addr, size);
+  if (err) {
+    fatal("Failed to remap memory (%s)", err.to_string());
+  }
+}
+
+void ZBackingFile::unmap(uintptr_t addr, size_t size) const {
+  // Note that we must keep the address space reservation intact and just detach
+  // the backing memory. For this reason we map a new anonymous, non-accessible
+  // and non-reserved page over the mapping instead of actually unmapping.
+  const void* const res = mmap((void*)addr, size, PROT_NONE, MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE, -1, 0);
+  if (res == MAP_FAILED) {
+    ZErrno err;
+    fatal("Failed to map memory (%s)", err.to_string());
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/os/bsd/gc/z/zBackingFile_bsd.hpp	Wed Nov 13 09:16:04 2019 +0000
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#ifndef OS_BSD_GC_Z_ZBACKINGFILE_BSD_HPP
+#define OS_BSD_GC_Z_ZBACKINGFILE_BSD_HPP
+
+#include "memory/allocation.hpp"
+
+class ZPhysicalMemory;
+
+// On macOS, we use a virtual backing file. It is represented by a reserved virtual
+// address space, in which we commit physical memory using the mach_vm_map() API.
+// The multi-mapping API simply remaps these addresses using mach_vm_remap() into
+// the different heap views. This works as-if there was a backing file, it's just
+// that the file is represented with memory mappings instead.
+
+class ZBackingFile {
+private:
+  uintptr_t _base;
+  size_t    _size;
+  bool      _initialized;
+
+  bool commit_inner(size_t offset, size_t length);
+
+public:
+  ZBackingFile();
+
+  bool is_initialized() const;
+
+  size_t size() const;
+
+  size_t commit(size_t offset, size_t length);
+  size_t uncommit(size_t offset, size_t length);
+
+  void map(uintptr_t addr, size_t size, uintptr_t offset) const;
+  void unmap(uintptr_t addr, size_t size) const;
+};
+
+#endif // OS_BSD_GC_Z_ZBACKINGFILE_BSD_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/os/bsd/gc/z/zLargePages_bsd.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "precompiled.hpp"
+#include "gc/z/zLargePages.hpp"
+#include "runtime/globals.hpp"
+
+void ZLargePages::initialize_platform() {
+  if (UseLargePages) {
+    _state = Explicit;
+  } else {
+    _state = Disabled;
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/os/bsd/gc/z/zNUMA_bsd.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "precompiled.hpp"
+#include "gc/z/zNUMA.hpp"
+
+void ZNUMA::initialize_platform() {
+  _enabled = false;
+}
+
+uint32_t ZNUMA::count() {
+  return 1;
+}
+
+uint32_t ZNUMA::id() {
+  return 0;
+}
+
+uint32_t ZNUMA::memory_id(uintptr_t addr) {
+  // NUMA support not enabled, assume everything belongs to node zero
+  return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/os/bsd/gc/z/zPhysicalMemoryBacking_bsd.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -0,0 +1,212 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "precompiled.hpp"
+#include "gc/z/zAddress.inline.hpp"
+#include "gc/z/zGlobals.hpp"
+#include "gc/z/zLargePages.inline.hpp"
+#include "gc/z/zPhysicalMemory.inline.hpp"
+#include "gc/z/zPhysicalMemoryBacking_bsd.hpp"
+#include "runtime/globals.hpp"
+#include "runtime/init.hpp"
+#include "runtime/os.hpp"
+#include "utilities/align.hpp"
+#include "utilities/debug.hpp"
+
+bool ZPhysicalMemoryBacking::is_initialized() const {
+  return _file.is_initialized();
+}
+
+void ZPhysicalMemoryBacking::warn_commit_limits(size_t max) const {
+  // Does nothing
+}
+
+bool ZPhysicalMemoryBacking::supports_uncommit() {
+  assert(!is_init_completed(), "Invalid state");
+  assert(_file.size() >= ZGranuleSize, "Invalid size");
+
+  // Test if uncommit is supported by uncommitting and then re-committing a granule
+  return commit(uncommit(ZGranuleSize)) == ZGranuleSize;
+}
+
+size_t ZPhysicalMemoryBacking::commit(size_t size) {
+  size_t committed = 0;
+
+  // Fill holes in the backing file
+  while (committed < size) {
+    size_t allocated = 0;
+    const size_t remaining = size - committed;
+    const uintptr_t start = _uncommitted.alloc_from_front_at_most(remaining, &allocated);
+    if (start == UINTPTR_MAX) {
+      // No holes to commit
+      break;
+    }
+
+    // Try commit hole
+    const size_t filled = _file.commit(start, allocated);
+    if (filled > 0) {
+      // Successful or partialy successful
+      _committed.free(start, filled);
+      committed += filled;
+    }
+    if (filled < allocated) {
+      // Failed or partialy failed
+      _uncommitted.free(start + filled, allocated - filled);
+      return committed;
+    }
+  }
+
+  // Expand backing file
+  if (committed < size) {
+    const size_t remaining = size - committed;
+    const uintptr_t start = _file.size();
+    const size_t expanded = _file.commit(start, remaining);
+    if (expanded > 0) {
+      // Successful or partialy successful
+      _committed.free(start, expanded);
+      committed += expanded;
+    }
+  }
+
+  return committed;
+}
+
+size_t ZPhysicalMemoryBacking::uncommit(size_t size) {
+  size_t uncommitted = 0;
+
+  // Punch holes in backing file
+  while (uncommitted < size) {
+    size_t allocated = 0;
+    const size_t remaining = size - uncommitted;
+    const uintptr_t start = _committed.alloc_from_back_at_most(remaining, &allocated);
+    assert(start != UINTPTR_MAX, "Allocation should never fail");
+
+    // Try punch hole
+    const size_t punched = _file.uncommit(start, allocated);
+    if (punched > 0) {
+      // Successful or partialy successful
+      _uncommitted.free(start, punched);
+      uncommitted += punched;
+    }
+    if (punched < allocated) {
+      // Failed or partialy failed
+      _committed.free(start + punched, allocated - punched);
+      return uncommitted;
+    }
+  }
+
+  return uncommitted;
+}
+
+ZPhysicalMemory ZPhysicalMemoryBacking::alloc(size_t size) {
+  assert(is_aligned(size, ZGranuleSize), "Invalid size");
+
+  ZPhysicalMemory pmem;
+
+  // Allocate segments
+  for (size_t allocated = 0; allocated < size; allocated += ZGranuleSize) {
+    const uintptr_t start = _committed.alloc_from_front(ZGranuleSize);
+    assert(start != UINTPTR_MAX, "Allocation should never fail");
+    pmem.add_segment(ZPhysicalMemorySegment(start, ZGranuleSize));
+  }
+
+  return pmem;
+}
+
+void ZPhysicalMemoryBacking::free(const ZPhysicalMemory& pmem) {
+  const size_t nsegments = pmem.nsegments();
+
+  // Free segments
+  for (size_t i = 0; i < nsegments; i++) {
+    const ZPhysicalMemorySegment& segment = pmem.segment(i);
+    _committed.free(segment.start(), segment.size());
+  }
+}
+
+void ZPhysicalMemoryBacking::pretouch_view(uintptr_t addr, size_t size) const {
+  const size_t page_size = ZLargePages::is_explicit() ? ZGranuleSize : os::vm_page_size();
+  os::pretouch_memory((void*)addr, (void*)(addr + size), page_size);
+}
+
+void ZPhysicalMemoryBacking::map_view(const ZPhysicalMemory& pmem, uintptr_t addr, bool pretouch) const {
+  const size_t nsegments = pmem.nsegments();
+  size_t size = 0;
+
+  // Map segments
+  for (size_t i = 0; i < nsegments; i++) {
+    const ZPhysicalMemorySegment& segment = pmem.segment(i);
+    const uintptr_t segment_addr = addr + size;
+    _file.map(segment_addr, segment.size(), segment.start());
+    size += segment.size();
+  }
+
+  // Pre-touch memory
+  if (pretouch) {
+    pretouch_view(addr, size);
+  }
+}
+
+void ZPhysicalMemoryBacking::unmap_view(const ZPhysicalMemory& pmem, uintptr_t addr) const {
+  _file.unmap(addr, pmem.size());
+}
+
+uintptr_t ZPhysicalMemoryBacking::nmt_address(uintptr_t offset) const {
+  // From an NMT point of view we treat the first heap view (marked0) as committed
+  return ZAddress::marked0(offset);
+}
+
+void ZPhysicalMemoryBacking::map(const ZPhysicalMemory& pmem, uintptr_t offset) const {
+  if (ZVerifyViews) {
+    // Map good view
+    map_view(pmem, ZAddress::good(offset), AlwaysPreTouch);
+  } else {
+    // Map all views
+    map_view(pmem, ZAddress::marked0(offset), AlwaysPreTouch);
+    map_view(pmem, ZAddress::marked1(offset), AlwaysPreTouch);
+    map_view(pmem, ZAddress::remapped(offset), AlwaysPreTouch);
+  }
+}
+
+void ZPhysicalMemoryBacking::unmap(const ZPhysicalMemory& pmem, uintptr_t offset) const {
+  if (ZVerifyViews) {
+    // Unmap good view
+    unmap_view(pmem, ZAddress::good(offset));
+  } else {
+    // Unmap all views
+    unmap_view(pmem, ZAddress::marked0(offset));
+    unmap_view(pmem, ZAddress::marked1(offset));
+    unmap_view(pmem, ZAddress::remapped(offset));
+  }
+}
+
+void ZPhysicalMemoryBacking::debug_map(const ZPhysicalMemory& pmem, uintptr_t offset) const {
+  // Map good view
+  assert(ZVerifyViews, "Should be enabled");
+  map_view(pmem, ZAddress::good(offset), false /* pretouch */);
+}
+
+void ZPhysicalMemoryBacking::debug_unmap(const ZPhysicalMemory& pmem, uintptr_t offset) const {
+  // Unmap good view
+  assert(ZVerifyViews, "Should be enabled");
+  unmap_view(pmem, ZAddress::good(offset));
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/os/bsd/gc/z/zPhysicalMemoryBacking_bsd.hpp	Wed Nov 13 09:16:04 2019 +0000
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#ifndef OS_BSD_GC_Z_ZPHYSICALMEMORYBACKING_BSD_HPP
+#define OS_BSD_GC_Z_ZPHYSICALMEMORYBACKING_BSD_HPP
+
+#include "gc/z/zBackingFile_bsd.hpp"
+#include "gc/z/zMemory.hpp"
+
+class ZPhysicalMemory;
+
+class ZPhysicalMemoryBacking {
+private:
+  ZBackingFile   _file;
+  ZMemoryManager _committed;
+  ZMemoryManager _uncommitted;
+
+  void pretouch_view(uintptr_t addr, size_t size) const;
+  void map_view(const ZPhysicalMemory& pmem, uintptr_t addr, bool pretouch) const;
+  void unmap_view(const ZPhysicalMemory& pmem, uintptr_t addr) const;
+
+public:
+  bool is_initialized() const;
+
+  void warn_commit_limits(size_t max) const;
+  bool supports_uncommit();
+
+  size_t commit(size_t size);
+  size_t uncommit(size_t size);
+
+  ZPhysicalMemory alloc(size_t size);
+  void free(const ZPhysicalMemory& pmem);
+
+  uintptr_t nmt_address(uintptr_t offset) const;
+
+  void map(const ZPhysicalMemory& pmem, uintptr_t offset) const;
+  void unmap(const ZPhysicalMemory& pmem, uintptr_t offset) const;
+
+  void debug_map(const ZPhysicalMemory& pmem, uintptr_t offset) const;
+  void debug_unmap(const ZPhysicalMemory& pmem, uintptr_t offset) const;
+};
+
+#endif // OS_BSD_GC_Z_ZPHYSICALMEMORYBACKING_BSD_HPP
--- a/src/hotspot/os/bsd/os_bsd.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/os/bsd/os_bsd.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -2845,15 +2845,11 @@
     // and if UserSignalHandler is installed all bets are off
     if (CheckJNICalls) {
       if (libjsig_is_loaded) {
-        if (PrintJNIResolving) {
-          tty->print_cr("Info: libjsig is activated, all active signal checking is disabled");
-        }
+        log_debug(jni, resolve)("Info: libjsig is activated, all active signal checking is disabled");
         check_signals = false;
       }
       if (AllowUserSignalHandlers) {
-        if (PrintJNIResolving) {
-          tty->print_cr("Info: AllowUserSignalHandlers is activated, all active signal checking is disabled");
-        }
+        log_debug(jni, resolve)("Info: AllowUserSignalHandlers is activated, all active signal checking is disabled");
         check_signals = false;
       }
     }
--- a/src/hotspot/os/linux/os_linux.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/os/linux/os_linux.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -4789,15 +4789,11 @@
     // Log that signal checking is off only if -verbose:jni is specified.
     if (CheckJNICalls) {
       if (libjsig_is_loaded) {
-        if (PrintJNIResolving) {
-          tty->print_cr("Info: libjsig is activated, all active signal checking is disabled");
-        }
+        log_debug(jni, resolve)("Info: libjsig is activated, all active signal checking is disabled");
         check_signals = false;
       }
       if (AllowUserSignalHandlers) {
-        if (PrintJNIResolving) {
-          tty->print_cr("Info: AllowUserSignalHandlers is activated, all active signal checking is disabled");
-        }
+        log_debug(jni, resolve)("Info: AllowUserSignalHandlers is activated, all active signal checking is disabled");
         check_signals = false;
       }
     }
--- a/src/hotspot/os/solaris/os_solaris.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/os/solaris/os_solaris.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -3684,15 +3684,11 @@
   // Log that signal checking is off only if -verbose:jni is specified.
   if (CheckJNICalls) {
     if (libjsig_is_loaded) {
-      if (PrintJNIResolving) {
-        tty->print_cr("Info: libjsig is activated, all active signal checking is disabled");
-      }
+      log_debug(jni, resolve)("Info: libjsig is activated, all active signal checking is disabled");
       check_signals = false;
     }
     if (AllowUserSignalHandlers) {
-      if (PrintJNIResolving) {
-        tty->print_cr("Info: AllowUserSignalHandlers is activated, all active signal checking is disabled");
-      }
+      log_debug(jni, resolve)("Info: AllowUserSignalHandlers is activated, all active signal checking is disabled");
       check_signals = false;
     }
   }
--- a/src/hotspot/share/adlc/output_h.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/adlc/output_h.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -758,10 +758,6 @@
       fprintf(fp_hpp, "  Pipeline_Use_Cycle_Mask(uint mask1, uint mask2) : _mask((((uint64_t)mask1) << 32) | mask2) {}\n\n");
       fprintf(fp_hpp, "  Pipeline_Use_Cycle_Mask(uint64_t mask) : _mask(mask) {}\n\n");
     }
-    fprintf(fp_hpp, "  Pipeline_Use_Cycle_Mask& operator=(const Pipeline_Use_Cycle_Mask &in) {\n");
-    fprintf(fp_hpp, "    _mask = in._mask;\n");
-    fprintf(fp_hpp, "    return *this;\n");
-    fprintf(fp_hpp, "  }\n\n");
     fprintf(fp_hpp, "  bool overlaps(const Pipeline_Use_Cycle_Mask &in2) const {\n");
     fprintf(fp_hpp, "    return ((_mask & in2._mask) != 0);\n");
     fprintf(fp_hpp, "  }\n\n");
@@ -792,11 +788,6 @@
     for (l = 1; l <= masklen; l++)
       fprintf(fp_hpp, "_mask%d(mask%d)%s", l, l, l < masklen ? ", " : " {}\n\n");
 
-    fprintf(fp_hpp, "  Pipeline_Use_Cycle_Mask& operator=(const Pipeline_Use_Cycle_Mask &in) {\n");
-    for (l = 1; l <= masklen; l++)
-      fprintf(fp_hpp, "    _mask%d = in._mask%d;\n", l, l);
-    fprintf(fp_hpp, "    return *this;\n");
-    fprintf(fp_hpp, "  }\n\n");
     fprintf(fp_hpp, "  Pipeline_Use_Cycle_Mask intersect(const Pipeline_Use_Cycle_Mask &in2) {\n");
     fprintf(fp_hpp, "    Pipeline_Use_Cycle_Mask out;\n");
     for (l = 1; l <= masklen; l++)
--- a/src/hotspot/share/c1/c1_GraphBuilder.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/c1/c1_GraphBuilder.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -2590,7 +2590,7 @@
 
 #ifdef ASSERT
   for_each_phi_fun(b, phi,
-                   assert(phi->operand_count() != 1 || phi->subst() != phi, "missed trivial simplification");
+                   assert(phi->operand_count() != 1 || phi->subst() != phi || phi->is_illegal(), "missed trivial simplification");
   );
 
   ValueStack* state = b->state()->caller_state();
--- a/src/hotspot/share/c1/c1_Optimizer.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/c1/c1_Optimizer.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -366,6 +366,8 @@
           assert(sux_value == end_state->stack_at(index), "stack not equal");
         }
         for_each_local_value(sux_state, index, sux_value) {
+          Phi* sux_phi = sux_value->as_Phi();
+          if (sux_phi != NULL && sux_phi->is_illegal()) continue;
           assert(sux_value == end_state->local_at(index), "locals not equal");
         }
         assert(sux_state->caller_state() == end_state->caller_state(), "caller not equal");
--- a/src/hotspot/share/compiler/compilerDefinitions.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/compiler/compilerDefinitions.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -54,10 +54,13 @@
     } else if (strcmp(CompilationMode, "high-only-quick-internal") == 0) {
       _high_only_quick_internal = true;
     } else {
-        jio_fprintf(defaultStream::error_stream(), "Unsupported compilation mode '%s', supported modes are: quick-only, high-only, high-only-quick-internal\n", CompilationMode);
-        return false;
-      }
+      jio_fprintf(defaultStream::error_stream(), "Unsupported compilation mode '%s', supported modes are: quick-only, high-only, high-only-quick-internal\n", CompilationMode);
+      return false;
     }
+    if (disable_intermediate()) {
+      CompLevel_initial_compile = CompLevel_full_optimization;
+    }
+  }
   return true;
 }
 
--- a/src/hotspot/share/gc/shared/c2/barrierSetC2.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/gc/shared/c2/barrierSetC2.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -149,10 +149,13 @@
     Node* control = control_dependent ? kit->control() : NULL;
 
     if (in_native) {
-      load = kit->make_load(control, adr, val_type, access.type(), mo);
+      load = kit->make_load(control, adr, val_type, access.type(), mo, dep,
+                            requires_atomic_access, unaligned,
+                            mismatched, unsafe, access.barrier_data());
     } else {
       load = kit->make_load(control, adr, val_type, access.type(), adr_type, mo,
-                            dep, requires_atomic_access, unaligned, mismatched, unsafe);
+                            dep, requires_atomic_access, unaligned, mismatched, unsafe,
+                            access.barrier_data());
     }
   } else {
     assert(!requires_atomic_access, "not yet supported");
@@ -162,7 +165,8 @@
     MergeMemNode* mm = opt_access.mem();
     PhaseGVN& gvn = opt_access.gvn();
     Node* mem = mm->memory_at(gvn.C->get_alias_index(adr_type));
-    load = LoadNode::make(gvn, control, mem, adr, adr_type, val_type, access.type(), mo, dep, unaligned, mismatched);
+    load = LoadNode::make(gvn, control, mem, adr, adr_type, val_type, access.type(), mo,
+                          dep, unaligned, mismatched, unsafe, access.barrier_data());
     load = gvn.transform(load);
   }
   access.set_raw_access(load);
@@ -409,28 +413,28 @@
     if (adr->bottom_type()->is_ptr_to_narrowoop()) {
       Node *newval_enc = kit->gvn().transform(new EncodePNode(new_val, new_val->bottom_type()->make_narrowoop()));
       Node *oldval_enc = kit->gvn().transform(new EncodePNode(expected_val, expected_val->bottom_type()->make_narrowoop()));
-      load_store = kit->gvn().transform(new CompareAndExchangeNNode(kit->control(), mem, adr, newval_enc, oldval_enc, adr_type, value_type->make_narrowoop(), mo));
+      load_store = new CompareAndExchangeNNode(kit->control(), mem, adr, newval_enc, oldval_enc, adr_type, value_type->make_narrowoop(), mo);
     } else
 #endif
     {
-      load_store = kit->gvn().transform(new CompareAndExchangePNode(kit->control(), mem, adr, new_val, expected_val, adr_type, value_type->is_oopptr(), mo));
+      load_store = new CompareAndExchangePNode(kit->control(), mem, adr, new_val, expected_val, adr_type, value_type->is_oopptr(), mo);
     }
   } else {
     switch (access.type()) {
       case T_BYTE: {
-        load_store = kit->gvn().transform(new CompareAndExchangeBNode(kit->control(), mem, adr, new_val, expected_val, adr_type, mo));
+        load_store = new CompareAndExchangeBNode(kit->control(), mem, adr, new_val, expected_val, adr_type, mo);
         break;
       }
       case T_SHORT: {
-        load_store = kit->gvn().transform(new CompareAndExchangeSNode(kit->control(), mem, adr, new_val, expected_val, adr_type, mo));
+        load_store = new CompareAndExchangeSNode(kit->control(), mem, adr, new_val, expected_val, adr_type, mo);
         break;
       }
       case T_INT: {
-        load_store = kit->gvn().transform(new CompareAndExchangeINode(kit->control(), mem, adr, new_val, expected_val, adr_type, mo));
+        load_store = new CompareAndExchangeINode(kit->control(), mem, adr, new_val, expected_val, adr_type, mo);
         break;
       }
       case T_LONG: {
-        load_store = kit->gvn().transform(new CompareAndExchangeLNode(kit->control(), mem, adr, new_val, expected_val, adr_type, mo));
+        load_store = new CompareAndExchangeLNode(kit->control(), mem, adr, new_val, expected_val, adr_type, mo);
         break;
       }
       default:
@@ -438,6 +442,9 @@
     }
   }
 
+  load_store->as_LoadStore()->set_barrier_data(access.barrier_data());
+  load_store = kit->gvn().transform(load_store);
+
   access.set_raw_access(load_store);
   pin_atomic_op(access);
 
@@ -466,50 +473,50 @@
       Node *newval_enc = kit->gvn().transform(new EncodePNode(new_val, new_val->bottom_type()->make_narrowoop()));
       Node *oldval_enc = kit->gvn().transform(new EncodePNode(expected_val, expected_val->bottom_type()->make_narrowoop()));
       if (is_weak_cas) {
-        load_store = kit->gvn().transform(new WeakCompareAndSwapNNode(kit->control(), mem, adr, newval_enc, oldval_enc, mo));
+        load_store = new WeakCompareAndSwapNNode(kit->control(), mem, adr, newval_enc, oldval_enc, mo);
       } else {
-        load_store = kit->gvn().transform(new CompareAndSwapNNode(kit->control(), mem, adr, newval_enc, oldval_enc, mo));
+        load_store = new CompareAndSwapNNode(kit->control(), mem, adr, newval_enc, oldval_enc, mo);
       }
     } else
 #endif
     {
       if (is_weak_cas) {
-        load_store = kit->gvn().transform(new WeakCompareAndSwapPNode(kit->control(), mem, adr, new_val, expected_val, mo));
+        load_store = new WeakCompareAndSwapPNode(kit->control(), mem, adr, new_val, expected_val, mo);
       } else {
-        load_store = kit->gvn().transform(new CompareAndSwapPNode(kit->control(), mem, adr, new_val, expected_val, mo));
+        load_store = new CompareAndSwapPNode(kit->control(), mem, adr, new_val, expected_val, mo);
       }
     }
   } else {
     switch(access.type()) {
       case T_BYTE: {
         if (is_weak_cas) {
-          load_store = kit->gvn().transform(new WeakCompareAndSwapBNode(kit->control(), mem, adr, new_val, expected_val, mo));
+          load_store = new WeakCompareAndSwapBNode(kit->control(), mem, adr, new_val, expected_val, mo);
         } else {
-          load_store = kit->gvn().transform(new CompareAndSwapBNode(kit->control(), mem, adr, new_val, expected_val, mo));
+          load_store = new CompareAndSwapBNode(kit->control(), mem, adr, new_val, expected_val, mo);
         }
         break;
       }
       case T_SHORT: {
         if (is_weak_cas) {
-          load_store = kit->gvn().transform(new WeakCompareAndSwapSNode(kit->control(), mem, adr, new_val, expected_val, mo));
+          load_store = new WeakCompareAndSwapSNode(kit->control(), mem, adr, new_val, expected_val, mo);
         } else {
-          load_store = kit->gvn().transform(new CompareAndSwapSNode(kit->control(), mem, adr, new_val, expected_val, mo));
+          load_store = new CompareAndSwapSNode(kit->control(), mem, adr, new_val, expected_val, mo);
         }
         break;
       }
       case T_INT: {
         if (is_weak_cas) {
-          load_store = kit->gvn().transform(new WeakCompareAndSwapINode(kit->control(), mem, adr, new_val, expected_val, mo));
+          load_store = new WeakCompareAndSwapINode(kit->control(), mem, adr, new_val, expected_val, mo);
         } else {
-          load_store = kit->gvn().transform(new CompareAndSwapINode(kit->control(), mem, adr, new_val, expected_val, mo));
+          load_store = new CompareAndSwapINode(kit->control(), mem, adr, new_val, expected_val, mo);
         }
         break;
       }
       case T_LONG: {
         if (is_weak_cas) {
-          load_store = kit->gvn().transform(new WeakCompareAndSwapLNode(kit->control(), mem, adr, new_val, expected_val, mo));
+          load_store = new WeakCompareAndSwapLNode(kit->control(), mem, adr, new_val, expected_val, mo);
         } else {
-          load_store = kit->gvn().transform(new CompareAndSwapLNode(kit->control(), mem, adr, new_val, expected_val, mo));
+          load_store = new CompareAndSwapLNode(kit->control(), mem, adr, new_val, expected_val, mo);
         }
         break;
       }
@@ -518,6 +525,9 @@
     }
   }
 
+  load_store->as_LoadStore()->set_barrier_data(access.barrier_data());
+  load_store = kit->gvn().transform(load_store);
+
   access.set_raw_access(load_store);
   pin_atomic_op(access);
 
@@ -539,27 +549,30 @@
     } else
 #endif
     {
-      load_store = kit->gvn().transform(new GetAndSetPNode(kit->control(), mem, adr, new_val, adr_type, value_type->is_oopptr()));
+      load_store = new GetAndSetPNode(kit->control(), mem, adr, new_val, adr_type, value_type->is_oopptr());
     }
   } else  {
     switch (access.type()) {
       case T_BYTE:
-        load_store = kit->gvn().transform(new GetAndSetBNode(kit->control(), mem, adr, new_val, adr_type));
+        load_store = new GetAndSetBNode(kit->control(), mem, adr, new_val, adr_type);
         break;
       case T_SHORT:
-        load_store = kit->gvn().transform(new GetAndSetSNode(kit->control(), mem, adr, new_val, adr_type));
+        load_store = new GetAndSetSNode(kit->control(), mem, adr, new_val, adr_type);
         break;
       case T_INT:
-        load_store = kit->gvn().transform(new GetAndSetINode(kit->control(), mem, adr, new_val, adr_type));
+        load_store = new GetAndSetINode(kit->control(), mem, adr, new_val, adr_type);
         break;
       case T_LONG:
-        load_store = kit->gvn().transform(new GetAndSetLNode(kit->control(), mem, adr, new_val, adr_type));
+        load_store = new GetAndSetLNode(kit->control(), mem, adr, new_val, adr_type);
         break;
       default:
         ShouldNotReachHere();
     }
   }
 
+  load_store->as_LoadStore()->set_barrier_data(access.barrier_data());
+  load_store = kit->gvn().transform(load_store);
+
   access.set_raw_access(load_store);
   pin_atomic_op(access);
 
@@ -581,21 +594,24 @@
 
   switch(access.type()) {
     case T_BYTE:
-      load_store = kit->gvn().transform(new GetAndAddBNode(kit->control(), mem, adr, new_val, adr_type));
+      load_store = new GetAndAddBNode(kit->control(), mem, adr, new_val, adr_type);
       break;
     case T_SHORT:
-      load_store = kit->gvn().transform(new GetAndAddSNode(kit->control(), mem, adr, new_val, adr_type));
+      load_store = new GetAndAddSNode(kit->control(), mem, adr, new_val, adr_type);
       break;
     case T_INT:
-      load_store = kit->gvn().transform(new GetAndAddINode(kit->control(), mem, adr, new_val, adr_type));
+      load_store = new GetAndAddINode(kit->control(), mem, adr, new_val, adr_type);
       break;
     case T_LONG:
-      load_store = kit->gvn().transform(new GetAndAddLNode(kit->control(), mem, adr, new_val, adr_type));
+      load_store = new GetAndAddLNode(kit->control(), mem, adr, new_val, adr_type);
       break;
     default:
       ShouldNotReachHere();
   }
 
+  load_store->as_LoadStore()->set_barrier_data(access.barrier_data());
+  load_store = kit->gvn().transform(load_store);
+
   access.set_raw_access(load_store);
   pin_atomic_op(access);
 
--- a/src/hotspot/share/gc/shared/c2/barrierSetC2.hpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/gc/shared/c2/barrierSetC2.hpp	Wed Nov 13 09:16:04 2019 +0000
@@ -103,6 +103,7 @@
   Node*             _base;
   C2AccessValuePtr& _addr;
   Node*             _raw_access;
+  uint8_t           _barrier_data;
 
   void fixup_decorators();
 
@@ -113,7 +114,8 @@
     _type(type),
     _base(base),
     _addr(addr),
-    _raw_access(NULL)
+    _raw_access(NULL),
+    _barrier_data(0)
   {}
 
   DecoratorSet decorators() const { return _decorators; }
@@ -124,6 +126,9 @@
   bool is_raw() const             { return (_decorators & AS_RAW) != 0; }
   Node* raw_access() const        { return _raw_access; }
 
+  uint8_t barrier_data() const        { return _barrier_data; }
+  void set_barrier_data(uint8_t data) { _barrier_data = data; }
+
   void set_raw_access(Node* raw_access) { _raw_access = raw_access; }
   virtual void set_memory() {} // no-op for normal accesses, but not for atomic accesses.
 
--- a/src/hotspot/share/gc/z/c2/zBarrierSetC2.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/gc/z/c2/zBarrierSetC2.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -178,47 +178,36 @@
   return size;
 }
 
-static bool barrier_needed(C2Access& access) {
-  return ZBarrierSet::barrier_needed(access.decorators(), access.type());
+static void set_barrier_data(C2Access& access) {
+  if (ZBarrierSet::barrier_needed(access.decorators(), access.type())) {
+    if (access.decorators() & ON_WEAK_OOP_REF) {
+      access.set_barrier_data(ZLoadBarrierWeak);
+    } else {
+      access.set_barrier_data(ZLoadBarrierStrong);
+    }
+  }
 }
 
 Node* ZBarrierSetC2::load_at_resolved(C2Access& access, const Type* val_type) const {
-  Node* result = BarrierSetC2::load_at_resolved(access, val_type);
-  if (barrier_needed(access) && access.raw_access()->is_Mem()) {
-    if ((access.decorators() & ON_WEAK_OOP_REF) != 0) {
-      access.raw_access()->as_Load()->set_barrier_data(ZLoadBarrierWeak);
-    } else {
-      access.raw_access()->as_Load()->set_barrier_data(ZLoadBarrierStrong);
-    }
-  }
-
-  return result;
+  set_barrier_data(access);
+  return BarrierSetC2::load_at_resolved(access, val_type);
 }
 
 Node* ZBarrierSetC2::atomic_cmpxchg_val_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
                                                     Node* new_val, const Type* val_type) const {
-  Node* result = BarrierSetC2::atomic_cmpxchg_val_at_resolved(access, expected_val, new_val, val_type);
-  if (barrier_needed(access)) {
-    access.raw_access()->as_LoadStore()->set_barrier_data(ZLoadBarrierStrong);
-  }
-  return result;
+  set_barrier_data(access);
+  return BarrierSetC2::atomic_cmpxchg_val_at_resolved(access, expected_val, new_val, val_type);
 }
 
 Node* ZBarrierSetC2::atomic_cmpxchg_bool_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
                                                      Node* new_val, const Type* value_type) const {
-  Node* result = BarrierSetC2::atomic_cmpxchg_bool_at_resolved(access, expected_val, new_val, value_type);
-  if (barrier_needed(access)) {
-    access.raw_access()->as_LoadStore()->set_barrier_data(ZLoadBarrierStrong);
-  }
-  return result;
+  set_barrier_data(access);
+  return BarrierSetC2::atomic_cmpxchg_bool_at_resolved(access, expected_val, new_val, value_type);
 }
 
 Node* ZBarrierSetC2::atomic_xchg_at_resolved(C2AtomicParseAccess& access, Node* new_val, const Type* val_type) const {
-  Node* result = BarrierSetC2::atomic_xchg_at_resolved(access, new_val, val_type);
-  if (barrier_needed(access)) {
-    access.raw_access()->as_LoadStore()->set_barrier_data(ZLoadBarrierStrong);
-  }
-  return result;
+  set_barrier_data(access);
+  return BarrierSetC2::atomic_xchg_at_resolved(access, new_val, val_type);
 }
 
 bool ZBarrierSetC2::array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type,
--- a/src/hotspot/share/gc/z/zBarrier.hpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/gc/z/zBarrier.hpp	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -41,6 +41,8 @@
   static const bool Publish     = true;
   static const bool Overflow    = false;
 
+  static void self_heal(volatile oop* p, uintptr_t addr, uintptr_t heal_addr);
+
   template <ZBarrierFastPath fast_path, ZBarrierSlowPath slow_path> static oop barrier(volatile oop* p, oop o);
   template <ZBarrierFastPath fast_path, ZBarrierSlowPath slow_path> static oop weak_barrier(volatile oop* p, oop o);
   template <ZBarrierFastPath fast_path, ZBarrierSlowPath slow_path> static void root_barrier(oop* p, oop o);
@@ -49,8 +51,6 @@
   static bool is_good_or_null_fast_path(uintptr_t addr);
   static bool is_weak_good_or_null_fast_path(uintptr_t addr);
 
-  static bool is_resurrection_blocked(volatile oop* p, oop* o);
-
   static bool during_mark();
   static bool during_relocate();
   template <bool finalizable> static bool should_mark_through(uintptr_t addr);
--- a/src/hotspot/share/gc/z/zBarrier.inline.hpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/gc/z/zBarrier.inline.hpp	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -32,11 +32,46 @@
 #include "oops/oop.hpp"
 #include "runtime/atomic.hpp"
 
+inline void ZBarrier::self_heal(volatile oop* p, uintptr_t addr, uintptr_t heal_addr) {
+  if (heal_addr == 0) {
+    // Never heal with null since it interacts badly with reference processing.
+    // A mutator clearing an oop would be similar to calling Reference.clear(),
+    // which would make the reference non-discoverable or silently dropped
+    // by the reference processor.
+    return;
+  }
+
+  for (;;) {
+    if (addr == heal_addr) {
+      // Already healed
+      return;
+    }
+
+    // Heal
+    const uintptr_t prev_addr = Atomic::cmpxchg(heal_addr, (volatile uintptr_t*)p, addr);
+    if (prev_addr == addr) {
+      // Success
+      return;
+    }
+
+    if (ZAddress::is_good_or_null(prev_addr)) {
+      // No need to heal
+      return;
+    }
+
+    // The oop location was healed by another barrier, but it is still not
+    // good or null. Re-apply healing to make sure the oop is not left with
+    // weaker (remapped or finalizable) metadata bits than what this barrier
+    // tried to apply.
+    assert(ZAddress::offset(prev_addr) == ZAddress::offset(heal_addr), "Invalid offset");
+    addr = prev_addr;
+  }
+}
+
 template <ZBarrierFastPath fast_path, ZBarrierSlowPath slow_path>
 inline oop ZBarrier::barrier(volatile oop* p, oop o) {
   uintptr_t addr = ZOop::to_address(o);
 
-retry:
   // Fast path
   if (fast_path(addr)) {
     return ZOop::from_address(addr);
@@ -45,17 +80,8 @@
   // Slow path
   const uintptr_t good_addr = slow_path(addr);
 
-  // Self heal, but only if the address was actually updated by the slow path,
-  // which might not be the case, e.g. when marking through an already good oop.
-  if (p != NULL && good_addr != addr) {
-    const uintptr_t prev_addr = Atomic::cmpxchg(good_addr, (volatile uintptr_t*)p, addr);
-    if (prev_addr != addr) {
-      // Some other thread overwrote the oop. If this oop was updated by a
-      // weak barrier the new oop might not be good, in which case we need
-      // to re-apply this barrier.
-      addr = prev_addr;
-      goto retry;
-    }
+  if (p != NULL) {
+    self_heal(p, addr, good_addr);
   }
 
   return ZOop::from_address(good_addr);
@@ -73,28 +99,12 @@
   }
 
   // Slow path
-  uintptr_t good_addr = slow_path(addr);
+  const uintptr_t good_addr = slow_path(addr);
 
-  // Self heal unless the address returned from the slow path is null,
-  // in which case resurrection was blocked and we must let the reference
-  // processor clear the oop. Mutators are not allowed to clear oops in
-  // these cases, since that would be similar to calling Reference.clear(),
-  // which would make the reference non-discoverable or silently dropped
-  // by the reference processor.
-  if (p != NULL && good_addr != 0) {
-    // The slow path returns a good/marked address, but we never mark oops
-    // in a weak load barrier so we always self heal with the remapped address.
-    const uintptr_t weak_good_addr = ZAddress::remapped(good_addr);
-    const uintptr_t prev_addr = Atomic::cmpxchg(weak_good_addr, (volatile uintptr_t*)p, addr);
-    if (prev_addr != addr) {
-      // Some other thread overwrote the oop. The new
-      // oop is guaranteed to be weak good or null.
-      assert(ZAddress::is_weak_good_or_null(prev_addr), "Bad weak overwrite");
-
-      // Return the good address instead of the weak good address
-      // to ensure that the currently active heap view is used.
-      good_addr = ZAddress::good_or_null(prev_addr);
-    }
+  if (p != NULL) {
+    // The slow path returns a good/marked address or null, but we never mark
+    // oops in a weak load barrier so we always heal with the remapped address.
+    self_heal(p, addr, ZAddress::remapped_or_null(good_addr));
   }
 
   return ZOop::from_address(good_addr);
@@ -134,25 +144,6 @@
   return ZAddress::is_weak_good_or_null(addr);
 }
 
-inline bool ZBarrier::is_resurrection_blocked(volatile oop* p, oop* o) {
-  const bool is_blocked = ZResurrection::is_blocked();
-
-  // Reload oop after checking the resurrection blocked state. This is
-  // done to prevent a race where we first load an oop, which is logically
-  // null but not yet cleared, then this oop is cleared by the reference
-  // processor and resurrection is unblocked. At this point the mutator
-  // would see the unblocked state and pass this invalid oop through the
-  // normal barrier path, which would incorrectly try to mark this oop.
-  if (p != NULL) {
-    // First assign to reloaded_o to avoid compiler warning about
-    // implicit dereference of volatile oop.
-    const oop reloaded_o = *p;
-    *o = reloaded_o;
-  }
-
-  return is_blocked;
-}
-
 //
 // Load barrier
 //
@@ -190,16 +181,16 @@
 inline oop ZBarrier::load_barrier_on_weak_oop_field_preloaded(volatile oop* p, oop o) {
   verify_on_weak(p);
 
-  if (is_resurrection_blocked(p, &o)) {
-    return weak_barrier<is_good_or_null_fast_path, weak_load_barrier_on_weak_oop_slow_path>(p, o);
+  if (ZResurrection::is_blocked()) {
+    return barrier<is_good_or_null_fast_path, weak_load_barrier_on_weak_oop_slow_path>(p, o);
   }
 
   return load_barrier_on_oop_field_preloaded(p, o);
 }
 
 inline oop ZBarrier::load_barrier_on_phantom_oop_field_preloaded(volatile oop* p, oop o) {
-  if (is_resurrection_blocked(p, &o)) {
-    return weak_barrier<is_good_or_null_fast_path, weak_load_barrier_on_phantom_oop_slow_path>(p, o);
+  if (ZResurrection::is_blocked()) {
+    return barrier<is_good_or_null_fast_path, weak_load_barrier_on_phantom_oop_slow_path>(p, o);
   }
 
   return load_barrier_on_oop_field_preloaded(p, o);
@@ -235,8 +226,8 @@
 inline oop ZBarrier::weak_load_barrier_on_weak_oop_field_preloaded(volatile oop* p, oop o) {
   verify_on_weak(p);
 
-  if (is_resurrection_blocked(p, &o)) {
-    return weak_barrier<is_good_or_null_fast_path, weak_load_barrier_on_weak_oop_slow_path>(p, o);
+  if (ZResurrection::is_blocked()) {
+    return barrier<is_good_or_null_fast_path, weak_load_barrier_on_weak_oop_slow_path>(p, o);
   }
 
   return weak_load_barrier_on_oop_field_preloaded(p, o);
@@ -252,8 +243,8 @@
 }
 
 inline oop ZBarrier::weak_load_barrier_on_phantom_oop_field_preloaded(volatile oop* p, oop o) {
-  if (is_resurrection_blocked(p, &o)) {
-    return weak_barrier<is_good_or_null_fast_path, weak_load_barrier_on_phantom_oop_slow_path>(p, o);
+  if (ZResurrection::is_blocked()) {
+    return barrier<is_good_or_null_fast_path, weak_load_barrier_on_phantom_oop_slow_path>(p, o);
   }
 
   return weak_load_barrier_on_oop_field_preloaded(p, o);
--- a/src/hotspot/share/gc/z/zHeap.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/gc/z/zHeap.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -40,6 +40,7 @@
 #include "logging/log.hpp"
 #include "memory/iterator.hpp"
 #include "memory/resourceArea.hpp"
+#include "runtime/handshake.hpp"
 #include "runtime/safepoint.hpp"
 #include "runtime/thread.hpp"
 #include "utilities/debug.hpp"
@@ -315,7 +316,7 @@
   // Process weak roots
   _weak_roots_processor.process_weak_roots();
 
-  // Prepare to unload unused classes and code
+  // Prepare to unload stale metadata and nmethods
   _unload.prepare();
 
   return true;
@@ -325,6 +326,11 @@
   _reference_processor.set_soft_reference_policy(clear);
 }
 
+class ZRendezvousClosure : public ThreadClosure {
+public:
+  virtual void do_thread(Thread* thread) {}
+};
+
 void ZHeap::process_non_strong_references() {
   // Process Soft/Weak/Final/PhantomReferences
   _reference_processor.process_references();
@@ -332,8 +338,22 @@
   // Process concurrent weak roots
   _weak_roots_processor.process_concurrent_weak_roots();
 
-  // Unload unused classes and code
-  _unload.unload();
+  // Unlink stale metadata and nmethods
+  _unload.unlink();
+
+  // Perform a handshake. This is needed 1) to make sure that stale
+  // metadata and nmethods are no longer observable. And 2), to
+  // prevent the race where a mutator first loads an oop, which is
+  // logically null but not yet cleared. Then this oop gets cleared
+  // by the reference processor and resurrection is unblocked. At
+  // this point the mutator could see the unblocked state and pass
+  // this invalid oop through the normal barrier path, which would
+  // incorrectly try to mark the oop.
+  ZRendezvousClosure cl;
+  Handshake::execute(&cl);
+
+  // Purge stale metadata and nmethods that were unlinked
+  _unload.purge();
 
   // Unblock resurrection of weak/phantom references
   ZResurrection::unblock();
@@ -405,7 +425,7 @@
 void ZHeap::relocate_start() {
   assert(SafepointSynchronize::is_at_safepoint(), "Should be at safepoint");
 
-  // Finish unloading of classes and code
+  // Finish unloading stale metadata and nmethods
   _unload.finish();
 
   // Flip address view
--- a/src/hotspot/share/gc/z/zLiveMap.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/gc/z/zLiveMap.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -54,7 +54,9 @@
 
   // Multiple threads can enter here, make sure only one of them
   // resets the marking information while the others busy wait.
-  for (uint32_t seqnum = _seqnum; seqnum != ZGlobalSeqNum; seqnum = _seqnum) {
+  for (uint32_t seqnum = OrderAccess::load_acquire(&_seqnum);
+       seqnum != ZGlobalSeqNum;
+       seqnum = OrderAccess::load_acquire(&_seqnum)) {
     if ((seqnum != seqnum_initializing) &&
         (Atomic::cmpxchg(seqnum_initializing, &_seqnum, seqnum) == seqnum)) {
       // Reset marking information
@@ -65,13 +67,13 @@
       segment_live_bits().clear();
       segment_claim_bits().clear();
 
-      // Make sure the newly reset marking information is
-      // globally visible before updating the page seqnum.
-      OrderAccess::storestore();
+      assert(_seqnum == seqnum_initializing, "Invalid");
 
-      // Update seqnum
-      assert(_seqnum == seqnum_initializing, "Invalid");
-      _seqnum = ZGlobalSeqNum;
+      // Make sure the newly reset marking information is ordered
+      // before the update of the page seqnum, such that when the
+      // up-to-date seqnum is load acquired, the bit maps will not
+      // contain stale information.
+      OrderAccess::release_store(&_seqnum, ZGlobalSeqNum);
       break;
     }
 
@@ -93,10 +95,6 @@
   if (!claim_segment(segment)) {
     // Already claimed, wait for live bit to be set
     while (!is_segment_live(segment)) {
-      // Busy wait. The loadload barrier is needed to make
-      // sure we re-read the live bit every time we loop.
-      OrderAccess::loadload();
-
       // Mark reset contention
       if (!contention) {
         // Count contention once
@@ -122,7 +120,7 @@
   }
 
   // Set live bit
-  const bool success = set_segment_live_atomic(segment);
+  const bool success = set_segment_live(segment);
   assert(success, "Should never fail");
 }
 
--- a/src/hotspot/share/gc/z/zLiveMap.hpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/gc/z/zLiveMap.hpp	Wed Nov 13 09:16:04 2019 +0000
@@ -55,7 +55,7 @@
   BitMap::idx_t segment_end(BitMap::idx_t segment) const;
 
   bool is_segment_live(BitMap::idx_t segment) const;
-  bool set_segment_live_atomic(BitMap::idx_t segment);
+  bool set_segment_live(BitMap::idx_t segment);
 
   BitMap::idx_t first_live_segment() const;
   BitMap::idx_t next_live_segment(BitMap::idx_t segment) const;
@@ -80,9 +80,9 @@
   size_t live_bytes() const;
 
   bool get(size_t index) const;
-  bool set_atomic(size_t index, bool finalizable, bool& inc_live);
+  bool set(size_t index, bool finalizable, bool& inc_live);
 
-  void inc_live_atomic(uint32_t objects, size_t bytes);
+  void inc_live(uint32_t objects, size_t bytes);
 
   void iterate(ObjectClosure* cl, uintptr_t page_start, size_t page_object_alignment_shift);
 };
--- a/src/hotspot/share/gc/z/zLiveMap.inline.hpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/gc/z/zLiveMap.inline.hpp	Wed Nov 13 09:16:04 2019 +0000
@@ -30,6 +30,7 @@
 #include "gc/z/zOop.inline.hpp"
 #include "gc/z/zUtils.inline.hpp"
 #include "runtime/atomic.hpp"
+#include "runtime/orderAccess.hpp"
 #include "utilities/bitMap.inline.hpp"
 #include "utilities/debug.hpp"
 
@@ -38,7 +39,7 @@
 }
 
 inline bool ZLiveMap::is_marked() const {
-  return _seqnum == ZGlobalSeqNum;
+  return OrderAccess::load_acquire(&_seqnum) == ZGlobalSeqNum;
 }
 
 inline uint32_t ZLiveMap::live_objects() const {
@@ -68,15 +69,15 @@
 }
 
 inline bool ZLiveMap::is_segment_live(BitMap::idx_t segment) const {
-  return segment_live_bits().at(segment);
+  return segment_live_bits().par_at(segment);
 }
 
-inline bool ZLiveMap::set_segment_live_atomic(BitMap::idx_t segment) {
-  return segment_live_bits().par_set_bit(segment);
+inline bool ZLiveMap::set_segment_live(BitMap::idx_t segment) {
+  return segment_live_bits().par_set_bit(segment, memory_order_release);
 }
 
 inline bool ZLiveMap::claim_segment(BitMap::idx_t segment) {
-  return segment_claim_bits().par_set_bit(segment);
+  return segment_claim_bits().par_set_bit(segment, memory_order_acq_rel);
 }
 
 inline BitMap::idx_t ZLiveMap::first_live_segment() const {
@@ -102,7 +103,7 @@
          _bitmap.at(index);          // Object is marked
 }
 
-inline bool ZLiveMap::set_atomic(size_t index, bool finalizable, bool& inc_live) {
+inline bool ZLiveMap::set(size_t index, bool finalizable, bool& inc_live) {
   if (!is_marked()) {
     // First object to be marked during this
     // cycle, reset marking information.
@@ -119,7 +120,7 @@
   return _bitmap.par_set_bit_pair(index, finalizable, inc_live);
 }
 
-inline void ZLiveMap::inc_live_atomic(uint32_t objects, size_t bytes) {
+inline void ZLiveMap::inc_live(uint32_t objects, size_t bytes) {
   Atomic::add(objects, &_live_objects);
   Atomic::add(bytes, &_live_bytes);
 }
--- a/src/hotspot/share/gc/z/zMarkCache.inline.hpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/gc/z/zMarkCache.inline.hpp	Wed Nov 13 09:16:04 2019 +0000
@@ -44,7 +44,7 @@
 inline void ZMarkCacheEntry::evict() {
   if (_page != NULL) {
     // Write cached data out to page
-    _page->inc_live_atomic(_objects, _bytes);
+    _page->inc_live(_objects, _bytes);
     _page = NULL;
   }
 }
--- a/src/hotspot/share/gc/z/zMarkStack.hpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/gc/z/zMarkStack.hpp	Wed Nov 13 09:16:04 2019 +0000
@@ -62,8 +62,8 @@
 
   bool is_empty() const;
 
-  void push_atomic(T* stack);
-  T* pop_atomic();
+  void push(T* stack);
+  T* pop();
 };
 
 typedef ZStack<ZMarkStackEntry, ZMarkStackSlots>     ZMarkStack;
--- a/src/hotspot/share/gc/z/zMarkStack.inline.hpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/gc/z/zMarkStack.inline.hpp	Wed Nov 13 09:16:04 2019 +0000
@@ -114,7 +114,7 @@
 }
 
 template <typename T>
-inline void ZStackList<T>::push_atomic(T* stack) {
+inline void ZStackList<T>::push(T* stack) {
   T* vstack = _head;
   uint32_t version = 0;
 
@@ -133,7 +133,7 @@
 }
 
 template <typename T>
-inline T* ZStackList<T>::pop_atomic() {
+inline T* ZStackList<T>::pop() {
   T* vstack = _head;
   T* stack = NULL;
   uint32_t version = 0;
@@ -168,20 +168,20 @@
   // contention between mutators and GC workers as much as possible, while
   // still allowing GC workers to help out and steal work from each other.
   if (publish) {
-    _published.push_atomic(stack);
+    _published.push(stack);
   } else {
-    _overflowed.push_atomic(stack);
+    _overflowed.push(stack);
   }
 }
 
 inline ZMarkStack* ZMarkStripe::steal_stack() {
   // Steal overflowed stacks first, then published stacks
-  ZMarkStack* const stack = _overflowed.pop_atomic();
+  ZMarkStack* const stack = _overflowed.pop();
   if (stack != NULL) {
     return stack;
   }
 
-  return _published.pop_atomic();
+  return _published.pop();
 }
 
 inline size_t ZMarkStripeSet::nstripes() const {
--- a/src/hotspot/share/gc/z/zMarkStackAllocator.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/gc/z/zMarkStackAllocator.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -166,7 +166,7 @@
 
 ZMarkStackMagazine* ZMarkStackAllocator::alloc_magazine() {
   // Try allocating from the free list first
-  ZMarkStackMagazine* const magazine = _freelist.pop_atomic();
+  ZMarkStackMagazine* const magazine = _freelist.pop();
   if (magazine != NULL) {
     return magazine;
   }
@@ -181,5 +181,5 @@
 }
 
 void ZMarkStackAllocator::free_magazine(ZMarkStackMagazine* magazine) {
-  _freelist.push_atomic(magazine);
+  _freelist.push(magazine);
 }
--- a/src/hotspot/share/gc/z/zPage.hpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/gc/z/zPage.hpp	Wed Nov 13 09:16:04 2019 +0000
@@ -96,7 +96,7 @@
   bool is_object_strongly_live(uintptr_t addr) const;
   bool mark_object(uintptr_t addr, bool finalizable, bool& inc_live);
 
-  void inc_live_atomic(uint32_t objects, size_t bytes);
+  void inc_live(uint32_t objects, size_t bytes);
   uint32_t live_objects() const;
   size_t live_bytes() const;
 
--- a/src/hotspot/share/gc/z/zPage.inline.hpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/gc/z/zPage.inline.hpp	Wed Nov 13 09:16:04 2019 +0000
@@ -207,11 +207,11 @@
 
   // Set mark bit
   const size_t index = ((ZAddress::offset(addr) - start()) >> object_alignment_shift()) * 2;
-  return _livemap.set_atomic(index, finalizable, inc_live);
+  return _livemap.set(index, finalizable, inc_live);
 }
 
-inline void ZPage::inc_live_atomic(uint32_t objects, size_t bytes) {
-  _livemap.inc_live_atomic(objects, bytes);
+inline void ZPage::inc_live(uint32_t objects, size_t bytes) {
+  _livemap.inc_live(objects, bytes);
 }
 
 inline uint32_t ZPage::live_objects() const {
--- a/src/hotspot/share/gc/z/zUnload.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/gc/z/zUnload.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -36,7 +36,8 @@
 #include "gc/z/zUnload.hpp"
 #include "oops/access.inline.hpp"
 
-static const ZStatSubPhase ZSubPhaseConcurrentClassesUnload("Concurrent Classes Unload");
+static const ZStatSubPhase ZSubPhaseConcurrentClassesUnlink("Concurrent Classes Unlink");
+static const ZStatSubPhase ZSubPhaseConcurrentClassesPurge("Concurrent Classes Purge");
 
 class ZIsUnloadingOopClosure : public OopClosure {
 private:
@@ -126,6 +127,11 @@
 }
 
 void ZUnload::unlink() {
+  if (!ClassUnloading) {
+    return;
+  }
+
+  ZStatTimer timer(ZSubPhaseConcurrentClassesUnlink);
   SuspendibleThreadSetJoiner sts;
   bool unloading_occurred;
 
@@ -135,13 +141,17 @@
   }
 
   Klass::clean_weak_klass_links(unloading_occurred);
-
   ZNMethod::unlink(_workers, unloading_occurred);
-
   DependencyContext::cleaning_end();
 }
 
 void ZUnload::purge() {
+  if (!ClassUnloading) {
+    return;
+  }
+
+  ZStatTimer timer(ZSubPhaseConcurrentClassesPurge);
+
   {
     SuspendibleThreadSetJoiner sts;
     ZNMethod::purge(_workers);
@@ -151,29 +161,6 @@
   CodeCache::purge_exception_caches();
 }
 
-class ZUnloadRendezvousClosure : public ThreadClosure {
-public:
-  void do_thread(Thread* thread) {}
-};
-
-void ZUnload::unload() {
-  if (!ClassUnloading) {
-    return;
-  }
-
-  ZStatTimer timer(ZSubPhaseConcurrentClassesUnload);
-
-  // Unlink stale metadata and nmethods
-  unlink();
-
-  // Make sure stale metadata and nmethods are no longer observable
-  ZUnloadRendezvousClosure cl;
-  Handshake::execute(&cl);
-
-  // Purge stale metadata and nmethods that were unlinked
-  purge();
-}
-
 void ZUnload::finish() {
   // Resize and verify metaspace
   MetaspaceGC::compute_new_size();
--- a/src/hotspot/share/gc/z/zUnload.hpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/gc/z/zUnload.hpp	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -30,14 +30,12 @@
 private:
   ZWorkers* const _workers;
 
-  void unlink();
-  void purge();
-
 public:
   ZUnload(ZWorkers* workers);
 
   void prepare();
-  void unload();
+  void unlink();
+  void purge();
   void finish();
 };
 
--- a/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -34,6 +34,8 @@
 #include "jvmci/jvmciCompilerToVM.hpp"
 #include "jvmci/jvmciCodeInstaller.hpp"
 #include "jvmci/jvmciRuntime.hpp"
+#include "logging/log.hpp"
+#include "logging/logTag.hpp"
 #include "memory/oopFactory.hpp"
 #include "memory/universe.hpp"
 #include "oops/constantPool.inline.hpp"
@@ -2296,11 +2298,9 @@
             method->name_and_sig_as_C_string(), p2i(method->native_function()), p2i(entry)));
       }
       method->set_native_function(entry, Method::native_bind_event_is_interesting);
-      if (PrintJNIResolving) {
-        tty->print_cr("[Dynamic-linking native method %s.%s ... JNI]",
-          method->method_holder()->external_name(),
-          method->name()->as_C_string());
-      }
+      log_debug(jni, resolve)("[Dynamic-linking native method %s.%s ... JNI]",
+                              method->method_holder()->external_name(),
+                              method->name()->as_C_string());
     }
   }
 
--- a/src/hotspot/share/jvmci/jvmci_globals.hpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/jvmci/jvmci_globals.hpp	Wed Nov 13 09:16:04 2019 +0000
@@ -49,10 +49,14 @@
           "Enable JVMCI")                                                   \
                                                                             \
   experimental(bool, EnableJVMCIProduct, false,                             \
-          "Allow JVMCI to be used in product mode")                         \
+          "Allow JVMCI to be used in product mode. This alters a subset of "\
+          "JVMCI flags to be non-experimental, defaults UseJVMCICompiler "  \
+          "to true and defaults UseJVMCINativeLibrary to true if a JVMCI "  \
+          "native library is available.")                                   \
                                                                             \
   experimental(bool, UseJVMCICompiler, false,                               \
-          "Use JVMCI as the default compiler")                              \
+          "Use JVMCI as the default compiler. Defaults to true if "         \
+          "EnableJVMCIProduct is true.")                                    \
                                                                             \
   experimental(bool, JVMCIPrintProperties, false,                           \
           "Prints properties used by the JVMCI compiler and exits")         \
@@ -117,7 +121,8 @@
   experimental(bool, UseJVMCINativeLibrary, false,                          \
           "Execute JVMCI Java code from a shared library "                  \
           "instead of loading it from class files and executing it "        \
-          "on the HotSpot heap")                                            \
+          "on the HotSpot heap. Defaults to true if EnableJVMCIProduct is " \
+          "true and a JVMCI native library is available.")\
                                                                             \
   NOT_COMPILER2(diagnostic(bool, UseMultiplyToLenIntrinsic, false,          \
           "Enables intrinsification of BigInteger.multiplyToLen()"))        \
--- a/src/hotspot/share/oops/method.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/oops/method.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -36,6 +36,8 @@
 #include "interpreter/bytecodes.hpp"
 #include "interpreter/interpreter.hpp"
 #include "interpreter/oopMapCache.hpp"
+#include "logging/log.hpp"
+#include "logging/logTag.hpp"
 #include "memory/allocation.inline.hpp"
 #include "memory/heapInspection.hpp"
 #include "memory/metadataFactory.hpp"
@@ -448,11 +450,11 @@
   } else {
     method->clear_native_function();
   }
-  if (PrintJNIResolving) {
+  if (log_is_enabled(Debug, jni, resolve)) {
     ResourceMark rm(THREAD);
-    tty->print_cr("[Registering JNI native method %s.%s]",
-      method->method_holder()->external_name(),
-      method->name()->as_C_string());
+    log_debug(jni, resolve)("[Registering JNI native method %s.%s]",
+                            method->method_holder()->external_name(),
+                            method->name()->as_C_string());
   }
   return true;
 }
--- a/src/hotspot/share/opto/graphKit.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/opto/graphKit.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -1493,18 +1493,19 @@
                           bool require_atomic_access,
                           bool unaligned,
                           bool mismatched,
-                          bool unsafe) {
+                          bool unsafe,
+                          uint8_t barrier_data) {
   assert(adr_idx != Compile::AliasIdxTop, "use other make_load factory" );
   const TypePtr* adr_type = NULL; // debug-mode-only argument
   debug_only(adr_type = C->get_adr_type(adr_idx));
   Node* mem = memory(adr_idx);
   Node* ld;
   if (require_atomic_access && bt == T_LONG) {
-    ld = LoadLNode::make_atomic(ctl, mem, adr, adr_type, t, mo, control_dependency, unaligned, mismatched, unsafe);
+    ld = LoadLNode::make_atomic(ctl, mem, adr, adr_type, t, mo, control_dependency, unaligned, mismatched, unsafe, barrier_data);
   } else if (require_atomic_access && bt == T_DOUBLE) {
-    ld = LoadDNode::make_atomic(ctl, mem, adr, adr_type, t, mo, control_dependency, unaligned, mismatched, unsafe);
+    ld = LoadDNode::make_atomic(ctl, mem, adr, adr_type, t, mo, control_dependency, unaligned, mismatched, unsafe, barrier_data);
   } else {
-    ld = LoadNode::make(_gvn, ctl, mem, adr, adr_type, t, bt, mo, control_dependency, unaligned, mismatched, unsafe);
+    ld = LoadNode::make(_gvn, ctl, mem, adr, adr_type, t, bt, mo, control_dependency, unaligned, mismatched, unsafe, barrier_data);
   }
   ld = _gvn.transform(ld);
   if (((bt == T_OBJECT) && C->do_escape_analysis()) || C->eliminate_boxing()) {
--- a/src/hotspot/share/opto/graphKit.hpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/opto/graphKit.hpp	Wed Nov 13 09:16:04 2019 +0000
@@ -523,27 +523,27 @@
   Node* make_load(Node* ctl, Node* adr, const Type* t, BasicType bt,
                   MemNode::MemOrd mo, LoadNode::ControlDependency control_dependency = LoadNode::DependsOnlyOnTest,
                   bool require_atomic_access = false, bool unaligned = false,
-                  bool mismatched = false, bool unsafe = false) {
+                  bool mismatched = false, bool unsafe = false, uint8_t barrier_data = 0) {
     // This version computes alias_index from bottom_type
     return make_load(ctl, adr, t, bt, adr->bottom_type()->is_ptr(),
                      mo, control_dependency, require_atomic_access,
-                     unaligned, mismatched, unsafe);
+                     unaligned, mismatched, unsafe, barrier_data);
   }
   Node* make_load(Node* ctl, Node* adr, const Type* t, BasicType bt, const TypePtr* adr_type,
                   MemNode::MemOrd mo, LoadNode::ControlDependency control_dependency = LoadNode::DependsOnlyOnTest,
                   bool require_atomic_access = false, bool unaligned = false,
-                  bool mismatched = false, bool unsafe = false) {
+                  bool mismatched = false, bool unsafe = false, uint8_t barrier_data = 0) {
     // This version computes alias_index from an address type
     assert(adr_type != NULL, "use other make_load factory");
     return make_load(ctl, adr, t, bt, C->get_alias_index(adr_type),
                      mo, control_dependency, require_atomic_access,
-                     unaligned, mismatched, unsafe);
+                     unaligned, mismatched, unsafe, barrier_data);
   }
   // This is the base version which is given an alias index.
   Node* make_load(Node* ctl, Node* adr, const Type* t, BasicType bt, int adr_idx,
                   MemNode::MemOrd mo, LoadNode::ControlDependency control_dependency = LoadNode::DependsOnlyOnTest,
                   bool require_atomic_access = false, bool unaligned = false,
-                  bool mismatched = false, bool unsafe = false);
+                  bool mismatched = false, bool unsafe = false, uint8_t barrier_data = 0);
 
   // Create & transform a StoreNode and store the effect into the
   // parser's memory state.
--- a/src/hotspot/share/opto/loopTransform.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/opto/loopTransform.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -2975,16 +2975,17 @@
 }
 
 #ifdef ASSERT
-static CountedLoopNode* locate_pre_from_main(CountedLoopNode *cl) {
-  Node *ctrl  = cl->skip_predicates();
+static CountedLoopNode* locate_pre_from_main(CountedLoopNode* main_loop) {
+  assert(!main_loop->is_main_no_pre_loop(), "Does not have a pre loop");
+  Node* ctrl = main_loop->skip_predicates();
   assert(ctrl->Opcode() == Op_IfTrue || ctrl->Opcode() == Op_IfFalse, "");
-  Node *iffm = ctrl->in(0);
+  Node* iffm = ctrl->in(0);
   assert(iffm->Opcode() == Op_If, "");
-  Node *p_f = iffm->in(0);
+  Node* p_f = iffm->in(0);
   assert(p_f->Opcode() == Op_IfFalse, "");
-  CountedLoopEndNode *pre_end = p_f->in(0)->as_CountedLoopEnd();
-  assert(pre_end->loopnode()->is_pre_loop(), "");
-  return pre_end->loopnode();
+  CountedLoopNode* pre_loop = p_f->in(0)->as_CountedLoopEnd()->loopnode();
+  assert(pre_loop->is_pre_loop(), "No pre loop found");
+  return pre_loop;
 }
 #endif
 
@@ -3010,7 +3011,7 @@
   }
 
   CountedLoopNode* main_head = next_head->as_CountedLoop();
-  if (!main_head->is_main_loop()) {
+  if (!main_head->is_main_loop() || main_head->is_main_no_pre_loop()) {
     return;
   }
 
--- a/src/hotspot/share/opto/memnode.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/opto/memnode.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -806,7 +806,7 @@
 //----------------------------LoadNode::make-----------------------------------
 // Polymorphic factory method:
 Node *LoadNode::make(PhaseGVN& gvn, Node *ctl, Node *mem, Node *adr, const TypePtr* adr_type, const Type *rt, BasicType bt, MemOrd mo,
-                     ControlDependency control_dependency, bool unaligned, bool mismatched, bool unsafe) {
+                     ControlDependency control_dependency, bool unaligned, bool mismatched, bool unsafe, uint8_t barrier_data) {
   Compile* C = gvn.C;
 
   // sanity check the alias category against the created node type
@@ -857,6 +857,7 @@
   if (unsafe) {
     load->set_unsafe_access();
   }
+  load->set_barrier_data(barrier_data);
   if (load->Opcode() == Op_LoadN) {
     Node* ld = gvn.transform(load);
     return new DecodeNNode(ld, ld->bottom_type()->make_ptr());
@@ -866,7 +867,7 @@
 }
 
 LoadLNode* LoadLNode::make_atomic(Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, const Type* rt, MemOrd mo,
-                                  ControlDependency control_dependency, bool unaligned, bool mismatched, bool unsafe) {
+                                  ControlDependency control_dependency, bool unaligned, bool mismatched, bool unsafe, uint8_t barrier_data) {
   bool require_atomic = true;
   LoadLNode* load = new LoadLNode(ctl, mem, adr, adr_type, rt->is_long(), mo, control_dependency, require_atomic);
   if (unaligned) {
@@ -878,11 +879,12 @@
   if (unsafe) {
     load->set_unsafe_access();
   }
+  load->set_barrier_data(barrier_data);
   return load;
 }
 
 LoadDNode* LoadDNode::make_atomic(Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, const Type* rt, MemOrd mo,
-                                  ControlDependency control_dependency, bool unaligned, bool mismatched, bool unsafe) {
+                                  ControlDependency control_dependency, bool unaligned, bool mismatched, bool unsafe, uint8_t barrier_data) {
   bool require_atomic = true;
   LoadDNode* load = new LoadDNode(ctl, mem, adr, adr_type, rt, mo, control_dependency, require_atomic);
   if (unaligned) {
@@ -894,6 +896,7 @@
   if (unsafe) {
     load->set_unsafe_access();
   }
+  load->set_barrier_data(barrier_data);
   return load;
 }
 
--- a/src/hotspot/share/opto/memnode.hpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/opto/memnode.hpp	Wed Nov 13 09:16:04 2019 +0000
@@ -228,7 +228,8 @@
   static Node* make(PhaseGVN& gvn, Node *c, Node *mem, Node *adr,
                     const TypePtr* at, const Type *rt, BasicType bt,
                     MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest,
-                    bool unaligned = false, bool mismatched = false, bool unsafe = false);
+                    bool unaligned = false, bool mismatched = false, bool unsafe = false,
+                    uint8_t barrier_data = 0);
 
   virtual uint hash()   const;  // Check the type
 
@@ -412,7 +413,7 @@
   bool require_atomic_access() const { return _require_atomic_access; }
   static LoadLNode* make_atomic(Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type,
                                 const Type* rt, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest,
-                                bool unaligned = false, bool mismatched = false, bool unsafe = false);
+                                bool unaligned = false, bool mismatched = false, bool unsafe = false, uint8_t barrier_data = 0);
 #ifndef PRODUCT
   virtual void dump_spec(outputStream *st) const {
     LoadNode::dump_spec(st);
@@ -464,7 +465,7 @@
   bool require_atomic_access() const { return _require_atomic_access; }
   static LoadDNode* make_atomic(Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type,
                                 const Type* rt, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest,
-                                bool unaligned = false, bool mismatched = false, bool unsafe = false);
+                                bool unaligned = false, bool mismatched = false, bool unsafe = false, uint8_t barrier_data = 0);
 #ifndef PRODUCT
   virtual void dump_spec(outputStream *st) const {
     LoadNode::dump_spec(st);
--- a/src/hotspot/share/opto/phaseX.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/opto/phaseX.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -891,7 +891,10 @@
 }
 
 bool PhaseGVN::is_dominator_helper(Node *d, Node *n, bool linear_only) {
-  if (d->is_top() || n->is_top()) {
+  if (d->is_top() || (d->is_Proj() && d->in(0)->is_top())) {
+    return false;
+  }
+  if (n->is_top() || (n->is_Proj() && n->in(0)->is_top())) {
     return false;
   }
   assert(d->is_CFG() && n->is_CFG(), "must have CFG nodes");
--- a/src/hotspot/share/prims/jniCheck.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/prims/jniCheck.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -28,6 +28,8 @@
 #include "classfile/javaClasses.inline.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "classfile/vmSymbols.hpp"
+#include "logging/log.hpp"
+#include "logging/logTag.hpp"
 #include "memory/allocation.inline.hpp"
 #include "memory/guardedMemory.hpp"
 #include "oops/instanceKlass.hpp"
@@ -2303,10 +2305,7 @@
          "Mismatched JNINativeInterface tables, check for new entries");
 
   // with -verbose:jni this message will print
-  if (PrintJNIResolving) {
-    tty->print_cr("Checked JNI functions are being used to " \
-                  "validate JNI usage");
-  }
+  log_debug(jni, resolve)("Checked JNI functions are being used to validate JNI usage");
 
   return &checked_jni_NativeInterface;
 }
--- a/src/hotspot/share/prims/jvmtiEnv.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/prims/jvmtiEnv.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -809,14 +809,11 @@
     LogConfiguration::configure_stdout(level, false, LOG_TAGS(class, load));
     break;
   case JVMTI_VERBOSE_GC:
-    if (value == 0) {
-      LogConfiguration::configure_stdout(LogLevel::Off, true, LOG_TAGS(gc));
-    } else {
-      LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(gc));
-    }
+    LogConfiguration::configure_stdout(level, true, LOG_TAGS(gc));
     break;
   case JVMTI_VERBOSE_JNI:
-    PrintJNIResolving = value != 0;
+    level = value == 0 ? LogLevel::Off : LogLevel::Debug;
+    LogConfiguration::configure_stdout(level, true, LOG_TAGS(jni, resolve));
     break;
   default:
     return JVMTI_ERROR_ILLEGAL_ARGUMENT;
--- a/src/hotspot/share/prims/nativeLookup.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/prims/nativeLookup.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -27,6 +27,8 @@
 #include "classfile/symbolTable.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "classfile/vmSymbols.hpp"
+#include "logging/log.hpp"
+#include "logging/logTag.hpp"
 #include "memory/oopFactory.hpp"
 #include "memory/resourceArea.hpp"
 #include "oops/instanceKlass.hpp"
@@ -413,11 +415,11 @@
     method->set_native_function(entry,
       Method::native_bind_event_is_interesting);
     // -verbose:jni printing
-    if (PrintJNIResolving) {
+    if (log_is_enabled(Debug, jni, resolve)) {
       ResourceMark rm(THREAD);
-      tty->print_cr("[Dynamic-linking native method %s.%s ... JNI]",
-        method->method_holder()->external_name(),
-        method->name()->as_C_string());
+      log_debug(jni, resolve)("[Dynamic-linking native method %s.%s ... JNI]",
+                              method->method_holder()->external_name(),
+                              method->name()->as_C_string());
     }
   }
   return method->native_function();
--- a/src/hotspot/share/runtime/arguments.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/runtime/arguments.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -588,6 +588,7 @@
   { "TraceSafepointCleanupTime", LogLevel::Info,  true,  LOG_TAGS(safepoint, cleanup) },
   { "TraceJVMTIObjectTagging",   LogLevel::Debug, true,  LOG_TAGS(jvmti, objecttagging) },
   { "TraceRedefineClasses",      LogLevel::Info,  false, LOG_TAGS(redefine, class) },
+  { "PrintJNIResolving",         LogLevel::Debug, true,  LOG_TAGS(jni, resolve) },
   { NULL,                        LogLevel::Off,   false, LOG_TAGS(_NO_TAG) }
 };
 
@@ -2400,9 +2401,7 @@
       } else if (!strcmp(tail, ":gc")) {
         LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(gc));
       } else if (!strcmp(tail, ":jni")) {
-        if (FLAG_SET_CMDLINE(PrintJNIResolving, true) != JVMFlag::SUCCESS) {
-          return JNI_EINVAL;
-        }
+        LogConfiguration::configure_stdout(LogLevel::Debug, true, LOG_TAGS(jni, resolve));
       }
     // -da / -ea / -disableassertions / -enableassertions
     // These accept an optional class/package name separated by a colon, e.g.,
--- a/src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -61,7 +61,7 @@
  *    'TieredStopAtLevel = CompLevel_full_optimization' (the default value). As a result,
  *    the minimum number of compiler threads is 2.
  * 5) Non-tiered emulation mode is on. CompilationModeFlag::disable_intermediate() == true.
- *    The mininum number of threads is 2. But if CompilationModeFlag::quick_internal() == false, then it's 1.
+ *    The minimum number of threads is 2. But if CompilationModeFlag::quick_internal() == false, then it's 1.
  */
 JVMFlag::Error CICompilerCountConstraintFunc(intx value, bool verbose) {
   int min_number_of_compiler_threads = 0;
--- a/src/hotspot/share/runtime/globals.hpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/runtime/globals.hpp	Wed Nov 13 09:16:04 2019 +0000
@@ -305,9 +305,6 @@
   notproduct(bool, TraceCodeBlobStacks, false,                              \
           "Trace stack-walk of codeblobs")                                  \
                                                                             \
-  product(bool, PrintJNIResolving, false,                                   \
-          "Used to implement -v:jni")                                       \
-                                                                            \
   notproduct(bool, PrintRewrites, false,                                    \
           "Print methods that are being rewritten")                         \
                                                                             \
--- a/src/hotspot/share/runtime/java.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/hotspot/share/runtime/java.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -733,6 +733,7 @@
   return (e > o) ? 1 : ((e == o) ? 0 : -1);
 }
 
+/* See JEP 223 */
 void JDK_Version::to_string(char* buffer, size_t buflen) const {
   assert(buffer && buflen > 0, "call with useful buffer");
   size_t index = 0;
@@ -744,13 +745,12 @@
         &buffer[index], buflen - index, "%d.%d", _major, _minor);
     if (rc == -1) return;
     index += rc;
-    if (_security > 0) {
-      rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _security);
+    if (_patch > 0) {
+      rc = jio_snprintf(&buffer[index], buflen - index, ".%d.%d", _security, _patch);
       if (rc == -1) return;
       index += rc;
-    }
-    if (_patch > 0) {
-      rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _patch);
+    } else if (_security > 0) {
+      rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _security);
       if (rc == -1) return;
       index += rc;
     }
--- a/src/java.base/macosx/classes/sun/util/locale/provider/HostLocaleProviderAdapterImpl.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/macosx/classes/sun/util/locale/provider/HostLocaleProviderAdapterImpl.java	Wed Nov 13 09:16:04 2019 +0000
@@ -429,8 +429,9 @@
 
             @Override
             public NumberFormat getIntegerInstance(Locale locale) {
-                return new DecimalFormat(getNumberPattern(NF_INTEGER, locale),
+                DecimalFormat format = new DecimalFormat(getNumberPattern(NF_INTEGER, locale),
                     DecimalFormatSymbols.getInstance(locale));
+                return HostLocaleProviderAdapter.makeIntegerFormatter(format);
             }
 
             @Override
--- a/src/java.base/share/classes/com/sun/crypto/provider/JceKeyStore.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/share/classes/com/sun/crypto/provider/JceKeyStore.java	Wed Nov 13 09:16:04 2019 +0000
@@ -45,6 +45,8 @@
 import java.security.cert.CertificateException;
 import javax.crypto.SealedObject;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 /**
  * This class provides the keystore implementation referred to as "jceks".
  * This implementation strongly protects the keystore private keys using
@@ -909,7 +911,8 @@
      * hash with a bit of whitener.
      */
     private MessageDigest getPreKeyedHash(char[] password)
-    throws NoSuchAlgorithmException, UnsupportedEncodingException {
+        throws NoSuchAlgorithmException
+    {
         int i, j;
 
         MessageDigest md = MessageDigest.getInstance("SHA");
@@ -921,7 +924,7 @@
         md.update(passwdBytes);
         for (i=0; i<passwdBytes.length; i++)
             passwdBytes[i] = 0;
-        md.update("Mighty Aphrodite".getBytes("UTF8"));
+        md.update("Mighty Aphrodite".getBytes(UTF_8));
         return md;
     }
 
--- a/src/java.base/share/classes/com/sun/crypto/provider/PBEWithMD5AndDESCipher.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/share/classes/com/sun/crypto/provider/PBEWithMD5AndDESCipher.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,6 @@
 
 package com.sun.crypto.provider;
 
-import java.io.UnsupportedEncodingException;
 import java.security.*;
 import java.security.spec.*;
 import javax.crypto.*;
--- a/src/java.base/share/classes/com/sun/crypto/provider/PBEWithMD5AndTripleDESCipher.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/share/classes/com/sun/crypto/provider/PBEWithMD5AndTripleDESCipher.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,6 @@
 
 package com.sun.crypto.provider;
 
-import java.io.UnsupportedEncodingException;
 import java.security.*;
 import java.security.spec.*;
 import javax.crypto.*;
--- a/src/java.base/share/classes/com/sun/crypto/provider/PBKDF2KeyImpl.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/share/classes/com/sun/crypto/provider/PBKDF2KeyImpl.java	Wed Nov 13 09:16:04 2019 +0000
@@ -29,7 +29,6 @@
 import java.lang.ref.Reference;
 import java.nio.ByteBuffer;
 import java.nio.CharBuffer;
-import java.nio.charset.Charset;
 import java.util.Arrays;
 import java.util.Locale;
 import java.security.MessageDigest;
@@ -41,6 +40,8 @@
 import javax.crypto.SecretKey;
 import javax.crypto.spec.PBEKeySpec;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 import jdk.internal.ref.CleanerFactory;
 
 /**
@@ -66,9 +67,8 @@
     private Mac prf;
 
     private static byte[] getPasswordBytes(char[] passwd) {
-        Charset utf8 = Charset.forName("UTF-8");
         CharBuffer cb = CharBuffer.wrap(passwd);
-        ByteBuffer bb = utf8.encode(cb);
+        ByteBuffer bb = UTF_8.encode(cb);
 
         int len = bb.limit();
         byte[] passwdBytes = new byte[len];
--- a/src/java.base/share/classes/com/sun/crypto/provider/TlsPrfGenerator.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/share/classes/com/sun/crypto/provider/TlsPrfGenerator.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -30,6 +30,8 @@
 import java.security.*;
 import java.security.spec.AlgorithmParameterSpec;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 import javax.crypto.*;
 import javax.crypto.spec.SecretKeySpec;
 
@@ -153,7 +155,7 @@
         SecretKey key = spec.getSecret();
         byte[] secret = (key == null) ? null : key.getEncoded();
         try {
-            byte[] labelBytes = spec.getLabel().getBytes("UTF8");
+            byte[] labelBytes = spec.getLabel().getBytes(UTF_8);
             int n = spec.getOutputLength();
             byte[] prfBytes = (tls12 ?
                 doTLS12PRF(secret, labelBytes, spec.getSeed(), n,
@@ -163,8 +165,6 @@
             return new SecretKeySpec(prfBytes, "TlsPrf");
         } catch (GeneralSecurityException e) {
             throw new ProviderException("Could not generate PRF", e);
-        } catch (java.io.UnsupportedEncodingException e) {
-            throw new ProviderException("Could not generate PRF", e);
         }
     }
 
--- a/src/java.base/share/classes/java/util/Arrays.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/share/classes/java/util/Arrays.java	Wed Nov 13 09:16:04 2019 +0000
@@ -74,17 +74,658 @@
  */
 public class Arrays {
 
-    /**
-     * The minimum array length below which a parallel sorting
-     * algorithm will not further partition the sorting task. Using
-     * smaller sizes typically results in memory contention across
-     * tasks that makes parallel speedups unlikely.
-     */
-    private static final int MIN_ARRAY_SORT_GRAN = 1 << 13;
-
     // Suppresses default constructor, ensuring non-instantiability.
     private Arrays() {}
 
+    /*
+     * Sorting methods. Note that all public "sort" methods take the
+     * same form: performing argument checks if necessary, and then
+     * expanding arguments into those required for the internal
+     * implementation methods residing in other package-private
+     * classes (except for legacyMergeSort, included in this class).
+     */
+
+    /**
+     * Sorts the specified array into ascending numerical order.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort
+     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     */
+    public static void sort(int[] a) {
+        DualPivotQuicksort.sort(a, 0, 0, a.length);
+    }
+
+    /**
+     * Sorts the specified range of the array into ascending order. The range
+     * to be sorted extends from the index {@code fromIndex}, inclusive, to
+     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
+     * the range to be sorted is empty.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort
+     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     * @param fromIndex the index of the first element, inclusive, to be sorted
+     * @param toIndex the index of the last element, exclusive, to be sorted
+     *
+     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
+     * @throws ArrayIndexOutOfBoundsException
+     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
+     */
+    public static void sort(int[] a, int fromIndex, int toIndex) {
+        rangeCheck(a.length, fromIndex, toIndex);
+        DualPivotQuicksort.sort(a, 0, fromIndex, toIndex);
+    }
+
+    /**
+     * Sorts the specified array into ascending numerical order.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort
+     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     */
+    public static void sort(long[] a) {
+        DualPivotQuicksort.sort(a, 0, 0, a.length);
+    }
+
+    /**
+     * Sorts the specified range of the array into ascending order. The range
+     * to be sorted extends from the index {@code fromIndex}, inclusive, to
+     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
+     * the range to be sorted is empty.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort
+     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     * @param fromIndex the index of the first element, inclusive, to be sorted
+     * @param toIndex the index of the last element, exclusive, to be sorted
+     *
+     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
+     * @throws ArrayIndexOutOfBoundsException
+     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
+     */
+    public static void sort(long[] a, int fromIndex, int toIndex) {
+        rangeCheck(a.length, fromIndex, toIndex);
+        DualPivotQuicksort.sort(a, 0, fromIndex, toIndex);
+    }
+
+    /**
+     * Sorts the specified array into ascending numerical order.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort
+     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     */
+    public static void sort(short[] a) {
+        DualPivotQuicksort.sort(a, 0, a.length);
+    }
+
+    /**
+     * Sorts the specified range of the array into ascending order. The range
+     * to be sorted extends from the index {@code fromIndex}, inclusive, to
+     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
+     * the range to be sorted is empty.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort
+     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     * @param fromIndex the index of the first element, inclusive, to be sorted
+     * @param toIndex the index of the last element, exclusive, to be sorted
+     *
+     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
+     * @throws ArrayIndexOutOfBoundsException
+     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
+     */
+    public static void sort(short[] a, int fromIndex, int toIndex) {
+        rangeCheck(a.length, fromIndex, toIndex);
+        DualPivotQuicksort.sort(a, fromIndex, toIndex);
+    }
+
+    /**
+     * Sorts the specified array into ascending numerical order.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort
+     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     */
+    public static void sort(char[] a) {
+        DualPivotQuicksort.sort(a, 0, a.length);
+    }
+
+    /**
+     * Sorts the specified range of the array into ascending order. The range
+     * to be sorted extends from the index {@code fromIndex}, inclusive, to
+     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
+     * the range to be sorted is empty.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort
+     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     * @param fromIndex the index of the first element, inclusive, to be sorted
+     * @param toIndex the index of the last element, exclusive, to be sorted
+     *
+     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
+     * @throws ArrayIndexOutOfBoundsException
+     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
+     */
+    public static void sort(char[] a, int fromIndex, int toIndex) {
+        rangeCheck(a.length, fromIndex, toIndex);
+        DualPivotQuicksort.sort(a, fromIndex, toIndex);
+    }
+
+    /**
+     * Sorts the specified array into ascending numerical order.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort
+     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     */
+    public static void sort(byte[] a) {
+        DualPivotQuicksort.sort(a, 0, a.length);
+    }
+
+    /**
+     * Sorts the specified range of the array into ascending order. The range
+     * to be sorted extends from the index {@code fromIndex}, inclusive, to
+     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
+     * the range to be sorted is empty.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort
+     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     * @param fromIndex the index of the first element, inclusive, to be sorted
+     * @param toIndex the index of the last element, exclusive, to be sorted
+     *
+     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
+     * @throws ArrayIndexOutOfBoundsException
+     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
+     */
+    public static void sort(byte[] a, int fromIndex, int toIndex) {
+        rangeCheck(a.length, fromIndex, toIndex);
+        DualPivotQuicksort.sort(a, fromIndex, toIndex);
+    }
+
+    /**
+     * Sorts the specified array into ascending numerical order.
+     *
+     * <p>The {@code <} relation does not provide a total order on all float
+     * values: {@code -0.0f == 0.0f} is {@code true} and a {@code Float.NaN}
+     * value compares neither less than, greater than, nor equal to any value,
+     * even itself. This method uses the total order imposed by the method
+     * {@link Float#compareTo}: {@code -0.0f} is treated as less than value
+     * {@code 0.0f} and {@code Float.NaN} is considered greater than any
+     * other value and all {@code Float.NaN} values are considered equal.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort
+     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     */
+    public static void sort(float[] a) {
+        DualPivotQuicksort.sort(a, 0, 0, a.length);
+    }
+
+    /**
+     * Sorts the specified range of the array into ascending order. The range
+     * to be sorted extends from the index {@code fromIndex}, inclusive, to
+     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
+     * the range to be sorted is empty.
+     *
+     * <p>The {@code <} relation does not provide a total order on all float
+     * values: {@code -0.0f == 0.0f} is {@code true} and a {@code Float.NaN}
+     * value compares neither less than, greater than, nor equal to any value,
+     * even itself. This method uses the total order imposed by the method
+     * {@link Float#compareTo}: {@code -0.0f} is treated as less than value
+     * {@code 0.0f} and {@code Float.NaN} is considered greater than any
+     * other value and all {@code Float.NaN} values are considered equal.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort
+     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     * @param fromIndex the index of the first element, inclusive, to be sorted
+     * @param toIndex the index of the last element, exclusive, to be sorted
+     *
+     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
+     * @throws ArrayIndexOutOfBoundsException
+     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
+     */
+    public static void sort(float[] a, int fromIndex, int toIndex) {
+        rangeCheck(a.length, fromIndex, toIndex);
+        DualPivotQuicksort.sort(a, 0, fromIndex, toIndex);
+    }
+
+    /**
+     * Sorts the specified array into ascending numerical order.
+     *
+     * <p>The {@code <} relation does not provide a total order on all double
+     * values: {@code -0.0d == 0.0d} is {@code true} and a {@code Double.NaN}
+     * value compares neither less than, greater than, nor equal to any value,
+     * even itself. This method uses the total order imposed by the method
+     * {@link Double#compareTo}: {@code -0.0d} is treated as less than value
+     * {@code 0.0d} and {@code Double.NaN} is considered greater than any
+     * other value and all {@code Double.NaN} values are considered equal.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort
+     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     */
+    public static void sort(double[] a) {
+        DualPivotQuicksort.sort(a, 0, 0, a.length);
+    }
+
+    /**
+     * Sorts the specified range of the array into ascending order. The range
+     * to be sorted extends from the index {@code fromIndex}, inclusive, to
+     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
+     * the range to be sorted is empty.
+     *
+     * <p>The {@code <} relation does not provide a total order on all double
+     * values: {@code -0.0d == 0.0d} is {@code true} and a {@code Double.NaN}
+     * value compares neither less than, greater than, nor equal to any value,
+     * even itself. This method uses the total order imposed by the method
+     * {@link Double#compareTo}: {@code -0.0d} is treated as less than value
+     * {@code 0.0d} and {@code Double.NaN} is considered greater than any
+     * other value and all {@code Double.NaN} values are considered equal.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort
+     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     * @param fromIndex the index of the first element, inclusive, to be sorted
+     * @param toIndex the index of the last element, exclusive, to be sorted
+     *
+     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
+     * @throws ArrayIndexOutOfBoundsException
+     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
+     */
+    public static void sort(double[] a, int fromIndex, int toIndex) {
+        rangeCheck(a.length, fromIndex, toIndex);
+        DualPivotQuicksort.sort(a, 0, fromIndex, toIndex);
+    }
+
+    /**
+     * Sorts the specified array into ascending numerical order.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+     * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     *
+     * @since 1.8
+     */
+    public static void parallelSort(byte[] a) {
+        DualPivotQuicksort.sort(a, 0, a.length);
+    }
+
+    /**
+     * Sorts the specified range of the array into ascending numerical order.
+     * The range to be sorted extends from the index {@code fromIndex},
+     * inclusive, to the index {@code toIndex}, exclusive. If
+     * {@code fromIndex == toIndex}, the range to be sorted is empty.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+     * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     * @param fromIndex the index of the first element, inclusive, to be sorted
+     * @param toIndex the index of the last element, exclusive, to be sorted
+     *
+     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
+     * @throws ArrayIndexOutOfBoundsException
+     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
+     *
+     * @since 1.8
+     */
+    public static void parallelSort(byte[] a, int fromIndex, int toIndex) {
+        rangeCheck(a.length, fromIndex, toIndex);
+        DualPivotQuicksort.sort(a, fromIndex, toIndex);
+    }
+
+    /**
+     * Sorts the specified array into ascending numerical order.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+     * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     *
+     * @since 1.8
+     */
+    public static void parallelSort(char[] a) {
+        DualPivotQuicksort.sort(a, 0, a.length);
+    }
+
+    /**
+     * Sorts the specified range of the array into ascending numerical order.
+     * The range to be sorted extends from the index {@code fromIndex},
+     * inclusive, to the index {@code toIndex}, exclusive. If
+     * {@code fromIndex == toIndex}, the range to be sorted is empty.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+     * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     * @param fromIndex the index of the first element, inclusive, to be sorted
+     * @param toIndex the index of the last element, exclusive, to be sorted
+     *
+     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
+     * @throws ArrayIndexOutOfBoundsException
+     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
+     *
+     * @since 1.8
+     */
+    public static void parallelSort(char[] a, int fromIndex, int toIndex) {
+        rangeCheck(a.length, fromIndex, toIndex);
+        DualPivotQuicksort.sort(a, fromIndex, toIndex);
+    }
+
+    /**
+     * Sorts the specified array into ascending numerical order.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+     * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     *
+     * @since 1.8
+     */
+    public static void parallelSort(short[] a) {
+        DualPivotQuicksort.sort(a, 0, a.length);
+    }
+
+    /**
+     * Sorts the specified range of the array into ascending numerical order.
+     * The range to be sorted extends from the index {@code fromIndex},
+     * inclusive, to the index {@code toIndex}, exclusive. If
+     * {@code fromIndex == toIndex}, the range to be sorted is empty.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+     * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     * @param fromIndex the index of the first element, inclusive, to be sorted
+     * @param toIndex the index of the last element, exclusive, to be sorted
+     *
+     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
+     * @throws ArrayIndexOutOfBoundsException
+     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
+     *
+     * @since 1.8
+     */
+    public static void parallelSort(short[] a, int fromIndex, int toIndex) {
+        rangeCheck(a.length, fromIndex, toIndex);
+        DualPivotQuicksort.sort(a, fromIndex, toIndex);
+    }
+
+    /**
+     * Sorts the specified array into ascending numerical order.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+     * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     *
+     * @since 1.8
+     */
+    public static void parallelSort(int[] a) {
+        DualPivotQuicksort.sort(a, ForkJoinPool.getCommonPoolParallelism(), 0, a.length);
+    }
+
+    /**
+     * Sorts the specified range of the array into ascending numerical order.
+     * The range to be sorted extends from the index {@code fromIndex},
+     * inclusive, to the index {@code toIndex}, exclusive. If
+     * {@code fromIndex == toIndex}, the range to be sorted is empty.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+     * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     * @param fromIndex the index of the first element, inclusive, to be sorted
+     * @param toIndex the index of the last element, exclusive, to be sorted
+     *
+     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
+     * @throws ArrayIndexOutOfBoundsException
+     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
+     *
+     * @since 1.8
+     */
+    public static void parallelSort(int[] a, int fromIndex, int toIndex) {
+        rangeCheck(a.length, fromIndex, toIndex);
+        DualPivotQuicksort.sort(a, ForkJoinPool.getCommonPoolParallelism(), fromIndex, toIndex);
+    }
+
+    /**
+     * Sorts the specified array into ascending numerical order.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+     * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     *
+     * @since 1.8
+     */
+    public static void parallelSort(long[] a) {
+        DualPivotQuicksort.sort(a, ForkJoinPool.getCommonPoolParallelism(), 0, a.length);
+    }
+
+    /**
+     * Sorts the specified range of the array into ascending numerical order.
+     * The range to be sorted extends from the index {@code fromIndex},
+     * inclusive, to the index {@code toIndex}, exclusive. If
+     * {@code fromIndex == toIndex}, the range to be sorted is empty.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+     * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     * @param fromIndex the index of the first element, inclusive, to be sorted
+     * @param toIndex the index of the last element, exclusive, to be sorted
+     *
+     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
+     * @throws ArrayIndexOutOfBoundsException
+     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
+     *
+     * @since 1.8
+     */
+    public static void parallelSort(long[] a, int fromIndex, int toIndex) {
+        rangeCheck(a.length, fromIndex, toIndex);
+        DualPivotQuicksort.sort(a, ForkJoinPool.getCommonPoolParallelism(), fromIndex, toIndex);
+    }
+
+    /**
+     * Sorts the specified array into ascending numerical order.
+     *
+     * <p>The {@code <} relation does not provide a total order on all float
+     * values: {@code -0.0f == 0.0f} is {@code true} and a {@code Float.NaN}
+     * value compares neither less than, greater than, nor equal to any value,
+     * even itself. This method uses the total order imposed by the method
+     * {@link Float#compareTo}: {@code -0.0f} is treated as less than value
+     * {@code 0.0f} and {@code Float.NaN} is considered greater than any
+     * other value and all {@code Float.NaN} values are considered equal.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+     * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     *
+     * @since 1.8
+     */
+    public static void parallelSort(float[] a) {
+        DualPivotQuicksort.sort(a, ForkJoinPool.getCommonPoolParallelism(), 0, a.length);
+    }
+
+    /**
+     * Sorts the specified range of the array into ascending numerical order.
+     * The range to be sorted extends from the index {@code fromIndex},
+     * inclusive, to the index {@code toIndex}, exclusive. If
+     * {@code fromIndex == toIndex}, the range to be sorted is empty.
+     *
+     * <p>The {@code <} relation does not provide a total order on all float
+     * values: {@code -0.0f == 0.0f} is {@code true} and a {@code Float.NaN}
+     * value compares neither less than, greater than, nor equal to any value,
+     * even itself. This method uses the total order imposed by the method
+     * {@link Float#compareTo}: {@code -0.0f} is treated as less than value
+     * {@code 0.0f} and {@code Float.NaN} is considered greater than any
+     * other value and all {@code Float.NaN} values are considered equal.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+     * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     * @param fromIndex the index of the first element, inclusive, to be sorted
+     * @param toIndex the index of the last element, exclusive, to be sorted
+     *
+     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
+     * @throws ArrayIndexOutOfBoundsException
+     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
+     *
+     * @since 1.8
+     */
+    public static void parallelSort(float[] a, int fromIndex, int toIndex) {
+        rangeCheck(a.length, fromIndex, toIndex);
+        DualPivotQuicksort.sort(a, ForkJoinPool.getCommonPoolParallelism(), fromIndex, toIndex);
+    }
+
+    /**
+     * Sorts the specified array into ascending numerical order.
+     *
+     * <p>The {@code <} relation does not provide a total order on all double
+     * values: {@code -0.0d == 0.0d} is {@code true} and a {@code Double.NaN}
+     * value compares neither less than, greater than, nor equal to any value,
+     * even itself. This method uses the total order imposed by the method
+     * {@link Double#compareTo}: {@code -0.0d} is treated as less than value
+     * {@code 0.0d} and {@code Double.NaN} is considered greater than any
+     * other value and all {@code Double.NaN} values are considered equal.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+     * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     *
+     * @since 1.8
+     */
+    public static void parallelSort(double[] a) {
+        DualPivotQuicksort.sort(a, ForkJoinPool.getCommonPoolParallelism(), 0, a.length);
+    }
+
+    /**
+     * Sorts the specified range of the array into ascending numerical order.
+     * The range to be sorted extends from the index {@code fromIndex},
+     * inclusive, to the index {@code toIndex}, exclusive. If
+     * {@code fromIndex == toIndex}, the range to be sorted is empty.
+     *
+     * <p>The {@code <} relation does not provide a total order on all double
+     * values: {@code -0.0d == 0.0d} is {@code true} and a {@code Double.NaN}
+     * value compares neither less than, greater than, nor equal to any value,
+     * even itself. This method uses the total order imposed by the method
+     * {@link Double#compareTo}: {@code -0.0d} is treated as less than value
+     * {@code 0.0d} and {@code Double.NaN} is considered greater than any
+     * other value and all {@code Double.NaN} values are considered equal.
+     *
+     * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+     * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+     * offers O(n log(n)) performance on all data sets, and is typically
+     * faster than traditional (one-pivot) Quicksort implementations.
+     *
+     * @param a the array to be sorted
+     * @param fromIndex the index of the first element, inclusive, to be sorted
+     * @param toIndex the index of the last element, exclusive, to be sorted
+     *
+     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
+     * @throws ArrayIndexOutOfBoundsException
+     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
+     *
+     * @since 1.8
+     */
+    public static void parallelSort(double[] a, int fromIndex, int toIndex) {
+        rangeCheck(a.length, fromIndex, toIndex);
+        DualPivotQuicksort.sort(a, ForkJoinPool.getCommonPoolParallelism(), fromIndex, toIndex);
+    }
+
+    /**
+     * Checks that {@code fromIndex} and {@code toIndex} are in
+     * the range and throws an exception if they aren't.
+     */
+    static void rangeCheck(int arrayLength, int fromIndex, int toIndex) {
+        if (fromIndex > toIndex) {
+            throw new IllegalArgumentException(
+                "fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")");
+        }
+        if (fromIndex < 0) {
+            throw new ArrayIndexOutOfBoundsException(fromIndex);
+        }
+        if (toIndex > arrayLength) {
+            throw new ArrayIndexOutOfBoundsException(toIndex);
+        }
+    }
+
     /**
      * A comparator that implements the natural ordering of a group of
      * mutually comparable elements. May be used when a supplied
@@ -109,863 +750,12 @@
     }
 
     /**
-     * Checks that {@code fromIndex} and {@code toIndex} are in
-     * the range and throws an exception if they aren't.
-     */
-    static void rangeCheck(int arrayLength, int fromIndex, int toIndex) {
-        if (fromIndex > toIndex) {
-            throw new IllegalArgumentException(
-                    "fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")");
-        }
-        if (fromIndex < 0) {
-            throw new ArrayIndexOutOfBoundsException(fromIndex);
-        }
-        if (toIndex > arrayLength) {
-            throw new ArrayIndexOutOfBoundsException(toIndex);
-        }
-    }
-
-    /*
-     * Sorting methods. Note that all public "sort" methods take the
-     * same form: Performing argument checks if necessary, and then
-     * expanding arguments into those required for the internal
-     * implementation methods residing in other package-private
-     * classes (except for legacyMergeSort, included in this class).
-     */
-
-    /**
-     * Sorts the specified array into ascending numerical order.
-     *
-     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
-     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
-     * offers O(n log(n)) performance on many data sets that cause other
-     * quicksorts to degrade to quadratic performance, and is typically
-     * faster than traditional (one-pivot) Quicksort implementations.
-     *
-     * @param a the array to be sorted
-     */
-    public static void sort(int[] a) {
-        DualPivotQuicksort.sort(a, 0, a.length - 1, null, 0, 0);
-    }
-
-    /**
-     * Sorts the specified range of the array into ascending order. The range
-     * to be sorted extends from the index {@code fromIndex}, inclusive, to
-     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
-     * the range to be sorted is empty.
-     *
-     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
-     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
-     * offers O(n log(n)) performance on many data sets that cause other
-     * quicksorts to degrade to quadratic performance, and is typically
-     * faster than traditional (one-pivot) Quicksort implementations.
-     *
-     * @param a the array to be sorted
-     * @param fromIndex the index of the first element, inclusive, to be sorted
-     * @param toIndex the index of the last element, exclusive, to be sorted
-     *
-     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
-     * @throws ArrayIndexOutOfBoundsException
-     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
-     */
-    public static void sort(int[] a, int fromIndex, int toIndex) {
-        rangeCheck(a.length, fromIndex, toIndex);
-        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1, null, 0, 0);
-    }
-
-    /**
-     * Sorts the specified array into ascending numerical order.
-     *
-     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
-     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
-     * offers O(n log(n)) performance on many data sets that cause other
-     * quicksorts to degrade to quadratic performance, and is typically
-     * faster than traditional (one-pivot) Quicksort implementations.
-     *
-     * @param a the array to be sorted
-     */
-    public static void sort(long[] a) {
-        DualPivotQuicksort.sort(a, 0, a.length - 1, null, 0, 0);
-    }
-
-    /**
-     * Sorts the specified range of the array into ascending order. The range
-     * to be sorted extends from the index {@code fromIndex}, inclusive, to
-     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
-     * the range to be sorted is empty.
-     *
-     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
-     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
-     * offers O(n log(n)) performance on many data sets that cause other
-     * quicksorts to degrade to quadratic performance, and is typically
-     * faster than traditional (one-pivot) Quicksort implementations.
-     *
-     * @param a the array to be sorted
-     * @param fromIndex the index of the first element, inclusive, to be sorted
-     * @param toIndex the index of the last element, exclusive, to be sorted
-     *
-     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
-     * @throws ArrayIndexOutOfBoundsException
-     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
-     */
-    public static void sort(long[] a, int fromIndex, int toIndex) {
-        rangeCheck(a.length, fromIndex, toIndex);
-        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1, null, 0, 0);
-    }
-
-    /**
-     * Sorts the specified array into ascending numerical order.
-     *
-     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
-     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
-     * offers O(n log(n)) performance on many data sets that cause other
-     * quicksorts to degrade to quadratic performance, and is typically
-     * faster than traditional (one-pivot) Quicksort implementations.
-     *
-     * @param a the array to be sorted
-     */
-    public static void sort(short[] a) {
-        DualPivotQuicksort.sort(a, 0, a.length - 1, null, 0, 0);
-    }
-
-    /**
-     * Sorts the specified range of the array into ascending order. The range
-     * to be sorted extends from the index {@code fromIndex}, inclusive, to
-     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
-     * the range to be sorted is empty.
-     *
-     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
-     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
-     * offers O(n log(n)) performance on many data sets that cause other
-     * quicksorts to degrade to quadratic performance, and is typically
-     * faster than traditional (one-pivot) Quicksort implementations.
-     *
-     * @param a the array to be sorted
-     * @param fromIndex the index of the first element, inclusive, to be sorted
-     * @param toIndex the index of the last element, exclusive, to be sorted
-     *
-     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
-     * @throws ArrayIndexOutOfBoundsException
-     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
-     */
-    public static void sort(short[] a, int fromIndex, int toIndex) {
-        rangeCheck(a.length, fromIndex, toIndex);
-        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1, null, 0, 0);
-    }
-
-    /**
-     * Sorts the specified array into ascending numerical order.
-     *
-     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
-     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
-     * offers O(n log(n)) performance on many data sets that cause other
-     * quicksorts to degrade to quadratic performance, and is typically
-     * faster than traditional (one-pivot) Quicksort implementations.
-     *
-     * @param a the array to be sorted
-     */
-    public static void sort(char[] a) {
-        DualPivotQuicksort.sort(a, 0, a.length - 1, null, 0, 0);
-    }
-
-    /**
-     * Sorts the specified range of the array into ascending order. The range
-     * to be sorted extends from the index {@code fromIndex}, inclusive, to
-     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
-     * the range to be sorted is empty.
-     *
-     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
-     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
-     * offers O(n log(n)) performance on many data sets that cause other
-     * quicksorts to degrade to quadratic performance, and is typically
-     * faster than traditional (one-pivot) Quicksort implementations.
-     *
-     * @param a the array to be sorted
-     * @param fromIndex the index of the first element, inclusive, to be sorted
-     * @param toIndex the index of the last element, exclusive, to be sorted
-     *
-     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
-     * @throws ArrayIndexOutOfBoundsException
-     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
-     */
-    public static void sort(char[] a, int fromIndex, int toIndex) {
-        rangeCheck(a.length, fromIndex, toIndex);
-        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1, null, 0, 0);
-    }
-
-    /**
-     * Sorts the specified array into ascending numerical order.
-     *
-     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
-     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
-     * offers O(n log(n)) performance on many data sets that cause other
-     * quicksorts to degrade to quadratic performance, and is typically
-     * faster than traditional (one-pivot) Quicksort implementations.
-     *
-     * @param a the array to be sorted
-     */
-    public static void sort(byte[] a) {
-        DualPivotQuicksort.sort(a, 0, a.length - 1);
-    }
-
-    /**
-     * Sorts the specified range of the array into ascending order. The range
-     * to be sorted extends from the index {@code fromIndex}, inclusive, to
-     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
-     * the range to be sorted is empty.
-     *
-     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
-     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
-     * offers O(n log(n)) performance on many data sets that cause other
-     * quicksorts to degrade to quadratic performance, and is typically
-     * faster than traditional (one-pivot) Quicksort implementations.
-     *
-     * @param a the array to be sorted
-     * @param fromIndex the index of the first element, inclusive, to be sorted
-     * @param toIndex the index of the last element, exclusive, to be sorted
-     *
-     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
-     * @throws ArrayIndexOutOfBoundsException
-     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
-     */
-    public static void sort(byte[] a, int fromIndex, int toIndex) {
-        rangeCheck(a.length, fromIndex, toIndex);
-        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1);
-    }
-
-    /**
-     * Sorts the specified array into ascending numerical order.
-     *
-     * <p>The {@code <} relation does not provide a total order on all float
-     * values: {@code -0.0f == 0.0f} is {@code true} and a {@code Float.NaN}
-     * value compares neither less than, greater than, nor equal to any value,
-     * even itself. This method uses the total order imposed by the method
-     * {@link Float#compareTo}: {@code -0.0f} is treated as less than value
-     * {@code 0.0f} and {@code Float.NaN} is considered greater than any
-     * other value and all {@code Float.NaN} values are considered equal.
-     *
-     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
-     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
-     * offers O(n log(n)) performance on many data sets that cause other
-     * quicksorts to degrade to quadratic performance, and is typically
-     * faster than traditional (one-pivot) Quicksort implementations.
-     *
-     * @param a the array to be sorted
-     */
-    public static void sort(float[] a) {
-        DualPivotQuicksort.sort(a, 0, a.length - 1, null, 0, 0);
-    }
-
-    /**
-     * Sorts the specified range of the array into ascending order. The range
-     * to be sorted extends from the index {@code fromIndex}, inclusive, to
-     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
-     * the range to be sorted is empty.
-     *
-     * <p>The {@code <} relation does not provide a total order on all float
-     * values: {@code -0.0f == 0.0f} is {@code true} and a {@code Float.NaN}
-     * value compares neither less than, greater than, nor equal to any value,
-     * even itself. This method uses the total order imposed by the method
-     * {@link Float#compareTo}: {@code -0.0f} is treated as less than value
-     * {@code 0.0f} and {@code Float.NaN} is considered greater than any
-     * other value and all {@code Float.NaN} values are considered equal.
-     *
-     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
-     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
-     * offers O(n log(n)) performance on many data sets that cause other
-     * quicksorts to degrade to quadratic performance, and is typically
-     * faster than traditional (one-pivot) Quicksort implementations.
-     *
-     * @param a the array to be sorted
-     * @param fromIndex the index of the first element, inclusive, to be sorted
-     * @param toIndex the index of the last element, exclusive, to be sorted
-     *
-     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
-     * @throws ArrayIndexOutOfBoundsException
-     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
-     */
-    public static void sort(float[] a, int fromIndex, int toIndex) {
-        rangeCheck(a.length, fromIndex, toIndex);
-        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1, null, 0, 0);
-    }
-
-    /**
-     * Sorts the specified array into ascending numerical order.
-     *
-     * <p>The {@code <} relation does not provide a total order on all double
-     * values: {@code -0.0d == 0.0d} is {@code true} and a {@code Double.NaN}
-     * value compares neither less than, greater than, nor equal to any value,
-     * even itself. This method uses the total order imposed by the method
-     * {@link Double#compareTo}: {@code -0.0d} is treated as less than value
-     * {@code 0.0d} and {@code Double.NaN} is considered greater than any
-     * other value and all {@code Double.NaN} values are considered equal.
-     *
-     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
-     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
-     * offers O(n log(n)) performance on many data sets that cause other
-     * quicksorts to degrade to quadratic performance, and is typically
-     * faster than traditional (one-pivot) Quicksort implementations.
-     *
-     * @param a the array to be sorted
-     */
-    public static void sort(double[] a) {
-        DualPivotQuicksort.sort(a, 0, a.length - 1, null, 0, 0);
-    }
-
-    /**
-     * Sorts the specified range of the array into ascending order. The range
-     * to be sorted extends from the index {@code fromIndex}, inclusive, to
-     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
-     * the range to be sorted is empty.
-     *
-     * <p>The {@code <} relation does not provide a total order on all double
-     * values: {@code -0.0d == 0.0d} is {@code true} and a {@code Double.NaN}
-     * value compares neither less than, greater than, nor equal to any value,
-     * even itself. This method uses the total order imposed by the method
-     * {@link Double#compareTo}: {@code -0.0d} is treated as less than value
-     * {@code 0.0d} and {@code Double.NaN} is considered greater than any
-     * other value and all {@code Double.NaN} values are considered equal.
-     *
-     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
-     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
-     * offers O(n log(n)) performance on many data sets that cause other
-     * quicksorts to degrade to quadratic performance, and is typically
-     * faster than traditional (one-pivot) Quicksort implementations.
-     *
-     * @param a the array to be sorted
-     * @param fromIndex the index of the first element, inclusive, to be sorted
-     * @param toIndex the index of the last element, exclusive, to be sorted
-     *
-     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
-     * @throws ArrayIndexOutOfBoundsException
-     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
-     */
-    public static void sort(double[] a, int fromIndex, int toIndex) {
-        rangeCheck(a.length, fromIndex, toIndex);
-        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1, null, 0, 0);
-    }
-
-    /**
-     * Sorts the specified array into ascending numerical order.
-     *
-     * @implNote The sorting algorithm is a parallel sort-merge that breaks the
-     * array into sub-arrays that are themselves sorted and then merged. When
-     * the sub-array length reaches a minimum granularity, the sub-array is
-     * sorted using the appropriate {@link Arrays#sort(byte[]) Arrays.sort}
-     * method. If the length of the specified array is less than the minimum
-     * granularity, then it is sorted using the appropriate {@link
-     * Arrays#sort(byte[]) Arrays.sort} method. The algorithm requires a
-     * working space no greater than the size of the original array. The
-     * {@link ForkJoinPool#commonPool() ForkJoin common pool} is used to
-     * execute any parallel tasks.
-     *
-     * @param a the array to be sorted
-     *
-     * @since 1.8
-     */
-    public static void parallelSort(byte[] a) {
-        int n = a.length, p, g;
-        if (n <= MIN_ARRAY_SORT_GRAN ||
-            (p = ForkJoinPool.getCommonPoolParallelism()) == 1)
-            DualPivotQuicksort.sort(a, 0, n - 1);
-        else
-            new ArraysParallelSortHelpers.FJByte.Sorter
-                (null, a, new byte[n], 0, n, 0,
-                 ((g = n / (p << 2)) <= MIN_ARRAY_SORT_GRAN) ?
-                 MIN_ARRAY_SORT_GRAN : g).invoke();
-    }
-
-    /**
-     * Sorts the specified range of the array into ascending numerical order.
-     * The range to be sorted extends from the index {@code fromIndex},
-     * inclusive, to the index {@code toIndex}, exclusive. If
-     * {@code fromIndex == toIndex}, the range to be sorted is empty.
-     *
-     * @implNote The sorting algorithm is a parallel sort-merge that breaks the
-     * array into sub-arrays that are themselves sorted and then merged. When
-     * the sub-array length reaches a minimum granularity, the sub-array is
-     * sorted using the appropriate {@link Arrays#sort(byte[]) Arrays.sort}
-     * method. If the length of the specified array is less than the minimum
-     * granularity, then it is sorted using the appropriate {@link
-     * Arrays#sort(byte[]) Arrays.sort} method. The algorithm requires a working
-     * space no greater than the size of the specified range of the original
-     * array. The {@link ForkJoinPool#commonPool() ForkJoin common pool} is
-     * used to execute any parallel tasks.
-     *
-     * @param a the array to be sorted
-     * @param fromIndex the index of the first element, inclusive, to be sorted
-     * @param toIndex the index of the last element, exclusive, to be sorted
-     *
-     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
-     * @throws ArrayIndexOutOfBoundsException
-     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
-     *
-     * @since 1.8
-     */
-    public static void parallelSort(byte[] a, int fromIndex, int toIndex) {
-        rangeCheck(a.length, fromIndex, toIndex);
-        int n = toIndex - fromIndex, p, g;
-        if (n <= MIN_ARRAY_SORT_GRAN ||
-            (p = ForkJoinPool.getCommonPoolParallelism()) == 1)
-            DualPivotQuicksort.sort(a, fromIndex, toIndex - 1);
-        else
-            new ArraysParallelSortHelpers.FJByte.Sorter
-                (null, a, new byte[n], fromIndex, n, 0,
-                 ((g = n / (p << 2)) <= MIN_ARRAY_SORT_GRAN) ?
-                 MIN_ARRAY_SORT_GRAN : g).invoke();
-    }
-
-    /**
-     * Sorts the specified array into ascending numerical order.
-     *
-     * @implNote The sorting algorithm is a parallel sort-merge that breaks the
-     * array into sub-arrays that are themselves sorted and then merged. When
-     * the sub-array length reaches a minimum granularity, the sub-array is
-     * sorted using the appropriate {@link Arrays#sort(char[]) Arrays.sort}
-     * method. If the length of the specified array is less than the minimum
-     * granularity, then it is sorted using the appropriate {@link
-     * Arrays#sort(char[]) Arrays.sort} method. The algorithm requires a
-     * working space no greater than the size of the original array. The
-     * {@link ForkJoinPool#commonPool() ForkJoin common pool} is used to
-     * execute any parallel tasks.
-     *
-     * @param a the array to be sorted
-     *
-     * @since 1.8
-     */
-    public static void parallelSort(char[] a) {
-        int n = a.length, p, g;
-        if (n <= MIN_ARRAY_SORT_GRAN ||
-            (p = ForkJoinPool.getCommonPoolParallelism()) == 1)
-            DualPivotQuicksort.sort(a, 0, n - 1, null, 0, 0);
-        else
-            new ArraysParallelSortHelpers.FJChar.Sorter
-                (null, a, new char[n], 0, n, 0,
-                 ((g = n / (p << 2)) <= MIN_ARRAY_SORT_GRAN) ?
-                 MIN_ARRAY_SORT_GRAN : g).invoke();
-    }
-
-    /**
-     * Sorts the specified range of the array into ascending numerical order.
-     * The range to be sorted extends from the index {@code fromIndex},
-     * inclusive, to the index {@code toIndex}, exclusive. If
-     * {@code fromIndex == toIndex}, the range to be sorted is empty.
-     *
-      @implNote The sorting algorithm is a parallel sort-merge that breaks the
-     * array into sub-arrays that are themselves sorted and then merged. When
-     * the sub-array length reaches a minimum granularity, the sub-array is
-     * sorted using the appropriate {@link Arrays#sort(char[]) Arrays.sort}
-     * method. If the length of the specified array is less than the minimum
-     * granularity, then it is sorted using the appropriate {@link
-     * Arrays#sort(char[]) Arrays.sort} method. The algorithm requires a working
-     * space no greater than the size of the specified range of the original
-     * array. The {@link ForkJoinPool#commonPool() ForkJoin common pool} is
-     * used to execute any parallel tasks.
-     *
-     * @param a the array to be sorted
-     * @param fromIndex the index of the first element, inclusive, to be sorted
-     * @param toIndex the index of the last element, exclusive, to be sorted
-     *
-     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
-     * @throws ArrayIndexOutOfBoundsException
-     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
-     *
-     * @since 1.8
-     */
-    public static void parallelSort(char[] a, int fromIndex, int toIndex) {
-        rangeCheck(a.length, fromIndex, toIndex);
-        int n = toIndex - fromIndex, p, g;
-        if (n <= MIN_ARRAY_SORT_GRAN ||
-            (p = ForkJoinPool.getCommonPoolParallelism()) == 1)
-            DualPivotQuicksort.sort(a, fromIndex, toIndex - 1, null, 0, 0);
-        else
-            new ArraysParallelSortHelpers.FJChar.Sorter
-                (null, a, new char[n], fromIndex, n, 0,
-                 ((g = n / (p << 2)) <= MIN_ARRAY_SORT_GRAN) ?
-                 MIN_ARRAY_SORT_GRAN : g).invoke();
-    }
-
-    /**
-     * Sorts the specified array into ascending numerical order.
-     *
-     * @implNote The sorting algorithm is a parallel sort-merge that breaks the
-     * array into sub-arrays that are themselves sorted and then merged. When
-     * the sub-array length reaches a minimum granularity, the sub-array is
-     * sorted using the appropriate {@link Arrays#sort(short[]) Arrays.sort}
-     * method. If the length of the specified array is less than the minimum
-     * granularity, then it is sorted using the appropriate {@link
-     * Arrays#sort(short[]) Arrays.sort} method. The algorithm requires a
-     * working space no greater than the size of the original array. The
-     * {@link ForkJoinPool#commonPool() ForkJoin common pool} is used to
-     * execute any parallel tasks.
-     *
-     * @param a the array to be sorted
-     *
-     * @since 1.8
-     */
-    public static void parallelSort(short[] a) {
-        int n = a.length, p, g;
-        if (n <= MIN_ARRAY_SORT_GRAN ||
-            (p = ForkJoinPool.getCommonPoolParallelism()) == 1)
-            DualPivotQuicksort.sort(a, 0, n - 1, null, 0, 0);
-        else
-            new ArraysParallelSortHelpers.FJShort.Sorter
-                (null, a, new short[n], 0, n, 0,
-                 ((g = n / (p << 2)) <= MIN_ARRAY_SORT_GRAN) ?
-                 MIN_ARRAY_SORT_GRAN : g).invoke();
-    }
-
-    /**
-     * Sorts the specified range of the array into ascending numerical order.
-     * The range to be sorted extends from the index {@code fromIndex},
-     * inclusive, to the index {@code toIndex}, exclusive. If
-     * {@code fromIndex == toIndex}, the range to be sorted is empty.
-     *
-     * @implNote The sorting algorithm is a parallel sort-merge that breaks the
-     * array into sub-arrays that are themselves sorted and then merged. When
-     * the sub-array length reaches a minimum granularity, the sub-array is
-     * sorted using the appropriate {@link Arrays#sort(short[]) Arrays.sort}
-     * method. If the length of the specified array is less than the minimum
-     * granularity, then it is sorted using the appropriate {@link
-     * Arrays#sort(short[]) Arrays.sort} method. The algorithm requires a working
-     * space no greater than the size of the specified range of the original
-     * array. The {@link ForkJoinPool#commonPool() ForkJoin common pool} is
-     * used to execute any parallel tasks.
-     *
-     * @param a the array to be sorted
-     * @param fromIndex the index of the first element, inclusive, to be sorted
-     * @param toIndex the index of the last element, exclusive, to be sorted
-     *
-     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
-     * @throws ArrayIndexOutOfBoundsException
-     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
-     *
-     * @since 1.8
-     */
-    public static void parallelSort(short[] a, int fromIndex, int toIndex) {
-        rangeCheck(a.length, fromIndex, toIndex);
-        int n = toIndex - fromIndex, p, g;
-        if (n <= MIN_ARRAY_SORT_GRAN ||
-            (p = ForkJoinPool.getCommonPoolParallelism()) == 1)
-            DualPivotQuicksort.sort(a, fromIndex, toIndex - 1, null, 0, 0);
-        else
-            new ArraysParallelSortHelpers.FJShort.Sorter
-                (null, a, new short[n], fromIndex, n, 0,
-                 ((g = n / (p << 2)) <= MIN_ARRAY_SORT_GRAN) ?
-                 MIN_ARRAY_SORT_GRAN : g).invoke();
-    }
-
-    /**
-     * Sorts the specified array into ascending numerical order.
-     *
-     * @implNote The sorting algorithm is a parallel sort-merge that breaks the
-     * array into sub-arrays that are themselves sorted and then merged. When
-     * the sub-array length reaches a minimum granularity, the sub-array is
-     * sorted using the appropriate {@link Arrays#sort(int[]) Arrays.sort}
-     * method. If the length of the specified array is less than the minimum
-     * granularity, then it is sorted using the appropriate {@link
-     * Arrays#sort(int[]) Arrays.sort} method. The algorithm requires a
-     * working space no greater than the size of the original array. The
-     * {@link ForkJoinPool#commonPool() ForkJoin common pool} is used to
-     * execute any parallel tasks.
-     *
-     * @param a the array to be sorted
-     *
-     * @since 1.8
-     */
-    public static void parallelSort(int[] a) {
-        int n = a.length, p, g;
-        if (n <= MIN_ARRAY_SORT_GRAN ||
-            (p = ForkJoinPool.getCommonPoolParallelism()) == 1)
-            DualPivotQuicksort.sort(a, 0, n - 1, null, 0, 0);
-        else
-            new ArraysParallelSortHelpers.FJInt.Sorter
-                (null, a, new int[n], 0, n, 0,
-                 ((g = n / (p << 2)) <= MIN_ARRAY_SORT_GRAN) ?
-                 MIN_ARRAY_SORT_GRAN : g).invoke();
-    }
-
-    /**
-     * Sorts the specified range of the array into ascending numerical order.
-     * The range to be sorted extends from the index {@code fromIndex},
-     * inclusive, to the index {@code toIndex}, exclusive. If
-     * {@code fromIndex == toIndex}, the range to be sorted is empty.
-     *
-     * @implNote The sorting algorithm is a parallel sort-merge that breaks the
-     * array into sub-arrays that are themselves sorted and then merged. When
-     * the sub-array length reaches a minimum granularity, the sub-array is
-     * sorted using the appropriate {@link Arrays#sort(int[]) Arrays.sort}
-     * method. If the length of the specified array is less than the minimum
-     * granularity, then it is sorted using the appropriate {@link
-     * Arrays#sort(int[]) Arrays.sort} method. The algorithm requires a working
-     * space no greater than the size of the specified range of the original
-     * array. The {@link ForkJoinPool#commonPool() ForkJoin common pool} is
-     * used to execute any parallel tasks.
-     *
-     * @param a the array to be sorted
-     * @param fromIndex the index of the first element, inclusive, to be sorted
-     * @param toIndex the index of the last element, exclusive, to be sorted
-     *
-     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
-     * @throws ArrayIndexOutOfBoundsException
-     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
-     *
-     * @since 1.8
-     */
-    public static void parallelSort(int[] a, int fromIndex, int toIndex) {
-        rangeCheck(a.length, fromIndex, toIndex);
-        int n = toIndex - fromIndex, p, g;
-        if (n <= MIN_ARRAY_SORT_GRAN ||
-            (p = ForkJoinPool.getCommonPoolParallelism()) == 1)
-            DualPivotQuicksort.sort(a, fromIndex, toIndex - 1, null, 0, 0);
-        else
-            new ArraysParallelSortHelpers.FJInt.Sorter
-                (null, a, new int[n], fromIndex, n, 0,
-                 ((g = n / (p << 2)) <= MIN_ARRAY_SORT_GRAN) ?
-                 MIN_ARRAY_SORT_GRAN : g).invoke();
-    }
-
-    /**
-     * Sorts the specified array into ascending numerical order.
-     *
-     * @implNote The sorting algorithm is a parallel sort-merge that breaks the
-     * array into sub-arrays that are themselves sorted and then merged. When
-     * the sub-array length reaches a minimum granularity, the sub-array is
-     * sorted using the appropriate {@link Arrays#sort(long[]) Arrays.sort}
-     * method. If the length of the specified array is less than the minimum
-     * granularity, then it is sorted using the appropriate {@link
-     * Arrays#sort(long[]) Arrays.sort} method. The algorithm requires a
-     * working space no greater than the size of the original array. The
-     * {@link ForkJoinPool#commonPool() ForkJoin common pool} is used to
-     * execute any parallel tasks.
-     *
-     * @param a the array to be sorted
-     *
-     * @since 1.8
-     */
-    public static void parallelSort(long[] a) {
-        int n = a.length, p, g;
-        if (n <= MIN_ARRAY_SORT_GRAN ||
-            (p = ForkJoinPool.getCommonPoolParallelism()) == 1)
-            DualPivotQuicksort.sort(a, 0, n - 1, null, 0, 0);
-        else
-            new ArraysParallelSortHelpers.FJLong.Sorter
-                (null, a, new long[n], 0, n, 0,
-                 ((g = n / (p << 2)) <= MIN_ARRAY_SORT_GRAN) ?
-                 MIN_ARRAY_SORT_GRAN : g).invoke();
-    }
-
-    /**
-     * Sorts the specified range of the array into ascending numerical order.
-     * The range to be sorted extends from the index {@code fromIndex},
-     * inclusive, to the index {@code toIndex}, exclusive. If
-     * {@code fromIndex == toIndex}, the range to be sorted is empty.
-     *
-     * @implNote The sorting algorithm is a parallel sort-merge that breaks the
-     * array into sub-arrays that are themselves sorted and then merged. When
-     * the sub-array length reaches a minimum granularity, the sub-array is
-     * sorted using the appropriate {@link Arrays#sort(long[]) Arrays.sort}
-     * method. If the length of the specified array is less than the minimum
-     * granularity, then it is sorted using the appropriate {@link
-     * Arrays#sort(long[]) Arrays.sort} method. The algorithm requires a working
-     * space no greater than the size of the specified range of the original
-     * array. The {@link ForkJoinPool#commonPool() ForkJoin common pool} is
-     * used to execute any parallel tasks.
-     *
-     * @param a the array to be sorted
-     * @param fromIndex the index of the first element, inclusive, to be sorted
-     * @param toIndex the index of the last element, exclusive, to be sorted
-     *
-     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
-     * @throws ArrayIndexOutOfBoundsException
-     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
-     *
-     * @since 1.8
-     */
-    public static void parallelSort(long[] a, int fromIndex, int toIndex) {
-        rangeCheck(a.length, fromIndex, toIndex);
-        int n = toIndex - fromIndex, p, g;
-        if (n <= MIN_ARRAY_SORT_GRAN ||
-            (p = ForkJoinPool.getCommonPoolParallelism()) == 1)
-            DualPivotQuicksort.sort(a, fromIndex, toIndex - 1, null, 0, 0);
-        else
-            new ArraysParallelSortHelpers.FJLong.Sorter
-                (null, a, new long[n], fromIndex, n, 0,
-                 ((g = n / (p << 2)) <= MIN_ARRAY_SORT_GRAN) ?
-                 MIN_ARRAY_SORT_GRAN : g).invoke();
-    }
-
-    /**
-     * Sorts the specified array into ascending numerical order.
-     *
-     * <p>The {@code <} relation does not provide a total order on all float
-     * values: {@code -0.0f == 0.0f} is {@code true} and a {@code Float.NaN}
-     * value compares neither less than, greater than, nor equal to any value,
-     * even itself. This method uses the total order imposed by the method
-     * {@link Float#compareTo}: {@code -0.0f} is treated as less than value
-     * {@code 0.0f} and {@code Float.NaN} is considered greater than any
-     * other value and all {@code Float.NaN} values are considered equal.
-     *
-     * @implNote The sorting algorithm is a parallel sort-merge that breaks the
-     * array into sub-arrays that are themselves sorted and then merged. When
-     * the sub-array length reaches a minimum granularity, the sub-array is
-     * sorted using the appropriate {@link Arrays#sort(float[]) Arrays.sort}
-     * method. If the length of the specified array is less than the minimum
-     * granularity, then it is sorted using the appropriate {@link
-     * Arrays#sort(float[]) Arrays.sort} method. The algorithm requires a
-     * working space no greater than the size of the original array. The
-     * {@link ForkJoinPool#commonPool() ForkJoin common pool} is used to
-     * execute any parallel tasks.
-     *
-     * @param a the array to be sorted
-     *
-     * @since 1.8
-     */
-    public static void parallelSort(float[] a) {
-        int n = a.length, p, g;
-        if (n <= MIN_ARRAY_SORT_GRAN ||
-            (p = ForkJoinPool.getCommonPoolParallelism()) == 1)
-            DualPivotQuicksort.sort(a, 0, n - 1, null, 0, 0);
-        else
-            new ArraysParallelSortHelpers.FJFloat.Sorter
-                (null, a, new float[n], 0, n, 0,
-                 ((g = n / (p << 2)) <= MIN_ARRAY_SORT_GRAN) ?
-                 MIN_ARRAY_SORT_GRAN : g).invoke();
-    }
-
-    /**
-     * Sorts the specified range of the array into ascending numerical order.
-     * The range to be sorted extends from the index {@code fromIndex},
-     * inclusive, to the index {@code toIndex}, exclusive. If
-     * {@code fromIndex == toIndex}, the range to be sorted is empty.
-     *
-     * <p>The {@code <} relation does not provide a total order on all float
-     * values: {@code -0.0f == 0.0f} is {@code true} and a {@code Float.NaN}
-     * value compares neither less than, greater than, nor equal to any value,
-     * even itself. This method uses the total order imposed by the method
-     * {@link Float#compareTo}: {@code -0.0f} is treated as less than value
-     * {@code 0.0f} and {@code Float.NaN} is considered greater than any
-     * other value and all {@code Float.NaN} values are considered equal.
-     *
-     * @implNote The sorting algorithm is a parallel sort-merge that breaks the
-     * array into sub-arrays that are themselves sorted and then merged. When
-     * the sub-array length reaches a minimum granularity, the sub-array is
-     * sorted using the appropriate {@link Arrays#sort(float[]) Arrays.sort}
-     * method. If the length of the specified array is less than the minimum
-     * granularity, then it is sorted using the appropriate {@link
-     * Arrays#sort(float[]) Arrays.sort} method. The algorithm requires a working
-     * space no greater than the size of the specified range of the original
-     * array. The {@link ForkJoinPool#commonPool() ForkJoin common pool} is
-     * used to execute any parallel tasks.
-     *
-     * @param a the array to be sorted
-     * @param fromIndex the index of the first element, inclusive, to be sorted
-     * @param toIndex the index of the last element, exclusive, to be sorted
-     *
-     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
-     * @throws ArrayIndexOutOfBoundsException
-     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
-     *
-     * @since 1.8
-     */
-    public static void parallelSort(float[] a, int fromIndex, int toIndex) {
-        rangeCheck(a.length, fromIndex, toIndex);
-        int n = toIndex - fromIndex, p, g;
-        if (n <= MIN_ARRAY_SORT_GRAN ||
-            (p = ForkJoinPool.getCommonPoolParallelism()) == 1)
-            DualPivotQuicksort.sort(a, fromIndex, toIndex - 1, null, 0, 0);
-        else
-            new ArraysParallelSortHelpers.FJFloat.Sorter
-                (null, a, new float[n], fromIndex, n, 0,
-                 ((g = n / (p << 2)) <= MIN_ARRAY_SORT_GRAN) ?
-                 MIN_ARRAY_SORT_GRAN : g).invoke();
-    }
-
-    /**
-     * Sorts the specified array into ascending numerical order.
-     *
-     * <p>The {@code <} relation does not provide a total order on all double
-     * values: {@code -0.0d == 0.0d} is {@code true} and a {@code Double.NaN}
-     * value compares neither less than, greater than, nor equal to any value,
-     * even itself. This method uses the total order imposed by the method
-     * {@link Double#compareTo}: {@code -0.0d} is treated as less than value
-     * {@code 0.0d} and {@code Double.NaN} is considered greater than any
-     * other value and all {@code Double.NaN} values are considered equal.
-     *
-     * @implNote The sorting algorithm is a parallel sort-merge that breaks the
-     * array into sub-arrays that are themselves sorted and then merged. When
-     * the sub-array length reaches a minimum granularity, the sub-array is
-     * sorted using the appropriate {@link Arrays#sort(double[]) Arrays.sort}
-     * method. If the length of the specified array is less than the minimum
-     * granularity, then it is sorted using the appropriate {@link
-     * Arrays#sort(double[]) Arrays.sort} method. The algorithm requires a
-     * working space no greater than the size of the original array. The
-     * {@link ForkJoinPool#commonPool() ForkJoin common pool} is used to
-     * execute any parallel tasks.
-     *
-     * @param a the array to be sorted
-     *
-     * @since 1.8
-     */
-    public static void parallelSort(double[] a) {
-        int n = a.length, p, g;
-        if (n <= MIN_ARRAY_SORT_GRAN ||
-            (p = ForkJoinPool.getCommonPoolParallelism()) == 1)
-            DualPivotQuicksort.sort(a, 0, n - 1, null, 0, 0);
-        else
-            new ArraysParallelSortHelpers.FJDouble.Sorter
-                (null, a, new double[n], 0, n, 0,
-                 ((g = n / (p << 2)) <= MIN_ARRAY_SORT_GRAN) ?
-                 MIN_ARRAY_SORT_GRAN : g).invoke();
-    }
-
-    /**
-     * Sorts the specified range of the array into ascending numerical order.
-     * The range to be sorted extends from the index {@code fromIndex},
-     * inclusive, to the index {@code toIndex}, exclusive. If
-     * {@code fromIndex == toIndex}, the range to be sorted is empty.
-     *
-     * <p>The {@code <} relation does not provide a total order on all double
-     * values: {@code -0.0d == 0.0d} is {@code true} and a {@code Double.NaN}
-     * value compares neither less than, greater than, nor equal to any value,
-     * even itself. This method uses the total order imposed by the method
-     * {@link Double#compareTo}: {@code -0.0d} is treated as less than value
-     * {@code 0.0d} and {@code Double.NaN} is considered greater than any
-     * other value and all {@code Double.NaN} values are considered equal.
-     *
-     * @implNote The sorting algorithm is a parallel sort-merge that breaks the
-     * array into sub-arrays that are themselves sorted and then merged. When
-     * the sub-array length reaches a minimum granularity, the sub-array is
-     * sorted using the appropriate {@link Arrays#sort(double[]) Arrays.sort}
-     * method. If the length of the specified array is less than the minimum
-     * granularity, then it is sorted using the appropriate {@link
-     * Arrays#sort(double[]) Arrays.sort} method. The algorithm requires a working
-     * space no greater than the size of the specified range of the original
-     * array. The {@link ForkJoinPool#commonPool() ForkJoin common pool} is
-     * used to execute any parallel tasks.
-     *
-     * @param a the array to be sorted
-     * @param fromIndex the index of the first element, inclusive, to be sorted
-     * @param toIndex the index of the last element, exclusive, to be sorted
-     *
-     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
-     * @throws ArrayIndexOutOfBoundsException
-     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
-     *
-     * @since 1.8
-     */
-    public static void parallelSort(double[] a, int fromIndex, int toIndex) {
-        rangeCheck(a.length, fromIndex, toIndex);
-        int n = toIndex - fromIndex, p, g;
-        if (n <= MIN_ARRAY_SORT_GRAN ||
-            (p = ForkJoinPool.getCommonPoolParallelism()) == 1)
-            DualPivotQuicksort.sort(a, fromIndex, toIndex - 1, null, 0, 0);
-        else
-            new ArraysParallelSortHelpers.FJDouble.Sorter
-                (null, a, new double[n], fromIndex, n, 0,
-                 ((g = n / (p << 2)) <= MIN_ARRAY_SORT_GRAN) ?
-                 MIN_ARRAY_SORT_GRAN : g).invoke();
-    }
+     * The minimum array length below which a parallel sorting
+     * algorithm will not further partition the sorting task. Using
+     * smaller sizes typically results in memory contention across
+     * tasks that makes parallel speedups unlikely.
+     */
+    private static final int MIN_ARRAY_SORT_GRAN = 1 << 13;
 
     /**
      * Sorts the specified array of objects into ascending order, according
--- a/src/java.base/share/classes/java/util/ArraysParallelSortHelpers.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/share/classes/java/util/ArraysParallelSortHelpers.java	Wed Nov 13 09:16:04 2019 +0000
@@ -24,7 +24,6 @@
  */
 package java.util;
 
-import java.util.concurrent.RecursiveAction;
 import java.util.concurrent.CountedCompleter;
 
 /**
@@ -36,7 +35,7 @@
  * Sorter classes based mainly on CilkSort
  * <A href="http://supertech.lcs.mit.edu/cilk/"> Cilk</A>:
  * Basic algorithm:
- * if array size is small, just use a sequential quicksort (via Arrays.sort)
+ * if array size is small, just use a sequential sort (via Arrays.sort)
  *         Otherwise:
  *         1. Break array in half.
  *         2. For each half,
@@ -63,14 +62,10 @@
  * need to keep track of the arrays, and are never themselves forked,
  * so don't hold any task state.
  *
- * The primitive class versions (FJByte... FJDouble) are
- * identical to each other except for type declarations.
- *
  * The base sequential sorts rely on non-public versions of TimSort,
- * ComparableTimSort, and DualPivotQuicksort sort methods that accept
- * temp workspace array slices that we will have already allocated, so
- * avoids redundant allocation. (Except for DualPivotQuicksort byte[]
- * sort, that does not ever use a workspace array.)
+ * ComparableTimSort sort methods that accept temp workspace array
+ * slices that we will have already allocated, so avoids redundant
+ * allocation.
  */
 /*package*/ class ArraysParallelSortHelpers {
 
@@ -142,7 +137,7 @@
                     Relay rc = new Relay(new Merger<>(fc, a, w, b+h, q,
                                                       b+u, n-u, wb+h, g, c));
                     new Sorter<>(rc, a, w, b+u, n-u, wb+u, g, c).fork();
-                    new Sorter<>(rc, a, w, b+h, q, wb+h, g, c).fork();;
+                    new Sorter<>(rc, a, w, b+h, q, wb+h, g, c).fork();
                     Relay bc = new Relay(new Merger<>(fc, a, w, b, q,
                                                       b+q, h-q, wb, g, c));
                     new Sorter<>(bc, a, w, b+q, h-q, wb+q, g, c).fork();
@@ -239,799 +234,6 @@
 
                 tryComplete();
             }
-
         }
-    } // FJObject
-
-    /** byte support class */
-    static final class FJByte {
-        static final class Sorter extends CountedCompleter<Void> {
-            @java.io.Serial
-            static final long serialVersionUID = 2446542900576103244L;
-            final byte[] a, w;
-            final int base, size, wbase, gran;
-            Sorter(CountedCompleter<?> par, byte[] a, byte[] w, int base,
-                   int size, int wbase, int gran) {
-                super(par);
-                this.a = a; this.w = w; this.base = base; this.size = size;
-                this.wbase = wbase; this.gran = gran;
-            }
-            public final void compute() {
-                CountedCompleter<?> s = this;
-                byte[] a = this.a, w = this.w; // localize all params
-                int b = this.base, n = this.size, wb = this.wbase, g = this.gran;
-                while (n > g) {
-                    int h = n >>> 1, q = h >>> 1, u = h + q; // quartiles
-                    Relay fc = new Relay(new Merger(s, w, a, wb, h,
-                                                    wb+h, n-h, b, g));
-                    Relay rc = new Relay(new Merger(fc, a, w, b+h, q,
-                                                    b+u, n-u, wb+h, g));
-                    new Sorter(rc, a, w, b+u, n-u, wb+u, g).fork();
-                    new Sorter(rc, a, w, b+h, q, wb+h, g).fork();;
-                    Relay bc = new Relay(new Merger(fc, a, w, b, q,
-                                                    b+q, h-q, wb, g));
-                    new Sorter(bc, a, w, b+q, h-q, wb+q, g).fork();
-                    s = new EmptyCompleter(bc);
-                    n = q;
-                }
-                DualPivotQuicksort.sort(a, b, b + n - 1);
-                s.tryComplete();
-            }
-        }
-
-        static final class Merger extends CountedCompleter<Void> {
-            @java.io.Serial
-            static final long serialVersionUID = 2446542900576103244L;
-            final byte[] a, w; // main and workspace arrays
-            final int lbase, lsize, rbase, rsize, wbase, gran;
-            Merger(CountedCompleter<?> par, byte[] a, byte[] w,
-                   int lbase, int lsize, int rbase,
-                   int rsize, int wbase, int gran) {
-                super(par);
-                this.a = a; this.w = w;
-                this.lbase = lbase; this.lsize = lsize;
-                this.rbase = rbase; this.rsize = rsize;
-                this.wbase = wbase; this.gran = gran;
-            }
-
-            public final void compute() {
-                byte[] a = this.a, w = this.w; // localize all params
-                int lb = this.lbase, ln = this.lsize, rb = this.rbase,
-                    rn = this.rsize, k = this.wbase, g = this.gran;
-                if (a == null || w == null || lb < 0 || rb < 0 || k < 0)
-                    throw new IllegalStateException(); // hoist checks
-                for (int lh, rh;;) {  // split larger, find point in smaller
-                    if (ln >= rn) {
-                        if (ln <= g)
-                            break;
-                        rh = rn;
-                        byte split = a[(lh = ln >>> 1) + lb];
-                        for (int lo = 0; lo < rh; ) {
-                            int rm = (lo + rh) >>> 1;
-                            if (split <= a[rm + rb])
-                                rh = rm;
-                            else
-                                lo = rm + 1;
-                        }
-                    }
-                    else {
-                        if (rn <= g)
-                            break;
-                        lh = ln;
-                        byte split = a[(rh = rn >>> 1) + rb];
-                        for (int lo = 0; lo < lh; ) {
-                            int lm = (lo + lh) >>> 1;
-                            if (split <= a[lm + lb])
-                                lh = lm;
-                            else
-                                lo = lm + 1;
-                        }
-                    }
-                    Merger m = new Merger(this, a, w, lb + lh, ln - lh,
-                                          rb + rh, rn - rh,
-                                          k + lh + rh, g);
-                    rn = rh;
-                    ln = lh;
-                    addToPendingCount(1);
-                    m.fork();
-                }
-
-                int lf = lb + ln, rf = rb + rn; // index bounds
-                while (lb < lf && rb < rf) {
-                    byte t, al, ar;
-                    if ((al = a[lb]) <= (ar = a[rb])) {
-                        lb++; t = al;
-                    }
-                    else {
-                        rb++; t = ar;
-                    }
-                    w[k++] = t;
-                }
-                if (rb < rf)
-                    System.arraycopy(a, rb, w, k, rf - rb);
-                else if (lb < lf)
-                    System.arraycopy(a, lb, w, k, lf - lb);
-                tryComplete();
-            }
-        }
-    } // FJByte
-
-    /** char support class */
-    static final class FJChar {
-        static final class Sorter extends CountedCompleter<Void> {
-            @java.io.Serial
-            static final long serialVersionUID = 2446542900576103244L;
-            final char[] a, w;
-            final int base, size, wbase, gran;
-            Sorter(CountedCompleter<?> par, char[] a, char[] w, int base,
-                   int size, int wbase, int gran) {
-                super(par);
-                this.a = a; this.w = w; this.base = base; this.size = size;
-                this.wbase = wbase; this.gran = gran;
-            }
-            public final void compute() {
-                CountedCompleter<?> s = this;
-                char[] a = this.a, w = this.w; // localize all params
-                int b = this.base, n = this.size, wb = this.wbase, g = this.gran;
-                while (n > g) {
-                    int h = n >>> 1, q = h >>> 1, u = h + q; // quartiles
-                    Relay fc = new Relay(new Merger(s, w, a, wb, h,
-                                                    wb+h, n-h, b, g));
-                    Relay rc = new Relay(new Merger(fc, a, w, b+h, q,
-                                                    b+u, n-u, wb+h, g));
-                    new Sorter(rc, a, w, b+u, n-u, wb+u, g).fork();
-                    new Sorter(rc, a, w, b+h, q, wb+h, g).fork();;
-                    Relay bc = new Relay(new Merger(fc, a, w, b, q,
-                                                    b+q, h-q, wb, g));
-                    new Sorter(bc, a, w, b+q, h-q, wb+q, g).fork();
-                    s = new EmptyCompleter(bc);
-                    n = q;
-                }
-                DualPivotQuicksort.sort(a, b, b + n - 1, w, wb, n);
-                s.tryComplete();
-            }
-        }
-
-        static final class Merger extends CountedCompleter<Void> {
-            @java.io.Serial
-            static final long serialVersionUID = 2446542900576103244L;
-            final char[] a, w; // main and workspace arrays
-            final int lbase, lsize, rbase, rsize, wbase, gran;
-            Merger(CountedCompleter<?> par, char[] a, char[] w,
-                   int lbase, int lsize, int rbase,
-                   int rsize, int wbase, int gran) {
-                super(par);
-                this.a = a; this.w = w;
-                this.lbase = lbase; this.lsize = lsize;
-                this.rbase = rbase; this.rsize = rsize;
-                this.wbase = wbase; this.gran = gran;
-            }
-
-            public final void compute() {
-                char[] a = this.a, w = this.w; // localize all params
-                int lb = this.lbase, ln = this.lsize, rb = this.rbase,
-                    rn = this.rsize, k = this.wbase, g = this.gran;
-                if (a == null || w == null || lb < 0 || rb < 0 || k < 0)
-                    throw new IllegalStateException(); // hoist checks
-                for (int lh, rh;;) {  // split larger, find point in smaller
-                    if (ln >= rn) {
-                        if (ln <= g)
-                            break;
-                        rh = rn;
-                        char split = a[(lh = ln >>> 1) + lb];
-                        for (int lo = 0; lo < rh; ) {
-                            int rm = (lo + rh) >>> 1;
-                            if (split <= a[rm + rb])
-                                rh = rm;
-                            else
-                                lo = rm + 1;
-                        }
-                    }
-                    else {
-                        if (rn <= g)
-                            break;
-                        lh = ln;
-                        char split = a[(rh = rn >>> 1) + rb];
-                        for (int lo = 0; lo < lh; ) {
-                            int lm = (lo + lh) >>> 1;
-                            if (split <= a[lm + lb])
-                                lh = lm;
-                            else
-                                lo = lm + 1;
-                        }
-                    }
-                    Merger m = new Merger(this, a, w, lb + lh, ln - lh,
-                                          rb + rh, rn - rh,
-                                          k + lh + rh, g);
-                    rn = rh;
-                    ln = lh;
-                    addToPendingCount(1);
-                    m.fork();
-                }
-
-                int lf = lb + ln, rf = rb + rn; // index bounds
-                while (lb < lf && rb < rf) {
-                    char t, al, ar;
-                    if ((al = a[lb]) <= (ar = a[rb])) {
-                        lb++; t = al;
-                    }
-                    else {
-                        rb++; t = ar;
-                    }
-                    w[k++] = t;
-                }
-                if (rb < rf)
-                    System.arraycopy(a, rb, w, k, rf - rb);
-                else if (lb < lf)
-                    System.arraycopy(a, lb, w, k, lf - lb);
-                tryComplete();
-            }
-        }
-    } // FJChar
-
-    /** short support class */
-    static final class FJShort {
-        static final class Sorter extends CountedCompleter<Void> {
-            @java.io.Serial
-            static final long serialVersionUID = 2446542900576103244L;
-            final short[] a, w;
-            final int base, size, wbase, gran;
-            Sorter(CountedCompleter<?> par, short[] a, short[] w, int base,
-                   int size, int wbase, int gran) {
-                super(par);
-                this.a = a; this.w = w; this.base = base; this.size = size;
-                this.wbase = wbase; this.gran = gran;
-            }
-            public final void compute() {
-                CountedCompleter<?> s = this;
-                short[] a = this.a, w = this.w; // localize all params
-                int b = this.base, n = this.size, wb = this.wbase, g = this.gran;
-                while (n > g) {
-                    int h = n >>> 1, q = h >>> 1, u = h + q; // quartiles
-                    Relay fc = new Relay(new Merger(s, w, a, wb, h,
-                                                    wb+h, n-h, b, g));
-                    Relay rc = new Relay(new Merger(fc, a, w, b+h, q,
-                                                    b+u, n-u, wb+h, g));
-                    new Sorter(rc, a, w, b+u, n-u, wb+u, g).fork();
-                    new Sorter(rc, a, w, b+h, q, wb+h, g).fork();;
-                    Relay bc = new Relay(new Merger(fc, a, w, b, q,
-                                                    b+q, h-q, wb, g));
-                    new Sorter(bc, a, w, b+q, h-q, wb+q, g).fork();
-                    s = new EmptyCompleter(bc);
-                    n = q;
-                }
-                DualPivotQuicksort.sort(a, b, b + n - 1, w, wb, n);
-                s.tryComplete();
-            }
-        }
-
-        static final class Merger extends CountedCompleter<Void> {
-            @java.io.Serial
-            static final long serialVersionUID = 2446542900576103244L;
-            final short[] a, w; // main and workspace arrays
-            final int lbase, lsize, rbase, rsize, wbase, gran;
-            Merger(CountedCompleter<?> par, short[] a, short[] w,
-                   int lbase, int lsize, int rbase,
-                   int rsize, int wbase, int gran) {
-                super(par);
-                this.a = a; this.w = w;
-                this.lbase = lbase; this.lsize = lsize;
-                this.rbase = rbase; this.rsize = rsize;
-                this.wbase = wbase; this.gran = gran;
-            }
-
-            public final void compute() {
-                short[] a = this.a, w = this.w; // localize all params
-                int lb = this.lbase, ln = this.lsize, rb = this.rbase,
-                    rn = this.rsize, k = this.wbase, g = this.gran;
-                if (a == null || w == null || lb < 0 || rb < 0 || k < 0)
-                    throw new IllegalStateException(); // hoist checks
-                for (int lh, rh;;) {  // split larger, find point in smaller
-                    if (ln >= rn) {
-                        if (ln <= g)
-                            break;
-                        rh = rn;
-                        short split = a[(lh = ln >>> 1) + lb];
-                        for (int lo = 0; lo < rh; ) {
-                            int rm = (lo + rh) >>> 1;
-                            if (split <= a[rm + rb])
-                                rh = rm;
-                            else
-                                lo = rm + 1;
-                        }
-                    }
-                    else {
-                        if (rn <= g)
-                            break;
-                        lh = ln;
-                        short split = a[(rh = rn >>> 1) + rb];
-                        for (int lo = 0; lo < lh; ) {
-                            int lm = (lo + lh) >>> 1;
-                            if (split <= a[lm + lb])
-                                lh = lm;
-                            else
-                                lo = lm + 1;
-                        }
-                    }
-                    Merger m = new Merger(this, a, w, lb + lh, ln - lh,
-                                          rb + rh, rn - rh,
-                                          k + lh + rh, g);
-                    rn = rh;
-                    ln = lh;
-                    addToPendingCount(1);
-                    m.fork();
-                }
-
-                int lf = lb + ln, rf = rb + rn; // index bounds
-                while (lb < lf && rb < rf) {
-                    short t, al, ar;
-                    if ((al = a[lb]) <= (ar = a[rb])) {
-                        lb++; t = al;
-                    }
-                    else {
-                        rb++; t = ar;
-                    }
-                    w[k++] = t;
-                }
-                if (rb < rf)
-                    System.arraycopy(a, rb, w, k, rf - rb);
-                else if (lb < lf)
-                    System.arraycopy(a, lb, w, k, lf - lb);
-                tryComplete();
-            }
-        }
-    } // FJShort
-
-    /** int support class */
-    static final class FJInt {
-        static final class Sorter extends CountedCompleter<Void> {
-            @java.io.Serial
-            static final long serialVersionUID = 2446542900576103244L;
-            final int[] a, w;
-            final int base, size, wbase, gran;
-            Sorter(CountedCompleter<?> par, int[] a, int[] w, int base,
-                   int size, int wbase, int gran) {
-                super(par);
-                this.a = a; this.w = w; this.base = base; this.size = size;
-                this.wbase = wbase; this.gran = gran;
-            }
-            public final void compute() {
-                CountedCompleter<?> s = this;
-                int[] a = this.a, w = this.w; // localize all params
-                int b = this.base, n = this.size, wb = this.wbase, g = this.gran;
-                while (n > g) {
-                    int h = n >>> 1, q = h >>> 1, u = h + q; // quartiles
-                    Relay fc = new Relay(new Merger(s, w, a, wb, h,
-                                                    wb+h, n-h, b, g));
-                    Relay rc = new Relay(new Merger(fc, a, w, b+h, q,
-                                                    b+u, n-u, wb+h, g));
-                    new Sorter(rc, a, w, b+u, n-u, wb+u, g).fork();
-                    new Sorter(rc, a, w, b+h, q, wb+h, g).fork();;
-                    Relay bc = new Relay(new Merger(fc, a, w, b, q,
-                                                    b+q, h-q, wb, g));
-                    new Sorter(bc, a, w, b+q, h-q, wb+q, g).fork();
-                    s = new EmptyCompleter(bc);
-                    n = q;
-                }
-                DualPivotQuicksort.sort(a, b, b + n - 1, w, wb, n);
-                s.tryComplete();
-            }
-        }
-
-        static final class Merger extends CountedCompleter<Void> {
-            @java.io.Serial
-            static final long serialVersionUID = 2446542900576103244L;
-            final int[] a, w; // main and workspace arrays
-            final int lbase, lsize, rbase, rsize, wbase, gran;
-            Merger(CountedCompleter<?> par, int[] a, int[] w,
-                   int lbase, int lsize, int rbase,
-                   int rsize, int wbase, int gran) {
-                super(par);
-                this.a = a; this.w = w;
-                this.lbase = lbase; this.lsize = lsize;
-                this.rbase = rbase; this.rsize = rsize;
-                this.wbase = wbase; this.gran = gran;
-            }
-
-            public final void compute() {
-                int[] a = this.a, w = this.w; // localize all params
-                int lb = this.lbase, ln = this.lsize, rb = this.rbase,
-                    rn = this.rsize, k = this.wbase, g = this.gran;
-                if (a == null || w == null || lb < 0 || rb < 0 || k < 0)
-                    throw new IllegalStateException(); // hoist checks
-                for (int lh, rh;;) {  // split larger, find point in smaller
-                    if (ln >= rn) {
-                        if (ln <= g)
-                            break;
-                        rh = rn;
-                        int split = a[(lh = ln >>> 1) + lb];
-                        for (int lo = 0; lo < rh; ) {
-                            int rm = (lo + rh) >>> 1;
-                            if (split <= a[rm + rb])
-                                rh = rm;
-                            else
-                                lo = rm + 1;
-                        }
-                    }
-                    else {
-                        if (rn <= g)
-                            break;
-                        lh = ln;
-                        int split = a[(rh = rn >>> 1) + rb];
-                        for (int lo = 0; lo < lh; ) {
-                            int lm = (lo + lh) >>> 1;
-                            if (split <= a[lm + lb])
-                                lh = lm;
-                            else
-                                lo = lm + 1;
-                        }
-                    }
-                    Merger m = new Merger(this, a, w, lb + lh, ln - lh,
-                                          rb + rh, rn - rh,
-                                          k + lh + rh, g);
-                    rn = rh;
-                    ln = lh;
-                    addToPendingCount(1);
-                    m.fork();
-                }
-
-                int lf = lb + ln, rf = rb + rn; // index bounds
-                while (lb < lf && rb < rf) {
-                    int t, al, ar;
-                    if ((al = a[lb]) <= (ar = a[rb])) {
-                        lb++; t = al;
-                    }
-                    else {
-                        rb++; t = ar;
-                    }
-                    w[k++] = t;
-                }
-                if (rb < rf)
-                    System.arraycopy(a, rb, w, k, rf - rb);
-                else if (lb < lf)
-                    System.arraycopy(a, lb, w, k, lf - lb);
-                tryComplete();
-            }
-        }
-    } // FJInt
-
-    /** long support class */
-    static final class FJLong {
-        static final class Sorter extends CountedCompleter<Void> {
-            @java.io.Serial
-            static final long serialVersionUID = 2446542900576103244L;
-            final long[] a, w;
-            final int base, size, wbase, gran;
-            Sorter(CountedCompleter<?> par, long[] a, long[] w, int base,
-                   int size, int wbase, int gran) {
-                super(par);
-                this.a = a; this.w = w; this.base = base; this.size = size;
-                this.wbase = wbase; this.gran = gran;
-            }
-            public final void compute() {
-                CountedCompleter<?> s = this;
-                long[] a = this.a, w = this.w; // localize all params
-                int b = this.base, n = this.size, wb = this.wbase, g = this.gran;
-                while (n > g) {
-                    int h = n >>> 1, q = h >>> 1, u = h + q; // quartiles
-                    Relay fc = new Relay(new Merger(s, w, a, wb, h,
-                                                    wb+h, n-h, b, g));
-                    Relay rc = new Relay(new Merger(fc, a, w, b+h, q,
-                                                    b+u, n-u, wb+h, g));
-                    new Sorter(rc, a, w, b+u, n-u, wb+u, g).fork();
-                    new Sorter(rc, a, w, b+h, q, wb+h, g).fork();;
-                    Relay bc = new Relay(new Merger(fc, a, w, b, q,
-                                                    b+q, h-q, wb, g));
-                    new Sorter(bc, a, w, b+q, h-q, wb+q, g).fork();
-                    s = new EmptyCompleter(bc);
-                    n = q;
-                }
-                DualPivotQuicksort.sort(a, b, b + n - 1, w, wb, n);
-                s.tryComplete();
-            }
-        }
-
-        static final class Merger extends CountedCompleter<Void> {
-            @java.io.Serial
-            static final long serialVersionUID = 2446542900576103244L;
-            final long[] a, w; // main and workspace arrays
-            final int lbase, lsize, rbase, rsize, wbase, gran;
-            Merger(CountedCompleter<?> par, long[] a, long[] w,
-                   int lbase, int lsize, int rbase,
-                   int rsize, int wbase, int gran) {
-                super(par);
-                this.a = a; this.w = w;
-                this.lbase = lbase; this.lsize = lsize;
-                this.rbase = rbase; this.rsize = rsize;
-                this.wbase = wbase; this.gran = gran;
-            }
-
-            public final void compute() {
-                long[] a = this.a, w = this.w; // localize all params
-                int lb = this.lbase, ln = this.lsize, rb = this.rbase,
-                    rn = this.rsize, k = this.wbase, g = this.gran;
-                if (a == null || w == null || lb < 0 || rb < 0 || k < 0)
-                    throw new IllegalStateException(); // hoist checks
-                for (int lh, rh;;) {  // split larger, find point in smaller
-                    if (ln >= rn) {
-                        if (ln <= g)
-                            break;
-                        rh = rn;
-                        long split = a[(lh = ln >>> 1) + lb];
-                        for (int lo = 0; lo < rh; ) {
-                            int rm = (lo + rh) >>> 1;
-                            if (split <= a[rm + rb])
-                                rh = rm;
-                            else
-                                lo = rm + 1;
-                        }
-                    }
-                    else {
-                        if (rn <= g)
-                            break;
-                        lh = ln;
-                        long split = a[(rh = rn >>> 1) + rb];
-                        for (int lo = 0; lo < lh; ) {
-                            int lm = (lo + lh) >>> 1;
-                            if (split <= a[lm + lb])
-                                lh = lm;
-                            else
-                                lo = lm + 1;
-                        }
-                    }
-                    Merger m = new Merger(this, a, w, lb + lh, ln - lh,
-                                          rb + rh, rn - rh,
-                                          k + lh + rh, g);
-                    rn = rh;
-                    ln = lh;
-                    addToPendingCount(1);
-                    m.fork();
-                }
-
-                int lf = lb + ln, rf = rb + rn; // index bounds
-                while (lb < lf && rb < rf) {
-                    long t, al, ar;
-                    if ((al = a[lb]) <= (ar = a[rb])) {
-                        lb++; t = al;
-                    }
-                    else {
-                        rb++; t = ar;
-                    }
-                    w[k++] = t;
-                }
-                if (rb < rf)
-                    System.arraycopy(a, rb, w, k, rf - rb);
-                else if (lb < lf)
-                    System.arraycopy(a, lb, w, k, lf - lb);
-                tryComplete();
-            }
-        }
-    } // FJLong
-
-    /** float support class */
-    static final class FJFloat {
-        static final class Sorter extends CountedCompleter<Void> {
-            @java.io.Serial
-            static final long serialVersionUID = 2446542900576103244L;
-            final float[] a, w;
-            final int base, size, wbase, gran;
-            Sorter(CountedCompleter<?> par, float[] a, float[] w, int base,
-                   int size, int wbase, int gran) {
-                super(par);
-                this.a = a; this.w = w; this.base = base; this.size = size;
-                this.wbase = wbase; this.gran = gran;
-            }
-            public final void compute() {
-                CountedCompleter<?> s = this;
-                float[] a = this.a, w = this.w; // localize all params
-                int b = this.base, n = this.size, wb = this.wbase, g = this.gran;
-                while (n > g) {
-                    int h = n >>> 1, q = h >>> 1, u = h + q; // quartiles
-                    Relay fc = new Relay(new Merger(s, w, a, wb, h,
-                                                    wb+h, n-h, b, g));
-                    Relay rc = new Relay(new Merger(fc, a, w, b+h, q,
-                                                    b+u, n-u, wb+h, g));
-                    new Sorter(rc, a, w, b+u, n-u, wb+u, g).fork();
-                    new Sorter(rc, a, w, b+h, q, wb+h, g).fork();;
-                    Relay bc = new Relay(new Merger(fc, a, w, b, q,
-                                                    b+q, h-q, wb, g));
-                    new Sorter(bc, a, w, b+q, h-q, wb+q, g).fork();
-                    s = new EmptyCompleter(bc);
-                    n = q;
-                }
-                DualPivotQuicksort.sort(a, b, b + n - 1, w, wb, n);
-                s.tryComplete();
-            }
-        }
-
-        static final class Merger extends CountedCompleter<Void> {
-            @java.io.Serial
-            static final long serialVersionUID = 2446542900576103244L;
-            final float[] a, w; // main and workspace arrays
-            final int lbase, lsize, rbase, rsize, wbase, gran;
-            Merger(CountedCompleter<?> par, float[] a, float[] w,
-                   int lbase, int lsize, int rbase,
-                   int rsize, int wbase, int gran) {
-                super(par);
-                this.a = a; this.w = w;
-                this.lbase = lbase; this.lsize = lsize;
-                this.rbase = rbase; this.rsize = rsize;
-                this.wbase = wbase; this.gran = gran;
-            }
-
-            public final void compute() {
-                float[] a = this.a, w = this.w; // localize all params
-                int lb = this.lbase, ln = this.lsize, rb = this.rbase,
-                    rn = this.rsize, k = this.wbase, g = this.gran;
-                if (a == null || w == null || lb < 0 || rb < 0 || k < 0)
-                    throw new IllegalStateException(); // hoist checks
-                for (int lh, rh;;) {  // split larger, find point in smaller
-                    if (ln >= rn) {
-                        if (ln <= g)
-                            break;
-                        rh = rn;
-                        float split = a[(lh = ln >>> 1) + lb];
-                        for (int lo = 0; lo < rh; ) {
-                            int rm = (lo + rh) >>> 1;
-                            if (split <= a[rm + rb])
-                                rh = rm;
-                            else
-                                lo = rm + 1;
-                        }
-                    }
-                    else {
-                        if (rn <= g)
-                            break;
-                        lh = ln;
-                        float split = a[(rh = rn >>> 1) + rb];
-                        for (int lo = 0; lo < lh; ) {
-                            int lm = (lo + lh) >>> 1;
-                            if (split <= a[lm + lb])
-                                lh = lm;
-                            else
-                                lo = lm + 1;
-                        }
-                    }
-                    Merger m = new Merger(this, a, w, lb + lh, ln - lh,
-                                          rb + rh, rn - rh,
-                                          k + lh + rh, g);
-                    rn = rh;
-                    ln = lh;
-                    addToPendingCount(1);
-                    m.fork();
-                }
-
-                int lf = lb + ln, rf = rb + rn; // index bounds
-                while (lb < lf && rb < rf) {
-                    float t, al, ar;
-                    if ((al = a[lb]) <= (ar = a[rb])) {
-                        lb++; t = al;
-                    }
-                    else {
-                        rb++; t = ar;
-                    }
-                    w[k++] = t;
-                }
-                if (rb < rf)
-                    System.arraycopy(a, rb, w, k, rf - rb);
-                else if (lb < lf)
-                    System.arraycopy(a, lb, w, k, lf - lb);
-                tryComplete();
-            }
-        }
-    } // FJFloat
-
-    /** double support class */
-    static final class FJDouble {
-        static final class Sorter extends CountedCompleter<Void> {
-            @java.io.Serial
-            static final long serialVersionUID = 2446542900576103244L;
-            final double[] a, w;
-            final int base, size, wbase, gran;
-            Sorter(CountedCompleter<?> par, double[] a, double[] w, int base,
-                   int size, int wbase, int gran) {
-                super(par);
-                this.a = a; this.w = w; this.base = base; this.size = size;
-                this.wbase = wbase; this.gran = gran;
-            }
-            public final void compute() {
-                CountedCompleter<?> s = this;
-                double[] a = this.a, w = this.w; // localize all params
-                int b = this.base, n = this.size, wb = this.wbase, g = this.gran;
-                while (n > g) {
-                    int h = n >>> 1, q = h >>> 1, u = h + q; // quartiles
-                    Relay fc = new Relay(new Merger(s, w, a, wb, h,
-                                                    wb+h, n-h, b, g));
-                    Relay rc = new Relay(new Merger(fc, a, w, b+h, q,
-                                                    b+u, n-u, wb+h, g));
-                    new Sorter(rc, a, w, b+u, n-u, wb+u, g).fork();
-                    new Sorter(rc, a, w, b+h, q, wb+h, g).fork();;
-                    Relay bc = new Relay(new Merger(fc, a, w, b, q,
-                                                    b+q, h-q, wb, g));
-                    new Sorter(bc, a, w, b+q, h-q, wb+q, g).fork();
-                    s = new EmptyCompleter(bc);
-                    n = q;
-                }
-                DualPivotQuicksort.sort(a, b, b + n - 1, w, wb, n);
-                s.tryComplete();
-            }
-        }
-
-        static final class Merger extends CountedCompleter<Void> {
-            @java.io.Serial
-            static final long serialVersionUID = 2446542900576103244L;
-            final double[] a, w; // main and workspace arrays
-            final int lbase, lsize, rbase, rsize, wbase, gran;
-            Merger(CountedCompleter<?> par, double[] a, double[] w,
-                   int lbase, int lsize, int rbase,
-                   int rsize, int wbase, int gran) {
-                super(par);
-                this.a = a; this.w = w;
-                this.lbase = lbase; this.lsize = lsize;
-                this.rbase = rbase; this.rsize = rsize;
-                this.wbase = wbase; this.gran = gran;
-            }
-
-            public final void compute() {
-                double[] a = this.a, w = this.w; // localize all params
-                int lb = this.lbase, ln = this.lsize, rb = this.rbase,
-                    rn = this.rsize, k = this.wbase, g = this.gran;
-                if (a == null || w == null || lb < 0 || rb < 0 || k < 0)
-                    throw new IllegalStateException(); // hoist checks
-                for (int lh, rh;;) {  // split larger, find point in smaller
-                    if (ln >= rn) {
-                        if (ln <= g)
-                            break;
-                        rh = rn;
-                        double split = a[(lh = ln >>> 1) + lb];
-                        for (int lo = 0; lo < rh; ) {
-                            int rm = (lo + rh) >>> 1;
-                            if (split <= a[rm + rb])
-                                rh = rm;
-                            else
-                                lo = rm + 1;
-                        }
-                    }
-                    else {
-                        if (rn <= g)
-                            break;
-                        lh = ln;
-                        double split = a[(rh = rn >>> 1) + rb];
-                        for (int lo = 0; lo < lh; ) {
-                            int lm = (lo + lh) >>> 1;
-                            if (split <= a[lm + lb])
-                                lh = lm;
-                            else
-                                lo = lm + 1;
-                        }
-                    }
-                    Merger m = new Merger(this, a, w, lb + lh, ln - lh,
-                                          rb + rh, rn - rh,
-                                          k + lh + rh, g);
-                    rn = rh;
-                    ln = lh;
-                    addToPendingCount(1);
-                    m.fork();
-                }
-
-                int lf = lb + ln, rf = rb + rn; // index bounds
-                while (lb < lf && rb < rf) {
-                    double t, al, ar;
-                    if ((al = a[lb]) <= (ar = a[rb])) {
-                        lb++; t = al;
-                    }
-                    else {
-                        rb++; t = ar;
-                    }
-                    w[k++] = t;
-                }
-                if (rb < rf)
-                    System.arraycopy(a, rb, w, k, rf - rb);
-                else if (lb < lf)
-                    System.arraycopy(a, lb, w, k, lf - lb);
-                tryComplete();
-            }
-        }
-    } // FJDouble
-
+    }
 }
--- a/src/java.base/share/classes/java/util/DualPivotQuicksort.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/share/classes/java/util/DualPivotQuicksort.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,24 +25,28 @@
 
 package java.util;
 
+import java.util.concurrent.CountedCompleter;
+import java.util.concurrent.RecursiveTask;
+
 /**
- * This class implements the Dual-Pivot Quicksort algorithm by
- * Vladimir Yaroslavskiy, Jon Bentley, and Josh Bloch. The algorithm
- * offers O(n log(n)) performance on many data sets that cause other
- * quicksorts to degrade to quadratic performance, and is typically
+ * This class implements powerful and fully optimized versions, both
+ * sequential and parallel, of the Dual-Pivot Quicksort algorithm by
+ * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+ * offers O(n log(n)) performance on all data sets, and is typically
  * faster than traditional (one-pivot) Quicksort implementations.
  *
- * All exposed methods are package-private, designed to be invoked
- * from public methods (in class Arrays) after performing any
- * necessary array bounds checks and expanding parameters into the
- * required forms.
+ * There are also additional algorithms, invoked from the Dual-Pivot
+ * Quicksort, such as mixed insertion sort, merging of runs and heap
+ * sort, counting sort and parallel merge sort.
  *
  * @author Vladimir Yaroslavskiy
  * @author Jon Bentley
  * @author Josh Bloch
+ * @author Doug Lea
  *
- * @version 2011.02.11 m765.827.12i:5\7pm
- * @since 1.7
+ * @version 2018.08.18
+ *
+ * @since 1.7 * 14
  */
 final class DualPivotQuicksort {
 
@@ -51,3131 +55,4107 @@
      */
     private DualPivotQuicksort() {}
 
-    /*
-     * Tuning parameters.
+    /**
+     * Max array size to use mixed insertion sort.
+     */
+    private static final int MAX_MIXED_INSERTION_SORT_SIZE = 65;
+
+    /**
+     * Max array size to use insertion sort.
      */
+    private static final int MAX_INSERTION_SORT_SIZE = 44;
+
+    /**
+     * Min array size to perform sorting in parallel.
+     */
+    private static final int MIN_PARALLEL_SORT_SIZE = 4 << 10;
+
+    /**
+     * Min array size to try merging of runs.
+     */
+    private static final int MIN_TRY_MERGE_SIZE = 4 << 10;
 
     /**
-     * The maximum number of runs in merge sort.
+     * Min size of the first run to continue with scanning.
      */
-    private static final int MAX_RUN_COUNT = 67;
+    private static final int MIN_FIRST_RUN_SIZE = 16;
+
+    /**
+     * Min factor for the first runs to continue scanning.
+     */
+    private static final int MIN_FIRST_RUNS_FACTOR = 7;
 
     /**
-     * If the length of an array to be sorted is less than this
-     * constant, Quicksort is used in preference to merge sort.
+     * Max capacity of the index array for tracking runs.
+     */
+    private static final int MAX_RUN_CAPACITY = 5 << 10;
+
+    /**
+     * Min number of runs, required by parallel merging.
      */
-    private static final int QUICKSORT_THRESHOLD = 286;
+    private static final int MIN_RUN_COUNT = 4;
+
+    /**
+     * Min array size to use parallel merging of parts.
+     */
+    private static final int MIN_PARALLEL_MERGE_PARTS_SIZE = 4 << 10;
 
     /**
-     * If the length of an array to be sorted is less than this
-     * constant, insertion sort is used in preference to Quicksort.
+     * Min size of a byte array to use counting sort.
      */
-    private static final int INSERTION_SORT_THRESHOLD = 47;
+    private static final int MIN_BYTE_COUNTING_SORT_SIZE = 64;
 
     /**
-     * If the length of a byte array to be sorted is greater than this
-     * constant, counting sort is used in preference to insertion sort.
+     * Min size of a short or char array to use counting sort.
+     */
+    private static final int MIN_SHORT_OR_CHAR_COUNTING_SORT_SIZE = 1750;
+
+    /**
+     * Threshold of mixed insertion sort is incremented by this value.
      */
-    private static final int COUNTING_SORT_THRESHOLD_FOR_BYTE = 29;
+    private static final int DELTA = 3 << 1;
+
+    /**
+     * Max recursive partitioning depth before using heap sort.
+     */
+    private static final int MAX_RECURSION_DEPTH = 64 * DELTA;
 
     /**
-     * If the length of a short or char array to be sorted is greater
-     * than this constant, counting sort is used in preference to Quicksort.
+     * Calculates the double depth of parallel merging.
+     * Depth is negative, if tasks split before sorting.
+     *
+     * @param parallelism the parallelism level
+     * @param size the target size
+     * @return the depth of parallel merging
      */
-    private static final int COUNTING_SORT_THRESHOLD_FOR_SHORT_OR_CHAR = 3200;
-
-    /*
-     * Sorting methods for seven primitive types.
-     */
+    private static int getDepth(int parallelism, int size) {
+        int depth = 0;
+
+        while ((parallelism >>= 3) > 0 && (size >>= 2) > 0) {
+            depth -= 2;
+        }
+        return depth;
+    }
 
     /**
-     * Sorts the specified range of the array using the given
-     * workspace array slice if possible for merging
+     * Sorts the specified range of the array using parallel merge
+     * sort and/or Dual-Pivot Quicksort.
+     *
+     * To balance the faster splitting and parallelism of merge sort
+     * with the faster element partitioning of Quicksort, ranges are
+     * subdivided in tiers such that, if there is enough parallelism,
+     * the four-way parallel merge is started, still ensuring enough
+     * parallelism to process the partitions.
      *
      * @param a the array to be sorted
-     * @param left the index of the first element, inclusive, to be sorted
-     * @param right the index of the last element, inclusive, to be sorted
-     * @param work a workspace array (slice)
-     * @param workBase origin of usable space in work array
-     * @param workLen usable size of work array
+     * @param parallelism the parallelism level
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
      */
-    static void sort(int[] a, int left, int right,
-                     int[] work, int workBase, int workLen) {
-        // Use Quicksort on small arrays
-        if (right - left < QUICKSORT_THRESHOLD) {
-            sort(a, left, right, true);
-            return;
+    static void sort(int[] a, int parallelism, int low, int high) {
+        int size = high - low;
+
+        if (parallelism > 1 && size > MIN_PARALLEL_SORT_SIZE) {
+            int depth = getDepth(parallelism, size >> 12);
+            int[] b = depth == 0 ? null : new int[size];
+            new Sorter(null, a, b, low, size, low, depth).invoke();
+        } else {
+            sort(null, a, 0, low, high);
         }
-
-        /*
-         * Index run[i] is the start of i-th run
-         * (ascending or descending sequence).
-         */
-        int[] run = new int[MAX_RUN_COUNT + 1];
-        int count = 0; run[0] = left;
-
-        // Check if the array is nearly sorted
-        for (int k = left; k < right; run[count] = k) {
-            // Equal items in the beginning of the sequence
-            while (k < right && a[k] == a[k + 1])
-                k++;
-            if (k == right) break;  // Sequence finishes with equal items
-            if (a[k] < a[k + 1]) { // ascending
-                while (++k <= right && a[k - 1] <= a[k]);
-            } else if (a[k] > a[k + 1]) { // descending
-                while (++k <= right && a[k - 1] >= a[k]);
-                // Transform into an ascending sequence
-                for (int lo = run[count] - 1, hi = k; ++lo < --hi; ) {
-                    int t = a[lo]; a[lo] = a[hi]; a[hi] = t;
-                }
+    }
+
+    /**
+     * Sorts the specified array using the Dual-Pivot Quicksort and/or
+     * other sorts in special-cases, possibly with parallel partitions.
+     *
+     * @param sorter parallel context
+     * @param a the array to be sorted
+     * @param bits the combination of recursion depth and bit flag, where
+     *        the right bit "0" indicates that array is the leftmost part
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
+     */
+    static void sort(Sorter sorter, int[] a, int bits, int low, int high) {
+        while (true) {
+            int end = high - 1, size = high - low;
+
+            /*
+             * Run mixed insertion sort on small non-leftmost parts.
+             */
+            if (size < MAX_MIXED_INSERTION_SORT_SIZE + bits && (bits & 1) > 0) {
+                mixedInsertionSort(a, low, high - 3 * ((size >> 5) << 3), high);
+                return;
             }
 
-            // Merge a transformed descending sequence followed by an
-            // ascending sequence
-            if (run[count] > left && a[run[count]] >= a[run[count] - 1]) {
-                count--;
+            /*
+             * Invoke insertion sort on small leftmost part.
+             */
+            if (size < MAX_INSERTION_SORT_SIZE) {
+                insertionSort(a, low, high);
+                return;
+            }
+
+            /*
+             * Check if the whole array or large non-leftmost
+             * parts are nearly sorted and then merge runs.
+             */
+            if ((bits == 0 || size > MIN_TRY_MERGE_SIZE && (bits & 1) > 0)
+                    && tryMergeRuns(sorter, a, low, size)) {
+                return;
+            }
+
+            /*
+             * Switch to heap sort if execution
+             * time is becoming quadratic.
+             */
+            if ((bits += DELTA) > MAX_RECURSION_DEPTH) {
+                heapSort(a, low, high);
+                return;
             }
 
             /*
-             * The array is not highly structured,
-             * use Quicksort instead of merge sort.
+             * Use an inexpensive approximation of the golden ratio
+             * to select five sample elements and determine pivots.
+             */
+            int step = (size >> 3) * 3 + 3;
+
+            /*
+             * Five elements around (and including) the central element
+             * will be used for pivot selection as described below. The
+             * unequal choice of spacing these elements was empirically
+             * determined to work well on a wide variety of inputs.
              */
-            if (++count == MAX_RUN_COUNT) {
-                sort(a, left, right, true);
-                return;
+            int e1 = low + step;
+            int e5 = end - step;
+            int e3 = (e1 + e5) >>> 1;
+            int e2 = (e1 + e3) >>> 1;
+            int e4 = (e3 + e5) >>> 1;
+            int a3 = a[e3];
+
+            /*
+             * Sort these elements in place by the combination
+             * of 4-element sorting network and insertion sort.
+             *
+             *    5 ------o-----------o------------
+             *            |           |
+             *    4 ------|-----o-----o-----o------
+             *            |     |           |
+             *    2 ------o-----|-----o-----o------
+             *                  |     |
+             *    1 ------------o-----o------------
+             */
+            if (a[e5] < a[e2]) { int t = a[e5]; a[e5] = a[e2]; a[e2] = t; }
+            if (a[e4] < a[e1]) { int t = a[e4]; a[e4] = a[e1]; a[e1] = t; }
+            if (a[e5] < a[e4]) { int t = a[e5]; a[e5] = a[e4]; a[e4] = t; }
+            if (a[e2] < a[e1]) { int t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
+            if (a[e4] < a[e2]) { int t = a[e4]; a[e4] = a[e2]; a[e2] = t; }
+
+            if (a3 < a[e2]) {
+                if (a3 < a[e1]) {
+                    a[e3] = a[e2]; a[e2] = a[e1]; a[e1] = a3;
+                } else {
+                    a[e3] = a[e2]; a[e2] = a3;
+                }
+            } else if (a3 > a[e4]) {
+                if (a3 > a[e5]) {
+                    a[e3] = a[e4]; a[e4] = a[e5]; a[e5] = a3;
+                } else {
+                    a[e3] = a[e4]; a[e4] = a3;
+                }
             }
-        }
-
-        // These invariants should hold true:
-        //    run[0] = 0
-        //    run[<last>] = right + 1; (terminator)
-
-        if (count == 0) {
-            // A single equal run
-            return;
-        } else if (count == 1 && run[count] > right) {
-            // Either a single ascending or a transformed descending run.
-            // Always check that a final run is a proper terminator, otherwise
-            // we have an unterminated trailing run, to handle downstream.
-            return;
-        }
-        right++;
-        if (run[count] < right) {
-            // Corner case: the final run is not a terminator. This may happen
-            // if a final run is an equals run, or there is a single-element run
-            // at the end. Fix up by adding a proper terminator at the end.
-            // Note that we terminate with (right + 1), incremented earlier.
-            run[++count] = right;
-        }
-
-        // Determine alternation base for merge
-        byte odd = 0;
-        for (int n = 1; (n <<= 1) < count; odd ^= 1);
-
-        // Use or create temporary array b for merging
-        int[] b;                 // temp array; alternates with a
-        int ao, bo;              // array offsets from 'left'
-        int blen = right - left; // space needed for b
-        if (work == null || workLen < blen || workBase + blen > work.length) {
-            work = new int[blen];
-            workBase = 0;
-        }
-        if (odd == 0) {
-            System.arraycopy(a, left, work, workBase, blen);
-            b = a;
-            bo = 0;
-            a = work;
-            ao = workBase - left;
-        } else {
-            b = work;
-            ao = 0;
-            bo = workBase - left;
-        }
-
-        // Merging
-        for (int last; count > 1; count = last) {
-            for (int k = (last = 0) + 2; k <= count; k += 2) {
-                int hi = run[k], mi = run[k - 1];
-                for (int i = run[k - 2], p = i, q = mi; i < hi; ++i) {
-                    if (q >= hi || p < mi && a[p + ao] <= a[q + ao]) {
-                        b[i + bo] = a[p++ + ao];
-                    } else {
-                        b[i + bo] = a[q++ + ao];
+
+            // Pointers
+            int lower = low; // The index of the last element of the left part
+            int upper = end; // The index of the first element of the right part
+
+            /*
+             * Partitioning with 2 pivots in case of different elements.
+             */
+            if (a[e1] < a[e2] && a[e2] < a[e3] && a[e3] < a[e4] && a[e4] < a[e5]) {
+
+                /*
+                 * Use the first and fifth of the five sorted elements as
+                 * the pivots. These values are inexpensive approximation
+                 * of tertiles. Note, that pivot1 < pivot2.
+                 */
+                int pivot1 = a[e1];
+                int pivot2 = a[e5];
+
+                /*
+                 * The first and the last elements to be sorted are moved
+                 * to the locations formerly occupied by the pivots. When
+                 * partitioning is completed, the pivots are swapped back
+                 * into their final positions, and excluded from the next
+                 * subsequent sorting.
+                 */
+                a[e1] = a[lower];
+                a[e5] = a[upper];
+
+                /*
+                 * Skip elements, which are less or greater than the pivots.
+                 */
+                while (a[++lower] < pivot1);
+                while (a[--upper] > pivot2);
+
+                /*
+                 * Backward 3-interval partitioning
+                 *
+                 *   left part                 central part          right part
+                 * +------------------------------------------------------------+
+                 * |  < pivot1  |   ?   |  pivot1 <= && <= pivot2  |  > pivot2  |
+                 * +------------------------------------------------------------+
+                 *             ^       ^                            ^
+                 *             |       |                            |
+                 *           lower     k                          upper
+                 *
+                 * Invariants:
+                 *
+                 *              all in (low, lower] < pivot1
+                 *    pivot1 <= all in (k, upper)  <= pivot2
+                 *              all in [upper, end) > pivot2
+                 *
+                 * Pointer k is the last index of ?-part
+                 */
+                for (int unused = --lower, k = ++upper; --k > lower; ) {
+                    int ak = a[k];
+
+                    if (ak < pivot1) { // Move a[k] to the left side
+                        while (lower < k) {
+                            if (a[++lower] >= pivot1) {
+                                if (a[lower] > pivot2) {
+                                    a[k] = a[--upper];
+                                    a[upper] = a[lower];
+                                } else {
+                                    a[k] = a[lower];
+                                }
+                                a[lower] = ak;
+                                break;
+                            }
+                        }
+                    } else if (ak > pivot2) { // Move a[k] to the right side
+                        a[k] = a[--upper];
+                        a[upper] = ak;
                     }
                 }
-                run[++last] = hi;
+
+                /*
+                 * Swap the pivots into their final positions.
+                 */
+                a[low] = a[lower]; a[lower] = pivot1;
+                a[end] = a[upper]; a[upper] = pivot2;
+
+                /*
+                 * Sort non-left parts recursively (possibly in parallel),
+                 * excluding known pivots.
+                 */
+                if (size > MIN_PARALLEL_SORT_SIZE && sorter != null) {
+                    sorter.forkSorter(bits | 1, lower + 1, upper);
+                    sorter.forkSorter(bits | 1, upper + 1, high);
+                } else {
+                    sort(sorter, a, bits | 1, lower + 1, upper);
+                    sort(sorter, a, bits | 1, upper + 1, high);
+                }
+
+            } else { // Use single pivot in case of many equal elements
+
+                /*
+                 * Use the third of the five sorted elements as the pivot.
+                 * This value is inexpensive approximation of the median.
+                 */
+                int pivot = a[e3];
+
+                /*
+                 * The first element to be sorted is moved to the
+                 * location formerly occupied by the pivot. After
+                 * completion of partitioning the pivot is swapped
+                 * back into its final position, and excluded from
+                 * the next subsequent sorting.
+                 */
+                a[e3] = a[lower];
+
+                /*
+                 * Traditional 3-way (Dutch National Flag) partitioning
+                 *
+                 *   left part                 central part    right part
+                 * +------------------------------------------------------+
+                 * |   < pivot   |     ?     |   == pivot   |   > pivot   |
+                 * +------------------------------------------------------+
+                 *              ^           ^                ^
+                 *              |           |                |
+                 *            lower         k              upper
+                 *
+                 * Invariants:
+                 *
+                 *   all in (low, lower] < pivot
+                 *   all in (k, upper)  == pivot
+                 *   all in [upper, end] > pivot
+                 *
+                 * Pointer k is the last index of ?-part
+                 */
+                for (int k = ++upper; --k > lower; ) {
+                    int ak = a[k];
+
+                    if (ak != pivot) {
+                        a[k] = pivot;
+
+                        if (ak < pivot) { // Move a[k] to the left side
+                            while (a[++lower] < pivot);
+
+                            if (a[lower] > pivot) {
+                                a[--upper] = a[lower];
+                            }
+                            a[lower] = ak;
+                        } else { // ak > pivot - Move a[k] to the right side
+                            a[--upper] = ak;
+                        }
+                    }
+                }
+
+                /*
+                 * Swap the pivot into its final position.
+                 */
+                a[low] = a[lower]; a[lower] = pivot;
+
+                /*
+                 * Sort the right part (possibly in parallel), excluding
+                 * known pivot. All elements from the central part are
+                 * equal and therefore already sorted.
+                 */
+                if (size > MIN_PARALLEL_SORT_SIZE && sorter != null) {
+                    sorter.forkSorter(bits | 1, upper, high);
+                } else {
+                    sort(sorter, a, bits | 1, upper, high);
+                }
             }
-            if ((count & 1) != 0) {
-                for (int i = right, lo = run[count - 1]; --i >= lo;
-                    b[i + bo] = a[i + ao]
-                );
-                run[++last] = right;
-            }
-            int[] t = a; a = b; b = t;
-            int o = ao; ao = bo; bo = o;
+            high = lower; // Iterate along the left part
         }
     }
 
     /**
-     * Sorts the specified range of the array by Dual-Pivot Quicksort.
+     * Sorts the specified range of the array using mixed insertion sort.
+     *
+     * Mixed insertion sort is combination of simple insertion sort,
+     * pin insertion sort and pair insertion sort.
+     *
+     * In the context of Dual-Pivot Quicksort, the pivot element
+     * from the left part plays the role of sentinel, because it
+     * is less than any elements from the given part. Therefore,
+     * expensive check of the left range can be skipped on each
+     * iteration unless it is the leftmost call.
      *
      * @param a the array to be sorted
-     * @param left the index of the first element, inclusive, to be sorted
-     * @param right the index of the last element, inclusive, to be sorted
-     * @param leftmost indicates if this part is the leftmost in the range
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param end the index of the last element for simple insertion sort
+     * @param high the index of the last element, exclusive, to be sorted
      */
-    private static void sort(int[] a, int left, int right, boolean leftmost) {
-        int length = right - left + 1;
-
-        // Use insertion sort on tiny arrays
-        if (length < INSERTION_SORT_THRESHOLD) {
-            if (leftmost) {
-                /*
-                 * Traditional (without sentinel) insertion sort,
-                 * optimized for server VM, is used in case of
-                 * the leftmost part.
-                 */
-                for (int i = left, j = i; i < right; j = ++i) {
-                    int ai = a[i + 1];
-                    while (ai < a[j]) {
-                        a[j + 1] = a[j];
-                        if (j-- == left) {
-                            break;
-                        }
-                    }
-                    a[j + 1] = ai;
-                }
-            } else {
-                /*
-                 * Skip the longest ascending sequence.
-                 */
-                do {
-                    if (left >= right) {
-                        return;
-                    }
-                } while (a[++left] >= a[left - 1]);
-
-                /*
-                 * Every element from adjoining part plays the role
-                 * of sentinel, therefore this allows us to avoid the
-                 * left range check on each iteration. Moreover, we use
-                 * the more optimized algorithm, so called pair insertion
-                 * sort, which is faster (in the context of Quicksort)
-                 * than traditional implementation of insertion sort.
-                 */
-                for (int k = left; ++left <= right; k = ++left) {
-                    int a1 = a[k], a2 = a[left];
-
-                    if (a1 < a2) {
-                        a2 = a1; a1 = a[left];
-                    }
-                    while (a1 < a[--k]) {
-                        a[k + 2] = a[k];
-                    }
-                    a[++k + 1] = a1;
-
-                    while (a2 < a[--k]) {
-                        a[k + 1] = a[k];
-                    }
-                    a[k + 1] = a2;
-                }
-                int last = a[right];
-
-                while (last < a[--right]) {
-                    a[right + 1] = a[right];
-                }
-                a[right + 1] = last;
-            }
-            return;
-        }
-
-        // Inexpensive approximation of length / 7
-        int seventh = (length >> 3) + (length >> 6) + 1;
-
-        /*
-         * Sort five evenly spaced elements around (and including) the
-         * center element in the range. These elements will be used for
-         * pivot selection as described below. The choice for spacing
-         * these elements was empirically determined to work well on
-         * a wide variety of inputs.
-         */
-        int e3 = (left + right) >>> 1; // The midpoint
-        int e2 = e3 - seventh;
-        int e1 = e2 - seventh;
-        int e4 = e3 + seventh;
-        int e5 = e4 + seventh;
-
-        // Sort these elements using insertion sort
-        if (a[e2] < a[e1]) { int t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
-
-        if (a[e3] < a[e2]) { int t = a[e3]; a[e3] = a[e2]; a[e2] = t;
-            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
-        }
-        if (a[e4] < a[e3]) { int t = a[e4]; a[e4] = a[e3]; a[e3] = t;
-            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
-                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
-            }
-        }
-        if (a[e5] < a[e4]) { int t = a[e5]; a[e5] = a[e4]; a[e4] = t;
-            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
-                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
-                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
-                }
-            }
-        }
-
-        // Pointers
-        int less  = left;  // The index of the first element of center part
-        int great = right; // The index before the first element of right part
-
-        if (a[e1] != a[e2] && a[e2] != a[e3] && a[e3] != a[e4] && a[e4] != a[e5]) {
-            /*
-             * Use the second and fourth of the five sorted elements as pivots.
-             * These values are inexpensive approximations of the first and
-             * second terciles of the array. Note that pivot1 <= pivot2.
-             */
-            int pivot1 = a[e2];
-            int pivot2 = a[e4];
+    private static void mixedInsertionSort(int[] a, int low, int end, int high) {
+        if (end == high) {
 
             /*
-             * The first and the last elements to be sorted are moved to the
-             * locations formerly occupied by the pivots. When partitioning
-             * is complete, the pivots are swapped back into their final
-             * positions, and excluded from subsequent sorting.
+             * Invoke simple insertion sort on tiny array.
              */
-            a[e2] = a[left];
-            a[e4] = a[right];
-
-            /*
-             * Skip elements, which are less or greater than pivot values.
-             */
-            while (a[++less] < pivot1);
-            while (a[--great] > pivot2);
+            for (int i; ++low < end; ) {
+                int ai = a[i = low];
+
+                while (ai < a[--i]) {
+                    a[i + 1] = a[i];
+                }
+                a[i + 1] = ai;
+            }
+        } else {
 
             /*
-             * Partitioning:
-             *
-             *   left part           center part                   right part
-             * +--------------------------------------------------------------+
-             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
-             * +--------------------------------------------------------------+
-             *               ^                          ^       ^
-             *               |                          |       |
-             *              less                        k     great
-             *
-             * Invariants:
-             *
-             *              all in (left, less)   < pivot1
-             *    pivot1 <= all in [less, k)     <= pivot2
-             *              all in (great, right) > pivot2
+             * Start with pin insertion sort on small part.
              *
-             * Pointer k is the first index of ?-part.
-             */
-            outer:
-            for (int k = less - 1; ++k <= great; ) {
-                int ak = a[k];
-                if (ak < pivot1) { // Move a[k] to left part
-                    a[k] = a[less];
-                    /*
-                     * Here and below we use "a[i] = b; i++;" instead
-                     * of "a[i++] = b;" due to performance issue.
-                     */
-                    a[less] = ak;
-                    ++less;
-                } else if (ak > pivot2) { // Move a[k] to right part
-                    while (a[great] > pivot2) {
-                        if (great-- == k) {
-                            break outer;
-                        }
-                    }
-                    if (a[great] < pivot1) { // a[great] <= pivot2
-                        a[k] = a[less];
-                        a[less] = a[great];
-                        ++less;
-                    } else { // pivot1 <= a[great] <= pivot2
-                        a[k] = a[great];
-                    }
-                    /*
-                     * Here and below we use "a[i] = b; i--;" instead
-                     * of "a[i--] = b;" due to performance issue.
-                     */
-                    a[great] = ak;
-                    --great;
-                }
-            }
-
-            // Swap pivots into their final positions
-            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
-            a[right] = a[great + 1]; a[great + 1] = pivot2;
-
-            // Sort left and right parts recursively, excluding known pivots
-            sort(a, left, less - 2, leftmost);
-            sort(a, great + 2, right, false);
-
-            /*
-             * If center part is too large (comprises > 4/7 of the array),
-             * swap internal pivot values to ends.
+             * Pin insertion sort is extended simple insertion sort.
+             * The main idea of this sort is to put elements larger
+             * than an element called pin to the end of array (the
+             * proper area for such elements). It avoids expensive
+             * movements of these elements through the whole array.
              */
-            if (less < e1 && e5 < great) {
-                /*
-                 * Skip elements, which are equal to pivot values.
-                 */
-                while (a[less] == pivot1) {
-                    ++less;
-                }
-
-                while (a[great] == pivot2) {
-                    --great;
-                }
-
-                /*
-                 * Partitioning:
-                 *
-                 *   left part         center part                  right part
-                 * +----------------------------------------------------------+
-                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
-                 * +----------------------------------------------------------+
-                 *              ^                        ^       ^
-                 *              |                        |       |
-                 *             less                      k     great
-                 *
-                 * Invariants:
-                 *
-                 *              all in (*,  less) == pivot1
-                 *     pivot1 < all in [less,  k)  < pivot2
-                 *              all in (great, *) == pivot2
-                 *
-                 * Pointer k is the first index of ?-part.
-                 */
-                outer:
-                for (int k = less - 1; ++k <= great; ) {
-                    int ak = a[k];
-                    if (ak == pivot1) { // Move a[k] to left part
-                        a[k] = a[less];
-                        a[less] = ak;
-                        ++less;
-                    } else if (ak == pivot2) { // Move a[k] to right part
-                        while (a[great] == pivot2) {
-                            if (great-- == k) {
-                                break outer;
-                            }
-                        }
-                        if (a[great] == pivot1) { // a[great] < pivot2
-                            a[k] = a[less];
-                            /*
-                             * Even though a[great] equals to pivot1, the
-                             * assignment a[less] = pivot1 may be incorrect,
-                             * if a[great] and pivot1 are floating-point zeros
-                             * of different signs. Therefore in float and
-                             * double sorting methods we have to use more
-                             * accurate assignment a[less] = a[great].
-                             */
-                            a[less] = pivot1;
-                            ++less;
-                        } else { // pivot1 < a[great] < pivot2
-                            a[k] = a[great];
-                        }
-                        a[great] = ak;
-                        --great;
+            int pin = a[end];
+
+            for (int i, p = high; ++low < end; ) {
+                int ai = a[i = low];
+
+                if (ai < a[i - 1]) { // Small element
+
+                    /*
+                     * Insert small element into sorted part.
+                     */
+                    a[i] = a[--i];
+
+                    while (ai < a[--i]) {
+                        a[i + 1] = a[i];
                     }
-                }
-            }
-
-            // Sort center part recursively
-            sort(a, less, great, false);
-
-        } else { // Partitioning with one pivot
-            /*
-             * Use the third of the five sorted elements as pivot.
-             * This value is inexpensive approximation of the median.
-             */
-            int pivot = a[e3];
-
-            /*
-             * Partitioning degenerates to the traditional 3-way
-             * (or "Dutch National Flag") schema:
-             *
-             *   left part    center part              right part
-             * +-------------------------------------------------+
-             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
-             * +-------------------------------------------------+
-             *              ^              ^        ^
-             *              |              |        |
-             *             less            k      great
-             *
-             * Invariants:
-             *
-             *   all in (left, less)   < pivot
-             *   all in [less, k)     == pivot
-             *   all in (great, right) > pivot
-             *
-             * Pointer k is the first index of ?-part.
-             */
-            for (int k = less; k <= great; ++k) {
-                if (a[k] == pivot) {
-                    continue;
-                }
-                int ak = a[k];
-                if (ak < pivot) { // Move a[k] to left part
-                    a[k] = a[less];
-                    a[less] = ak;
-                    ++less;
-                } else { // a[k] > pivot - Move a[k] to right part
-                    while (a[great] > pivot) {
-                        --great;
+                    a[i + 1] = ai;
+
+                } else if (p > i && ai > pin) { // Large element
+
+                    /*
+                     * Find element smaller than pin.
+                     */
+                    while (a[--p] > pin);
+
+                    /*
+                     * Swap it with large element.
+                     */
+                    if (p > i) {
+                        ai = a[p];
+                        a[p] = a[i];
                     }
-                    if (a[great] < pivot) { // a[great] <= pivot
-                        a[k] = a[less];
-                        a[less] = a[great];
-                        ++less;
-                    } else { // a[great] == pivot
-                        /*
-                         * Even though a[great] equals to pivot, the
-                         * assignment a[k] = pivot may be incorrect,
-                         * if a[great] and pivot are floating-point
-                         * zeros of different signs. Therefore in float
-                         * and double sorting methods we have to use
-                         * more accurate assignment a[k] = a[great].
-                         */
-                        a[k] = pivot;
+
+                    /*
+                     * Insert small element into sorted part.
+                     */
+                    while (ai < a[--i]) {
+                        a[i + 1] = a[i];
                     }
-                    a[great] = ak;
-                    --great;
+                    a[i + 1] = ai;
                 }
             }
 
             /*
-             * Sort left and right parts recursively.
-             * All elements from center part are equal
-             * and, therefore, already sorted.
+             * Continue with pair insertion sort on remain part.
              */
-            sort(a, left, less - 1, leftmost);
-            sort(a, great + 1, right, false);
+            for (int i; low < high; ++low) {
+                int a1 = a[i = low], a2 = a[++low];
+
+                /*
+                 * Insert two elements per iteration: at first, insert the
+                 * larger element and then insert the smaller element, but
+                 * from the position where the larger element was inserted.
+                 */
+                if (a1 > a2) {
+
+                    while (a1 < a[--i]) {
+                        a[i + 2] = a[i];
+                    }
+                    a[++i + 1] = a1;
+
+                    while (a2 < a[--i]) {
+                        a[i + 1] = a[i];
+                    }
+                    a[i + 1] = a2;
+
+                } else if (a1 < a[i - 1]) {
+
+                    while (a2 < a[--i]) {
+                        a[i + 2] = a[i];
+                    }
+                    a[++i + 1] = a2;
+
+                    while (a1 < a[--i]) {
+                        a[i + 1] = a[i];
+                    }
+                    a[i + 1] = a1;
+                }
+            }
+        }
+    }
+
+    /**
+     * Sorts the specified range of the array using insertion sort.
+     *
+     * @param a the array to be sorted
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
+     */
+    private static void insertionSort(int[] a, int low, int high) {
+        for (int i, k = low; ++k < high; ) {
+            int ai = a[i = k];
+
+            if (ai < a[i - 1]) {
+                while (--i >= low && ai < a[i]) {
+                    a[i + 1] = a[i];
+                }
+                a[i + 1] = ai;
+            }
+        }
+    }
+
+    /**
+     * Sorts the specified range of the array using heap sort.
+     *
+     * @param a the array to be sorted
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
+     */
+    private static void heapSort(int[] a, int low, int high) {
+        for (int k = (low + high) >>> 1; k > low; ) {
+            pushDown(a, --k, a[k], low, high);
+        }
+        while (--high > low) {
+            int max = a[low];
+            pushDown(a, low, a[high], low, high);
+            a[high] = max;
         }
     }
 
     /**
-     * Sorts the specified range of the array using the given
-     * workspace array slice if possible for merging
+     * Pushes specified element down during heap sort.
      *
-     * @param a the array to be sorted
-     * @param left the index of the first element, inclusive, to be sorted
-     * @param right the index of the last element, inclusive, to be sorted
-     * @param work a workspace array (slice)
-     * @param workBase origin of usable space in work array
-     * @param workLen usable size of work array
+     * @param a the given array
+     * @param p the start index
+     * @param value the given element
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
      */
-    static void sort(long[] a, int left, int right,
-                     long[] work, int workBase, int workLen) {
-        // Use Quicksort on small arrays
-        if (right - left < QUICKSORT_THRESHOLD) {
-            sort(a, left, right, true);
-            return;
-        }
-
-        /*
-         * Index run[i] is the start of i-th run
-         * (ascending or descending sequence).
-         */
-        int[] run = new int[MAX_RUN_COUNT + 1];
-        int count = 0; run[0] = left;
-
-        // Check if the array is nearly sorted
-        for (int k = left; k < right; run[count] = k) {
-            // Equal items in the beginning of the sequence
-            while (k < right && a[k] == a[k + 1])
-                k++;
-            if (k == right) break;  // Sequence finishes with equal items
-            if (a[k] < a[k + 1]) { // ascending
-                while (++k <= right && a[k - 1] <= a[k]);
-            } else if (a[k] > a[k + 1]) { // descending
-                while (++k <= right && a[k - 1] >= a[k]);
-                // Transform into an ascending sequence
-                for (int lo = run[count] - 1, hi = k; ++lo < --hi; ) {
-                    long t = a[lo]; a[lo] = a[hi]; a[hi] = t;
-                }
+    private static void pushDown(int[] a, int p, int value, int low, int high) {
+        for (int k ;; a[p] = a[p = k]) {
+            k = (p << 1) - low + 2; // Index of the right child
+
+            if (k > high) {
+                break;
             }
-
-            // Merge a transformed descending sequence followed by an
-            // ascending sequence
-            if (run[count] > left && a[run[count]] >= a[run[count] - 1]) {
-                count--;
+            if (k == high || a[k] < a[k - 1]) {
+                --k;
             }
-
-            /*
-             * The array is not highly structured,
-             * use Quicksort instead of merge sort.
-             */
-            if (++count == MAX_RUN_COUNT) {
-                sort(a, left, right, true);
-                return;
+            if (a[k] <= value) {
+                break;
             }
         }
-
-        // These invariants should hold true:
-        //    run[0] = 0
-        //    run[<last>] = right + 1; (terminator)
-
-        if (count == 0) {
-            // A single equal run
-            return;
-        } else if (count == 1 && run[count] > right) {
-            // Either a single ascending or a transformed descending run.
-            // Always check that a final run is a proper terminator, otherwise
-            // we have an unterminated trailing run, to handle downstream.
-            return;
-        }
-        right++;
-        if (run[count] < right) {
-            // Corner case: the final run is not a terminator. This may happen
-            // if a final run is an equals run, or there is a single-element run
-            // at the end. Fix up by adding a proper terminator at the end.
-            // Note that we terminate with (right + 1), incremented earlier.
-            run[++count] = right;
-        }
-
-        // Determine alternation base for merge
-        byte odd = 0;
-        for (int n = 1; (n <<= 1) < count; odd ^= 1);
-
-        // Use or create temporary array b for merging
-        long[] b;                 // temp array; alternates with a
-        int ao, bo;              // array offsets from 'left'
-        int blen = right - left; // space needed for b
-        if (work == null || workLen < blen || workBase + blen > work.length) {
-            work = new long[blen];
-            workBase = 0;
-        }
-        if (odd == 0) {
-            System.arraycopy(a, left, work, workBase, blen);
-            b = a;
-            bo = 0;
-            a = work;
-            ao = workBase - left;
-        } else {
-            b = work;
-            ao = 0;
-            bo = workBase - left;
-        }
-
-        // Merging
-        for (int last; count > 1; count = last) {
-            for (int k = (last = 0) + 2; k <= count; k += 2) {
-                int hi = run[k], mi = run[k - 1];
-                for (int i = run[k - 2], p = i, q = mi; i < hi; ++i) {
-                    if (q >= hi || p < mi && a[p + ao] <= a[q + ao]) {
-                        b[i + bo] = a[p++ + ao];
-                    } else {
-                        b[i + bo] = a[q++ + ao];
-                    }
-                }
-                run[++last] = hi;
-            }
-            if ((count & 1) != 0) {
-                for (int i = right, lo = run[count - 1]; --i >= lo;
-                    b[i + bo] = a[i + ao]
-                );
-                run[++last] = right;
-            }
-            long[] t = a; a = b; b = t;
-            int o = ao; ao = bo; bo = o;
-        }
+        a[p] = value;
     }
 
     /**
-     * Sorts the specified range of the array by Dual-Pivot Quicksort.
+     * Tries to sort the specified range of the array.
      *
+     * @param sorter parallel context
      * @param a the array to be sorted
-     * @param left the index of the first element, inclusive, to be sorted
-     * @param right the index of the last element, inclusive, to be sorted
-     * @param leftmost indicates if this part is the leftmost in the range
+     * @param low the index of the first element to be sorted
+     * @param size the array size
+     * @return true if finally sorted, false otherwise
      */
-    private static void sort(long[] a, int left, int right, boolean leftmost) {
-        int length = right - left + 1;
-
-        // Use insertion sort on tiny arrays
-        if (length < INSERTION_SORT_THRESHOLD) {
-            if (leftmost) {
-                /*
-                 * Traditional (without sentinel) insertion sort,
-                 * optimized for server VM, is used in case of
-                 * the leftmost part.
-                 */
-                for (int i = left, j = i; i < right; j = ++i) {
-                    long ai = a[i + 1];
-                    while (ai < a[j]) {
-                        a[j + 1] = a[j];
-                        if (j-- == left) {
-                            break;
-                        }
-                    }
-                    a[j + 1] = ai;
-                }
-            } else {
-                /*
-                 * Skip the longest ascending sequence.
-                 */
-                do {
-                    if (left >= right) {
-                        return;
-                    }
-                } while (a[++left] >= a[left - 1]);
-
-                /*
-                 * Every element from adjoining part plays the role
-                 * of sentinel, therefore this allows us to avoid the
-                 * left range check on each iteration. Moreover, we use
-                 * the more optimized algorithm, so called pair insertion
-                 * sort, which is faster (in the context of Quicksort)
-                 * than traditional implementation of insertion sort.
-                 */
-                for (int k = left; ++left <= right; k = ++left) {
-                    long a1 = a[k], a2 = a[left];
-
-                    if (a1 < a2) {
-                        a2 = a1; a1 = a[left];
-                    }
-                    while (a1 < a[--k]) {
-                        a[k + 2] = a[k];
-                    }
-                    a[++k + 1] = a1;
-
-                    while (a2 < a[--k]) {
-                        a[k + 1] = a[k];
-                    }
-                    a[k + 1] = a2;
-                }
-                long last = a[right];
-
-                while (last < a[--right]) {
-                    a[right + 1] = a[right];
-                }
-                a[right + 1] = last;
-            }
-            return;
-        }
-
-        // Inexpensive approximation of length / 7
-        int seventh = (length >> 3) + (length >> 6) + 1;
+    private static boolean tryMergeRuns(Sorter sorter, int[] a, int low, int size) {
 
         /*
-         * Sort five evenly spaced elements around (and including) the
-         * center element in the range. These elements will be used for
-         * pivot selection as described below. The choice for spacing
-         * these elements was empirically determined to work well on
-         * a wide variety of inputs.
+         * The run array is constructed only if initial runs are
+         * long enough to continue, run[i] then holds start index
+         * of the i-th sequence of elements in non-descending order.
          */
-        int e3 = (left + right) >>> 1; // The midpoint
-        int e2 = e3 - seventh;
-        int e1 = e2 - seventh;
-        int e4 = e3 + seventh;
-        int e5 = e4 + seventh;
-
-        // Sort these elements using insertion sort
-        if (a[e2] < a[e1]) { long t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
-
-        if (a[e3] < a[e2]) { long t = a[e3]; a[e3] = a[e2]; a[e2] = t;
-            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
-        }
-        if (a[e4] < a[e3]) { long t = a[e4]; a[e4] = a[e3]; a[e3] = t;
-            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
-                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
-            }
-        }
-        if (a[e5] < a[e4]) { long t = a[e5]; a[e5] = a[e4]; a[e4] = t;
-            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
-                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
-                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
-                }
-            }
-        }
-
-        // Pointers
-        int less  = left;  // The index of the first element of center part
-        int great = right; // The index before the first element of right part
-
-        if (a[e1] != a[e2] && a[e2] != a[e3] && a[e3] != a[e4] && a[e4] != a[e5]) {
-            /*
-             * Use the second and fourth of the five sorted elements as pivots.
-             * These values are inexpensive approximations of the first and
-             * second terciles of the array. Note that pivot1 <= pivot2.
-             */
-            long pivot1 = a[e2];
-            long pivot2 = a[e4];
-
-            /*
-             * The first and the last elements to be sorted are moved to the
-             * locations formerly occupied by the pivots. When partitioning
-             * is complete, the pivots are swapped back into their final
-             * positions, and excluded from subsequent sorting.
-             */
-            a[e2] = a[left];
-            a[e4] = a[right];
-
-            /*
-             * Skip elements, which are less or greater than pivot values.
-             */
-            while (a[++less] < pivot1);
-            while (a[--great] > pivot2);
+        int[] run = null;
+        int high = low + size;
+        int count = 1, last = low;
+
+        /*
+         * Identify all possible runs.
+         */
+        for (int k = low + 1; k < high; ) {
 
             /*
-             * Partitioning:
-             *
-             *   left part           center part                   right part
-             * +--------------------------------------------------------------+
-             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
-             * +--------------------------------------------------------------+
-             *               ^                          ^       ^
-             *               |                          |       |
-             *              less                        k     great
-             *
-             * Invariants:
-             *
-             *              all in (left, less)   < pivot1
-             *    pivot1 <= all in [less, k)     <= pivot2
-             *              all in (great, right) > pivot2
-             *
-             * Pointer k is the first index of ?-part.
+             * Find the end index of the current run.
              */
-            outer:
-            for (int k = less - 1; ++k <= great; ) {
-                long ak = a[k];
-                if (ak < pivot1) { // Move a[k] to left part
-                    a[k] = a[less];
-                    /*
-                     * Here and below we use "a[i] = b; i++;" instead
-                     * of "a[i++] = b;" due to performance issue.
-                     */
-                    a[less] = ak;
-                    ++less;
-                } else if (ak > pivot2) { // Move a[k] to right part
-                    while (a[great] > pivot2) {
-                        if (great-- == k) {
-                            break outer;
-                        }
-                    }
-                    if (a[great] < pivot1) { // a[great] <= pivot2
-                        a[k] = a[less];
-                        a[less] = a[great];
-                        ++less;
-                    } else { // pivot1 <= a[great] <= pivot2
-                        a[k] = a[great];
-                    }
-                    /*
-                     * Here and below we use "a[i] = b; i--;" instead
-                     * of "a[i--] = b;" due to performance issue.
-                     */
-                    a[great] = ak;
-                    --great;
-                }
-            }
-
-            // Swap pivots into their final positions
-            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
-            a[right] = a[great + 1]; a[great + 1] = pivot2;
-
-            // Sort left and right parts recursively, excluding known pivots
-            sort(a, left, less - 2, leftmost);
-            sort(a, great + 2, right, false);
-
-            /*
-             * If center part is too large (comprises > 4/7 of the array),
-             * swap internal pivot values to ends.
-             */
-            if (less < e1 && e5 < great) {
-                /*
-                 * Skip elements, which are equal to pivot values.
-                 */
-                while (a[less] == pivot1) {
-                    ++less;
-                }
-
-                while (a[great] == pivot2) {
-                    --great;
+            if (a[k - 1] < a[k]) {
+
+                // Identify ascending sequence
+                while (++k < high && a[k - 1] <= a[k]);
+
+            } else if (a[k - 1] > a[k]) {
+
+                // Identify descending sequence
+                while (++k < high && a[k - 1] >= a[k]);
+
+                // Reverse into ascending order
+                for (int i = last - 1, j = k; ++i < --j && a[i] > a[j]; ) {
+                    int ai = a[i]; a[i] = a[j]; a[j] = ai;
                 }
-
-                /*
-                 * Partitioning:
-                 *
-                 *   left part         center part                  right part
-                 * +----------------------------------------------------------+
-                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
-                 * +----------------------------------------------------------+
-                 *              ^                        ^       ^
-                 *              |                        |       |
-                 *             less                      k     great
-                 *
-                 * Invariants:
-                 *
-                 *              all in (*,  less) == pivot1
-                 *     pivot1 < all in [less,  k)  < pivot2
-                 *              all in (great, *) == pivot2
-                 *
-                 * Pointer k is the first index of ?-part.
-                 */
-                outer:
-                for (int k = less - 1; ++k <= great; ) {
-                    long ak = a[k];
-                    if (ak == pivot1) { // Move a[k] to left part
-                        a[k] = a[less];
-                        a[less] = ak;
-                        ++less;
-                    } else if (ak == pivot2) { // Move a[k] to right part
-                        while (a[great] == pivot2) {
-                            if (great-- == k) {
-                                break outer;
-                            }
-                        }
-                        if (a[great] == pivot1) { // a[great] < pivot2
-                            a[k] = a[less];
-                            /*
-                             * Even though a[great] equals to pivot1, the
-                             * assignment a[less] = pivot1 may be incorrect,
-                             * if a[great] and pivot1 are floating-point zeros
-                             * of different signs. Therefore in float and
-                             * double sorting methods we have to use more
-                             * accurate assignment a[less] = a[great].
-                             */
-                            a[less] = pivot1;
-                            ++less;
-                        } else { // pivot1 < a[great] < pivot2
-                            a[k] = a[great];
-                        }
-                        a[great] = ak;
-                        --great;
-                    }
-                }
-            }
-
-            // Sort center part recursively
-            sort(a, less, great, false);
-
-        } else { // Partitioning with one pivot
-            /*
-             * Use the third of the five sorted elements as pivot.
-             * This value is inexpensive approximation of the median.
-             */
-            long pivot = a[e3];
-
-            /*
-             * Partitioning degenerates to the traditional 3-way
-             * (or "Dutch National Flag") schema:
-             *
-             *   left part    center part              right part
-             * +-------------------------------------------------+
-             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
-             * +-------------------------------------------------+
-             *              ^              ^        ^
-             *              |              |        |
-             *             less            k      great
-             *
-             * Invariants:
-             *
-             *   all in (left, less)   < pivot
-             *   all in [less, k)     == pivot
-             *   all in (great, right) > pivot
-             *
-             * Pointer k is the first index of ?-part.
-             */
-            for (int k = less; k <= great; ++k) {
-                if (a[k] == pivot) {
+            } else { // Identify constant sequence
+                for (int ak = a[k]; ++k < high && ak == a[k]; );
+
+                if (k < high) {
                     continue;
                 }
-                long ak = a[k];
-                if (ak < pivot) { // Move a[k] to left part
-                    a[k] = a[less];
-                    a[less] = ak;
-                    ++less;
-                } else { // a[k] > pivot - Move a[k] to right part
-                    while (a[great] > pivot) {
-                        --great;
-                    }
-                    if (a[great] < pivot) { // a[great] <= pivot
-                        a[k] = a[less];
-                        a[less] = a[great];
-                        ++less;
-                    } else { // a[great] == pivot
-                        /*
-                         * Even though a[great] equals to pivot, the
-                         * assignment a[k] = pivot may be incorrect,
-                         * if a[great] and pivot are floating-point
-                         * zeros of different signs. Therefore in float
-                         * and double sorting methods we have to use
-                         * more accurate assignment a[k] = a[great].
-                         */
-                        a[k] = pivot;
-                    }
-                    a[great] = ak;
-                    --great;
-                }
             }
 
             /*
-             * Sort left and right parts recursively.
-             * All elements from center part are equal
-             * and, therefore, already sorted.
+             * Check special cases.
              */
-            sort(a, left, less - 1, leftmost);
-            sort(a, great + 1, right, false);
+            if (run == null) {
+                if (k == high) {
+
+                    /*
+                     * The array is monotonous sequence,
+                     * and therefore already sorted.
+                     */
+                    return true;
+                }
+
+                if (k - low < MIN_FIRST_RUN_SIZE) {
+
+                    /*
+                     * The first run is too small
+                     * to proceed with scanning.
+                     */
+                    return false;
+                }
+
+                run = new int[((size >> 10) | 0x7F) & 0x3FF];
+                run[0] = low;
+
+            } else if (a[last - 1] > a[last]) {
+
+                if (count > (k - low) >> MIN_FIRST_RUNS_FACTOR) {
+
+                    /*
+                     * The first runs are not long
+                     * enough to continue scanning.
+                     */
+                    return false;
+                }
+
+                if (++count == MAX_RUN_CAPACITY) {
+
+                    /*
+                     * Array is not highly structured.
+                     */
+                    return false;
+                }
+
+                if (count == run.length) {
+
+                    /*
+                     * Increase capacity of index array.
+                     */
+                    run = Arrays.copyOf(run, count << 1);
+                }
+            }
+            run[count] = (last = k);
+        }
+
+        /*
+         * Merge runs of highly structured array.
+         */
+        if (count > 1) {
+            int[] b; int offset = low;
+
+            if (sorter == null || (b = (int[]) sorter.b) == null) {
+                b = new int[size];
+            } else {
+                offset = sorter.offset;
+            }
+            mergeRuns(a, b, offset, 1, sorter != null, run, 0, count);
+        }
+        return true;
+    }
+
+    /**
+     * Merges the specified runs.
+     *
+     * @param a the source array
+     * @param b the temporary buffer used in merging
+     * @param offset the start index in the source, inclusive
+     * @param aim specifies merging: to source ( > 0), buffer ( < 0) or any ( == 0)
+     * @param parallel indicates whether merging is performed in parallel
+     * @param run the start indexes of the runs, inclusive
+     * @param lo the start index of the first run, inclusive
+     * @param hi the start index of the last run, inclusive
+     * @return the destination where runs are merged
+     */
+    private static int[] mergeRuns(int[] a, int[] b, int offset,
+            int aim, boolean parallel, int[] run, int lo, int hi) {
+
+        if (hi - lo == 1) {
+            if (aim >= 0) {
+                return a;
+            }
+            for (int i = run[hi], j = i - offset, low = run[lo]; i > low;
+                b[--j] = a[--i]
+            );
+            return b;
+        }
+
+        /*
+         * Split into approximately equal parts.
+         */
+        int mi = lo, rmi = (run[lo] + run[hi]) >>> 1;
+        while (run[++mi + 1] <= rmi);
+
+        /*
+         * Merge the left and right parts.
+         */
+        int[] a1, a2;
+
+        if (parallel && hi - lo > MIN_RUN_COUNT) {
+            RunMerger merger = new RunMerger(a, b, offset, 0, run, mi, hi).forkMe();
+            a1 = mergeRuns(a, b, offset, -aim, true, run, lo, mi);
+            a2 = (int[]) merger.getDestination();
+        } else {
+            a1 = mergeRuns(a, b, offset, -aim, false, run, lo, mi);
+            a2 = mergeRuns(a, b, offset,    0, false, run, mi, hi);
+        }
+
+        int[] dst = a1 == a ? b : a;
+
+        int k   = a1 == a ? run[lo] - offset : run[lo];
+        int lo1 = a1 == b ? run[lo] - offset : run[lo];
+        int hi1 = a1 == b ? run[mi] - offset : run[mi];
+        int lo2 = a2 == b ? run[mi] - offset : run[mi];
+        int hi2 = a2 == b ? run[hi] - offset : run[hi];
+
+        if (parallel) {
+            new Merger(null, dst, k, a1, lo1, hi1, a2, lo2, hi2).invoke();
+        } else {
+            mergeParts(null, dst, k, a1, lo1, hi1, a2, lo2, hi2);
+        }
+        return dst;
+    }
+
+    /**
+     * Merges the sorted parts.
+     *
+     * @param merger parallel context
+     * @param dst the destination where parts are merged
+     * @param k the start index of the destination, inclusive
+     * @param a1 the first part
+     * @param lo1 the start index of the first part, inclusive
+     * @param hi1 the end index of the first part, exclusive
+     * @param a2 the second part
+     * @param lo2 the start index of the second part, inclusive
+     * @param hi2 the end index of the second part, exclusive
+     */
+    private static void mergeParts(Merger merger, int[] dst, int k,
+            int[] a1, int lo1, int hi1, int[] a2, int lo2, int hi2) {
+
+        if (merger != null && a1 == a2) {
+
+            while (true) {
+
+                /*
+                 * The first part must be larger.
+                 */
+                if (hi1 - lo1 < hi2 - lo2) {
+                    int lo = lo1; lo1 = lo2; lo2 = lo;
+                    int hi = hi1; hi1 = hi2; hi2 = hi;
+                }
+
+                /*
+                 * Small parts will be merged sequentially.
+                 */
+                if (hi1 - lo1 < MIN_PARALLEL_MERGE_PARTS_SIZE) {
+                    break;
+                }
+
+                /*
+                 * Find the median of the larger part.
+                 */
+                int mi1 = (lo1 + hi1) >>> 1;
+                int key = a1[mi1];
+                int mi2 = hi2;
+
+                /*
+                 * Partition the smaller part.
+                 */
+                for (int loo = lo2; loo < mi2; ) {
+                    int t = (loo + mi2) >>> 1;
+
+                    if (key > a2[t]) {
+                        loo = t + 1;
+                    } else {
+                        mi2 = t;
+                    }
+                }
+
+                int d = mi2 - lo2 + mi1 - lo1;
+
+                /*
+                 * Merge the right sub-parts in parallel.
+                 */
+                merger.forkMerger(dst, k + d, a1, mi1, hi1, a2, mi2, hi2);
+
+                /*
+                 * Process the sub-left parts.
+                 */
+                hi1 = mi1;
+                hi2 = mi2;
+            }
+        }
+
+        /*
+         * Merge small parts sequentially.
+         */
+        while (lo1 < hi1 && lo2 < hi2) {
+            dst[k++] = a1[lo1] < a2[lo2] ? a1[lo1++] : a2[lo2++];
+        }
+        if (dst != a1 || k < lo1) {
+            while (lo1 < hi1) {
+                dst[k++] = a1[lo1++];
+            }
+        }
+        if (dst != a2 || k < lo2) {
+            while (lo2 < hi2) {
+                dst[k++] = a2[lo2++];
+            }
+        }
+    }
+
+// [long]
+
+    /**
+     * Sorts the specified range of the array using parallel merge
+     * sort and/or Dual-Pivot Quicksort.
+     *
+     * To balance the faster splitting and parallelism of merge sort
+     * with the faster element partitioning of Quicksort, ranges are
+     * subdivided in tiers such that, if there is enough parallelism,
+     * the four-way parallel merge is started, still ensuring enough
+     * parallelism to process the partitions.
+     *
+     * @param a the array to be sorted
+     * @param parallelism the parallelism level
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
+     */
+    static void sort(long[] a, int parallelism, int low, int high) {
+        int size = high - low;
+
+        if (parallelism > 1 && size > MIN_PARALLEL_SORT_SIZE) {
+            int depth = getDepth(parallelism, size >> 12);
+            long[] b = depth == 0 ? null : new long[size];
+            new Sorter(null, a, b, low, size, low, depth).invoke();
+        } else {
+            sort(null, a, 0, low, high);
         }
     }
 
     /**
-     * Sorts the specified range of the array using the given
-     * workspace array slice if possible for merging
+     * Sorts the specified array using the Dual-Pivot Quicksort and/or
+     * other sorts in special-cases, possibly with parallel partitions.
      *
-     * @param a the array to be sorted
-     * @param left the index of the first element, inclusive, to be sorted
-     * @param right the index of the last element, inclusive, to be sorted
-     * @param work a workspace array (slice)
-     * @param workBase origin of usable space in work array
-     * @param workLen usable size of work array
-     */
-    static void sort(short[] a, int left, int right,
-                     short[] work, int workBase, int workLen) {
-        // Use counting sort on large arrays
-        if (right - left > COUNTING_SORT_THRESHOLD_FOR_SHORT_OR_CHAR) {
-            int[] count = new int[NUM_SHORT_VALUES];
-
-            for (int i = left - 1; ++i <= right;
-                count[a[i] - Short.MIN_VALUE]++
-            );
-            for (int i = NUM_SHORT_VALUES, k = right + 1; k > left; ) {
-                while (count[--i] == 0);
-                short value = (short) (i + Short.MIN_VALUE);
-                int s = count[i];
-
-                do {
-                    a[--k] = value;
-                } while (--s > 0);
-            }
-        } else { // Use Dual-Pivot Quicksort on small arrays
-            doSort(a, left, right, work, workBase, workLen);
-        }
-    }
-
-    /** The number of distinct short values. */
-    private static final int NUM_SHORT_VALUES = 1 << 16;
-
-    /**
-     * Sorts the specified range of the array.
-     *
+     * @param sorter parallel context
      * @param a the array to be sorted
-     * @param left the index of the first element, inclusive, to be sorted
-     * @param right the index of the last element, inclusive, to be sorted
-     * @param work a workspace array (slice)
-     * @param workBase origin of usable space in work array
-     * @param workLen usable size of work array
+     * @param bits the combination of recursion depth and bit flag, where
+     *        the right bit "0" indicates that array is the leftmost part
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
      */
-    private static void doSort(short[] a, int left, int right,
-                               short[] work, int workBase, int workLen) {
-        // Use Quicksort on small arrays
-        if (right - left < QUICKSORT_THRESHOLD) {
-            sort(a, left, right, true);
-            return;
-        }
-
-        /*
-         * Index run[i] is the start of i-th run
-         * (ascending or descending sequence).
-         */
-        int[] run = new int[MAX_RUN_COUNT + 1];
-        int count = 0; run[0] = left;
-
-        // Check if the array is nearly sorted
-        for (int k = left; k < right; run[count] = k) {
-            // Equal items in the beginning of the sequence
-            while (k < right && a[k] == a[k + 1])
-                k++;
-            if (k == right) break;  // Sequence finishes with equal items
-            if (a[k] < a[k + 1]) { // ascending
-                while (++k <= right && a[k - 1] <= a[k]);
-            } else if (a[k] > a[k + 1]) { // descending
-                while (++k <= right && a[k - 1] >= a[k]);
-                // Transform into an ascending sequence
-                for (int lo = run[count] - 1, hi = k; ++lo < --hi; ) {
-                    short t = a[lo]; a[lo] = a[hi]; a[hi] = t;
-                }
+    static void sort(Sorter sorter, long[] a, int bits, int low, int high) {
+        while (true) {
+            int end = high - 1, size = high - low;
+
+            /*
+             * Run mixed insertion sort on small non-leftmost parts.
+             */
+            if (size < MAX_MIXED_INSERTION_SORT_SIZE + bits && (bits & 1) > 0) {
+                mixedInsertionSort(a, low, high - 3 * ((size >> 5) << 3), high);
+                return;
             }
 
-            // Merge a transformed descending sequence followed by an
-            // ascending sequence
-            if (run[count] > left && a[run[count]] >= a[run[count] - 1]) {
-                count--;
+            /*
+             * Invoke insertion sort on small leftmost part.
+             */
+            if (size < MAX_INSERTION_SORT_SIZE) {
+                insertionSort(a, low, high);
+                return;
+            }
+
+            /*
+             * Check if the whole array or large non-leftmost
+             * parts are nearly sorted and then merge runs.
+             */
+            if ((bits == 0 || size > MIN_TRY_MERGE_SIZE && (bits & 1) > 0)
+                    && tryMergeRuns(sorter, a, low, size)) {
+                return;
+            }
+
+            /*
+             * Switch to heap sort if execution
+             * time is becoming quadratic.
+             */
+            if ((bits += DELTA) > MAX_RECURSION_DEPTH) {
+                heapSort(a, low, high);
+                return;
             }
 
             /*
-             * The array is not highly structured,
-             * use Quicksort instead of merge sort.
+             * Use an inexpensive approximation of the golden ratio
+             * to select five sample elements and determine pivots.
+             */
+            int step = (size >> 3) * 3 + 3;
+
+            /*
+             * Five elements around (and including) the central element
+             * will be used for pivot selection as described below. The
+             * unequal choice of spacing these elements was empirically
+             * determined to work well on a wide variety of inputs.
              */
-            if (++count == MAX_RUN_COUNT) {
-                sort(a, left, right, true);
-                return;
+            int e1 = low + step;
+            int e5 = end - step;
+            int e3 = (e1 + e5) >>> 1;
+            int e2 = (e1 + e3) >>> 1;
+            int e4 = (e3 + e5) >>> 1;
+            long a3 = a[e3];
+
+            /*
+             * Sort these elements in place by the combination
+             * of 4-element sorting network and insertion sort.
+             *
+             *    5 ------o-----------o------------
+             *            |           |
+             *    4 ------|-----o-----o-----o------
+             *            |     |           |
+             *    2 ------o-----|-----o-----o------
+             *                  |     |
+             *    1 ------------o-----o------------
+             */
+            if (a[e5] < a[e2]) { long t = a[e5]; a[e5] = a[e2]; a[e2] = t; }
+            if (a[e4] < a[e1]) { long t = a[e4]; a[e4] = a[e1]; a[e1] = t; }
+            if (a[e5] < a[e4]) { long t = a[e5]; a[e5] = a[e4]; a[e4] = t; }
+            if (a[e2] < a[e1]) { long t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
+            if (a[e4] < a[e2]) { long t = a[e4]; a[e4] = a[e2]; a[e2] = t; }
+
+            if (a3 < a[e2]) {
+                if (a3 < a[e1]) {
+                    a[e3] = a[e2]; a[e2] = a[e1]; a[e1] = a3;
+                } else {
+                    a[e3] = a[e2]; a[e2] = a3;
+                }
+            } else if (a3 > a[e4]) {
+                if (a3 > a[e5]) {
+                    a[e3] = a[e4]; a[e4] = a[e5]; a[e5] = a3;
+                } else {
+                    a[e3] = a[e4]; a[e4] = a3;
+                }
             }
-        }
-
-        // These invariants should hold true:
-        //    run[0] = 0
-        //    run[<last>] = right + 1; (terminator)
-
-        if (count == 0) {
-            // A single equal run
-            return;
-        } else if (count == 1 && run[count] > right) {
-            // Either a single ascending or a transformed descending run.
-            // Always check that a final run is a proper terminator, otherwise
-            // we have an unterminated trailing run, to handle downstream.
-            return;
-        }
-        right++;
-        if (run[count] < right) {
-            // Corner case: the final run is not a terminator. This may happen
-            // if a final run is an equals run, or there is a single-element run
-            // at the end. Fix up by adding a proper terminator at the end.
-            // Note that we terminate with (right + 1), incremented earlier.
-            run[++count] = right;
-        }
-
-        // Determine alternation base for merge
-        byte odd = 0;
-        for (int n = 1; (n <<= 1) < count; odd ^= 1);
-
-        // Use or create temporary array b for merging
-        short[] b;                 // temp array; alternates with a
-        int ao, bo;              // array offsets from 'left'
-        int blen = right - left; // space needed for b
-        if (work == null || workLen < blen || workBase + blen > work.length) {
-            work = new short[blen];
-            workBase = 0;
-        }
-        if (odd == 0) {
-            System.arraycopy(a, left, work, workBase, blen);
-            b = a;
-            bo = 0;
-            a = work;
-            ao = workBase - left;
-        } else {
-            b = work;
-            ao = 0;
-            bo = workBase - left;
-        }
-
-        // Merging
-        for (int last; count > 1; count = last) {
-            for (int k = (last = 0) + 2; k <= count; k += 2) {
-                int hi = run[k], mi = run[k - 1];
-                for (int i = run[k - 2], p = i, q = mi; i < hi; ++i) {
-                    if (q >= hi || p < mi && a[p + ao] <= a[q + ao]) {
-                        b[i + bo] = a[p++ + ao];
-                    } else {
-                        b[i + bo] = a[q++ + ao];
+
+            // Pointers
+            int lower = low; // The index of the last element of the left part
+            int upper = end; // The index of the first element of the right part
+
+            /*
+             * Partitioning with 2 pivots in case of different elements.
+             */
+            if (a[e1] < a[e2] && a[e2] < a[e3] && a[e3] < a[e4] && a[e4] < a[e5]) {
+
+                /*
+                 * Use the first and fifth of the five sorted elements as
+                 * the pivots. These values are inexpensive approximation
+                 * of tertiles. Note, that pivot1 < pivot2.
+                 */
+                long pivot1 = a[e1];
+                long pivot2 = a[e5];
+
+                /*
+                 * The first and the last elements to be sorted are moved
+                 * to the locations formerly occupied by the pivots. When
+                 * partitioning is completed, the pivots are swapped back
+                 * into their final positions, and excluded from the next
+                 * subsequent sorting.
+                 */
+                a[e1] = a[lower];
+                a[e5] = a[upper];
+
+                /*
+                 * Skip elements, which are less or greater than the pivots.
+                 */
+                while (a[++lower] < pivot1);
+                while (a[--upper] > pivot2);
+
+                /*
+                 * Backward 3-interval partitioning
+                 *
+                 *   left part                 central part          right part
+                 * +------------------------------------------------------------+
+                 * |  < pivot1  |   ?   |  pivot1 <= && <= pivot2  |  > pivot2  |
+                 * +------------------------------------------------------------+
+                 *             ^       ^                            ^
+                 *             |       |                            |
+                 *           lower     k                          upper
+                 *
+                 * Invariants:
+                 *
+                 *              all in (low, lower] < pivot1
+                 *    pivot1 <= all in (k, upper)  <= pivot2
+                 *              all in [upper, end) > pivot2
+                 *
+                 * Pointer k is the last index of ?-part
+                 */
+                for (int unused = --lower, k = ++upper; --k > lower; ) {
+                    long ak = a[k];
+
+                    if (ak < pivot1) { // Move a[k] to the left side
+                        while (lower < k) {
+                            if (a[++lower] >= pivot1) {
+                                if (a[lower] > pivot2) {
+                                    a[k] = a[--upper];
+                                    a[upper] = a[lower];
+                                } else {
+                                    a[k] = a[lower];
+                                }
+                                a[lower] = ak;
+                                break;
+                            }
+                        }
+                    } else if (ak > pivot2) { // Move a[k] to the right side
+                        a[k] = a[--upper];
+                        a[upper] = ak;
                     }
                 }
-                run[++last] = hi;
+
+                /*
+                 * Swap the pivots into their final positions.
+                 */
+                a[low] = a[lower]; a[lower] = pivot1;
+                a[end] = a[upper]; a[upper] = pivot2;
+
+                /*
+                 * Sort non-left parts recursively (possibly in parallel),
+                 * excluding known pivots.
+                 */
+                if (size > MIN_PARALLEL_SORT_SIZE && sorter != null) {
+                    sorter.forkSorter(bits | 1, lower + 1, upper);
+                    sorter.forkSorter(bits | 1, upper + 1, high);
+                } else {
+                    sort(sorter, a, bits | 1, lower + 1, upper);
+                    sort(sorter, a, bits | 1, upper + 1, high);
+                }
+
+            } else { // Use single pivot in case of many equal elements
+
+                /*
+                 * Use the third of the five sorted elements as the pivot.
+                 * This value is inexpensive approximation of the median.
+                 */
+                long pivot = a[e3];
+
+                /*
+                 * The first element to be sorted is moved to the
+                 * location formerly occupied by the pivot. After
+                 * completion of partitioning the pivot is swapped
+                 * back into its final position, and excluded from
+                 * the next subsequent sorting.
+                 */
+                a[e3] = a[lower];
+
+                /*
+                 * Traditional 3-way (Dutch National Flag) partitioning
+                 *
+                 *   left part                 central part    right part
+                 * +------------------------------------------------------+
+                 * |   < pivot   |     ?     |   == pivot   |   > pivot   |
+                 * +------------------------------------------------------+
+                 *              ^           ^                ^
+                 *              |           |                |
+                 *            lower         k              upper
+                 *
+                 * Invariants:
+                 *
+                 *   all in (low, lower] < pivot
+                 *   all in (k, upper)  == pivot
+                 *   all in [upper, end] > pivot
+                 *
+                 * Pointer k is the last index of ?-part
+                 */
+                for (int k = ++upper; --k > lower; ) {
+                    long ak = a[k];
+
+                    if (ak != pivot) {
+                        a[k] = pivot;
+
+                        if (ak < pivot) { // Move a[k] to the left side
+                            while (a[++lower] < pivot);
+
+                            if (a[lower] > pivot) {
+                                a[--upper] = a[lower];
+                            }
+                            a[lower] = ak;
+                        } else { // ak > pivot - Move a[k] to the right side
+                            a[--upper] = ak;
+                        }
+                    }
+                }
+
+                /*
+                 * Swap the pivot into its final position.
+                 */
+                a[low] = a[lower]; a[lower] = pivot;
+
+                /*
+                 * Sort the right part (possibly in parallel), excluding
+                 * known pivot. All elements from the central part are
+                 * equal and therefore already sorted.
+                 */
+                if (size > MIN_PARALLEL_SORT_SIZE && sorter != null) {
+                    sorter.forkSorter(bits | 1, upper, high);
+                } else {
+                    sort(sorter, a, bits | 1, upper, high);
+                }
             }
-            if ((count & 1) != 0) {
-                for (int i = right, lo = run[count - 1]; --i >= lo;
-                    b[i + bo] = a[i + ao]
-                );
-                run[++last] = right;
-            }
-            short[] t = a; a = b; b = t;
-            int o = ao; ao = bo; bo = o;
+            high = lower; // Iterate along the left part
         }
     }
 
     /**
-     * Sorts the specified range of the array by Dual-Pivot Quicksort.
+     * Sorts the specified range of the array using mixed insertion sort.
+     *
+     * Mixed insertion sort is combination of simple insertion sort,
+     * pin insertion sort and pair insertion sort.
+     *
+     * In the context of Dual-Pivot Quicksort, the pivot element
+     * from the left part plays the role of sentinel, because it
+     * is less than any elements from the given part. Therefore,
+     * expensive check of the left range can be skipped on each
+     * iteration unless it is the leftmost call.
      *
      * @param a the array to be sorted
-     * @param left the index of the first element, inclusive, to be sorted
-     * @param right the index of the last element, inclusive, to be sorted
-     * @param leftmost indicates if this part is the leftmost in the range
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param end the index of the last element for simple insertion sort
+     * @param high the index of the last element, exclusive, to be sorted
      */
-    private static void sort(short[] a, int left, int right, boolean leftmost) {
-        int length = right - left + 1;
-
-        // Use insertion sort on tiny arrays
-        if (length < INSERTION_SORT_THRESHOLD) {
-            if (leftmost) {
-                /*
-                 * Traditional (without sentinel) insertion sort,
-                 * optimized for server VM, is used in case of
-                 * the leftmost part.
-                 */
-                for (int i = left, j = i; i < right; j = ++i) {
-                    short ai = a[i + 1];
-                    while (ai < a[j]) {
-                        a[j + 1] = a[j];
-                        if (j-- == left) {
-                            break;
-                        }
-                    }
-                    a[j + 1] = ai;
-                }
-            } else {
-                /*
-                 * Skip the longest ascending sequence.
-                 */
-                do {
-                    if (left >= right) {
-                        return;
-                    }
-                } while (a[++left] >= a[left - 1]);
-
-                /*
-                 * Every element from adjoining part plays the role
-                 * of sentinel, therefore this allows us to avoid the
-                 * left range check on each iteration. Moreover, we use
-                 * the more optimized algorithm, so called pair insertion
-                 * sort, which is faster (in the context of Quicksort)
-                 * than traditional implementation of insertion sort.
-                 */
-                for (int k = left; ++left <= right; k = ++left) {
-                    short a1 = a[k], a2 = a[left];
-
-                    if (a1 < a2) {
-                        a2 = a1; a1 = a[left];
-                    }
-                    while (a1 < a[--k]) {
-                        a[k + 2] = a[k];
-                    }
-                    a[++k + 1] = a1;
-
-                    while (a2 < a[--k]) {
-                        a[k + 1] = a[k];
-                    }
-                    a[k + 1] = a2;
-                }
-                short last = a[right];
-
-                while (last < a[--right]) {
-                    a[right + 1] = a[right];
-                }
-                a[right + 1] = last;
-            }
-            return;
-        }
-
-        // Inexpensive approximation of length / 7
-        int seventh = (length >> 3) + (length >> 6) + 1;
-
-        /*
-         * Sort five evenly spaced elements around (and including) the
-         * center element in the range. These elements will be used for
-         * pivot selection as described below. The choice for spacing
-         * these elements was empirically determined to work well on
-         * a wide variety of inputs.
-         */
-        int e3 = (left + right) >>> 1; // The midpoint
-        int e2 = e3 - seventh;
-        int e1 = e2 - seventh;
-        int e4 = e3 + seventh;
-        int e5 = e4 + seventh;
-
-        // Sort these elements using insertion sort
-        if (a[e2] < a[e1]) { short t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
-
-        if (a[e3] < a[e2]) { short t = a[e3]; a[e3] = a[e2]; a[e2] = t;
-            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
-        }
-        if (a[e4] < a[e3]) { short t = a[e4]; a[e4] = a[e3]; a[e3] = t;
-            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
-                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
-            }
-        }
-        if (a[e5] < a[e4]) { short t = a[e5]; a[e5] = a[e4]; a[e4] = t;
-            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
-                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
-                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
-                }
-            }
-        }
-
-        // Pointers
-        int less  = left;  // The index of the first element of center part
-        int great = right; // The index before the first element of right part
-
-        if (a[e1] != a[e2] && a[e2] != a[e3] && a[e3] != a[e4] && a[e4] != a[e5]) {
-            /*
-             * Use the second and fourth of the five sorted elements as pivots.
-             * These values are inexpensive approximations of the first and
-             * second terciles of the array. Note that pivot1 <= pivot2.
-             */
-            short pivot1 = a[e2];
-            short pivot2 = a[e4];
+    private static void mixedInsertionSort(long[] a, int low, int end, int high) {
+        if (end == high) {
 
             /*
-             * The first and the last elements to be sorted are moved to the
-             * locations formerly occupied by the pivots. When partitioning
-             * is complete, the pivots are swapped back into their final
-             * positions, and excluded from subsequent sorting.
+             * Invoke simple insertion sort on tiny array.
              */
-            a[e2] = a[left];
-            a[e4] = a[right];
-
-            /*
-             * Skip elements, which are less or greater than pivot values.
-             */
-            while (a[++less] < pivot1);
-            while (a[--great] > pivot2);
+            for (int i; ++low < end; ) {
+                long ai = a[i = low];
+
+                while (ai < a[--i]) {
+                    a[i + 1] = a[i];
+                }
+                a[i + 1] = ai;
+            }
+        } else {
 
             /*
-             * Partitioning:
-             *
-             *   left part           center part                   right part
-             * +--------------------------------------------------------------+
-             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
-             * +--------------------------------------------------------------+
-             *               ^                          ^       ^
-             *               |                          |       |
-             *              less                        k     great
-             *
-             * Invariants:
-             *
-             *              all in (left, less)   < pivot1
-             *    pivot1 <= all in [less, k)     <= pivot2
-             *              all in (great, right) > pivot2
+             * Start with pin insertion sort on small part.
              *
-             * Pointer k is the first index of ?-part.
-             */
-            outer:
-            for (int k = less - 1; ++k <= great; ) {
-                short ak = a[k];
-                if (ak < pivot1) { // Move a[k] to left part
-                    a[k] = a[less];
-                    /*
-                     * Here and below we use "a[i] = b; i++;" instead
-                     * of "a[i++] = b;" due to performance issue.
-                     */
-                    a[less] = ak;
-                    ++less;
-                } else if (ak > pivot2) { // Move a[k] to right part
-                    while (a[great] > pivot2) {
-                        if (great-- == k) {
-                            break outer;
-                        }
-                    }
-                    if (a[great] < pivot1) { // a[great] <= pivot2
-                        a[k] = a[less];
-                        a[less] = a[great];
-                        ++less;
-                    } else { // pivot1 <= a[great] <= pivot2
-                        a[k] = a[great];
-                    }
-                    /*
-                     * Here and below we use "a[i] = b; i--;" instead
-                     * of "a[i--] = b;" due to performance issue.
-                     */
-                    a[great] = ak;
-                    --great;
-                }
-            }
-
-            // Swap pivots into their final positions
-            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
-            a[right] = a[great + 1]; a[great + 1] = pivot2;
-
-            // Sort left and right parts recursively, excluding known pivots
-            sort(a, left, less - 2, leftmost);
-            sort(a, great + 2, right, false);
-
-            /*
-             * If center part is too large (comprises > 4/7 of the array),
-             * swap internal pivot values to ends.
+             * Pin insertion sort is extended simple insertion sort.
+             * The main idea of this sort is to put elements larger
+             * than an element called pin to the end of array (the
+             * proper area for such elements). It avoids expensive
+             * movements of these elements through the whole array.
              */
-            if (less < e1 && e5 < great) {
-                /*
-                 * Skip elements, which are equal to pivot values.
-                 */
-                while (a[less] == pivot1) {
-                    ++less;
-                }
-
-                while (a[great] == pivot2) {
-                    --great;
-                }
-
-                /*
-                 * Partitioning:
-                 *
-                 *   left part         center part                  right part
-                 * +----------------------------------------------------------+
-                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
-                 * +----------------------------------------------------------+
-                 *              ^                        ^       ^
-                 *              |                        |       |
-                 *             less                      k     great
-                 *
-                 * Invariants:
-                 *
-                 *              all in (*,  less) == pivot1
-                 *     pivot1 < all in [less,  k)  < pivot2
-                 *              all in (great, *) == pivot2
-                 *
-                 * Pointer k is the first index of ?-part.
-                 */
-                outer:
-                for (int k = less - 1; ++k <= great; ) {
-                    short ak = a[k];
-                    if (ak == pivot1) { // Move a[k] to left part
-                        a[k] = a[less];
-                        a[less] = ak;
-                        ++less;
-                    } else if (ak == pivot2) { // Move a[k] to right part
-                        while (a[great] == pivot2) {
-                            if (great-- == k) {
-                                break outer;
-                            }
-                        }
-                        if (a[great] == pivot1) { // a[great] < pivot2
-                            a[k] = a[less];
-                            /*
-                             * Even though a[great] equals to pivot1, the
-                             * assignment a[less] = pivot1 may be incorrect,
-                             * if a[great] and pivot1 are floating-point zeros
-                             * of different signs. Therefore in float and
-                             * double sorting methods we have to use more
-                             * accurate assignment a[less] = a[great].
-                             */
-                            a[less] = pivot1;
-                            ++less;
-                        } else { // pivot1 < a[great] < pivot2
-                            a[k] = a[great];
-                        }
-                        a[great] = ak;
-                        --great;
+            long pin = a[end];
+
+            for (int i, p = high; ++low < end; ) {
+                long ai = a[i = low];
+
+                if (ai < a[i - 1]) { // Small element
+
+                    /*
+                     * Insert small element into sorted part.
+                     */
+                    a[i] = a[--i];
+
+                    while (ai < a[--i]) {
+                        a[i + 1] = a[i];
                     }
-                }
-            }
-
-            // Sort center part recursively
-            sort(a, less, great, false);
-
-        } else { // Partitioning with one pivot
-            /*
-             * Use the third of the five sorted elements as pivot.
-             * This value is inexpensive approximation of the median.
-             */
-            short pivot = a[e3];
-
-            /*
-             * Partitioning degenerates to the traditional 3-way
-             * (or "Dutch National Flag") schema:
-             *
-             *   left part    center part              right part
-             * +-------------------------------------------------+
-             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
-             * +-------------------------------------------------+
-             *              ^              ^        ^
-             *              |              |        |
-             *             less            k      great
-             *
-             * Invariants:
-             *
-             *   all in (left, less)   < pivot
-             *   all in [less, k)     == pivot
-             *   all in (great, right) > pivot
-             *
-             * Pointer k is the first index of ?-part.
-             */
-            for (int k = less; k <= great; ++k) {
-                if (a[k] == pivot) {
-                    continue;
-                }
-                short ak = a[k];
-                if (ak < pivot) { // Move a[k] to left part
-                    a[k] = a[less];
-                    a[less] = ak;
-                    ++less;
-                } else { // a[k] > pivot - Move a[k] to right part
-                    while (a[great] > pivot) {
-                        --great;
+                    a[i + 1] = ai;
+
+                } else if (p > i && ai > pin) { // Large element
+
+                    /*
+                     * Find element smaller than pin.
+                     */
+                    while (a[--p] > pin);
+
+                    /*
+                     * Swap it with large element.
+                     */
+                    if (p > i) {
+                        ai = a[p];
+                        a[p] = a[i];
                     }
-                    if (a[great] < pivot) { // a[great] <= pivot
-                        a[k] = a[less];
-                        a[less] = a[great];
-                        ++less;
-                    } else { // a[great] == pivot
-                        /*
-                         * Even though a[great] equals to pivot, the
-                         * assignment a[k] = pivot may be incorrect,
-                         * if a[great] and pivot are floating-point
-                         * zeros of different signs. Therefore in float
-                         * and double sorting methods we have to use
-                         * more accurate assignment a[k] = a[great].
-                         */
-                        a[k] = pivot;
+
+                    /*
+                     * Insert small element into sorted part.
+                     */
+                    while (ai < a[--i]) {
+                        a[i + 1] = a[i];
                     }
-                    a[great] = ak;
-                    --great;
+                    a[i + 1] = ai;
                 }
             }
 
             /*
-             * Sort left and right parts recursively.
-             * All elements from center part are equal
-             * and, therefore, already sorted.
+             * Continue with pair insertion sort on remain part.
              */
-            sort(a, left, less - 1, leftmost);
-            sort(a, great + 1, right, false);
+            for (int i; low < high; ++low) {
+                long a1 = a[i = low], a2 = a[++low];
+
+                /*
+                 * Insert two elements per iteration: at first, insert the
+                 * larger element and then insert the smaller element, but
+                 * from the position where the larger element was inserted.
+                 */
+                if (a1 > a2) {
+
+                    while (a1 < a[--i]) {
+                        a[i + 2] = a[i];
+                    }
+                    a[++i + 1] = a1;
+
+                    while (a2 < a[--i]) {
+                        a[i + 1] = a[i];
+                    }
+                    a[i + 1] = a2;
+
+                } else if (a1 < a[i - 1]) {
+
+                    while (a2 < a[--i]) {
+                        a[i + 2] = a[i];
+                    }
+                    a[++i + 1] = a2;
+
+                    while (a1 < a[--i]) {
+                        a[i + 1] = a[i];
+                    }
+                    a[i + 1] = a1;
+                }
+            }
+        }
+    }
+
+    /**
+     * Sorts the specified range of the array using insertion sort.
+     *
+     * @param a the array to be sorted
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
+     */
+    private static void insertionSort(long[] a, int low, int high) {
+        for (int i, k = low; ++k < high; ) {
+            long ai = a[i = k];
+
+            if (ai < a[i - 1]) {
+                while (--i >= low && ai < a[i]) {
+                    a[i + 1] = a[i];
+                }
+                a[i + 1] = ai;
+            }
+        }
+    }
+
+    /**
+     * Sorts the specified range of the array using heap sort.
+     *
+     * @param a the array to be sorted
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
+     */
+    private static void heapSort(long[] a, int low, int high) {
+        for (int k = (low + high) >>> 1; k > low; ) {
+            pushDown(a, --k, a[k], low, high);
+        }
+        while (--high > low) {
+            long max = a[low];
+            pushDown(a, low, a[high], low, high);
+            a[high] = max;
         }
     }
 
     /**
-     * Sorts the specified range of the array using the given
-     * workspace array slice if possible for merging
+     * Pushes specified element down during heap sort.
      *
-     * @param a the array to be sorted
-     * @param left the index of the first element, inclusive, to be sorted
-     * @param right the index of the last element, inclusive, to be sorted
-     * @param work a workspace array (slice)
-     * @param workBase origin of usable space in work array
-     * @param workLen usable size of work array
+     * @param a the given array
+     * @param p the start index
+     * @param value the given element
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
      */
-    static void sort(char[] a, int left, int right,
-                     char[] work, int workBase, int workLen) {
-        // Use counting sort on large arrays
-        if (right - left > COUNTING_SORT_THRESHOLD_FOR_SHORT_OR_CHAR) {
-            int[] count = new int[NUM_CHAR_VALUES];
-
-            for (int i = left - 1; ++i <= right;
-                count[a[i]]++
-            );
-            for (int i = NUM_CHAR_VALUES, k = right + 1; k > left; ) {
-                while (count[--i] == 0);
-                char value = (char) i;
-                int s = count[i];
-
-                do {
-                    a[--k] = value;
-                } while (--s > 0);
+    private static void pushDown(long[] a, int p, long value, int low, int high) {
+        for (int k ;; a[p] = a[p = k]) {
+            k = (p << 1) - low + 2; // Index of the right child
+
+            if (k > high) {
+                break;
             }
-        } else { // Use Dual-Pivot Quicksort on small arrays
-            doSort(a, left, right, work, workBase, workLen);
+            if (k == high || a[k] < a[k - 1]) {
+                --k;
+            }
+            if (a[k] <= value) {
+                break;
+            }
         }
+        a[p] = value;
     }
 
-    /** The number of distinct char values. */
-    private static final int NUM_CHAR_VALUES = 1 << 16;
-
     /**
-     * Sorts the specified range of the array.
+     * Tries to sort the specified range of the array.
      *
+     * @param sorter parallel context
      * @param a the array to be sorted
-     * @param left the index of the first element, inclusive, to be sorted
-     * @param right the index of the last element, inclusive, to be sorted
-     * @param work a workspace array (slice)
-     * @param workBase origin of usable space in work array
-     * @param workLen usable size of work array
+     * @param low the index of the first element to be sorted
+     * @param size the array size
+     * @return true if finally sorted, false otherwise
      */
-    private static void doSort(char[] a, int left, int right,
-                               char[] work, int workBase, int workLen) {
-        // Use Quicksort on small arrays
-        if (right - left < QUICKSORT_THRESHOLD) {
-            sort(a, left, right, true);
-            return;
+    private static boolean tryMergeRuns(Sorter sorter, long[] a, int low, int size) {
+
+        /*
+         * The run array is constructed only if initial runs are
+         * long enough to continue, run[i] then holds start index
+         * of the i-th sequence of elements in non-descending order.
+         */
+        int[] run = null;
+        int high = low + size;
+        int count = 1, last = low;
+
+        /*
+         * Identify all possible runs.
+         */
+        for (int k = low + 1; k < high; ) {
+
+            /*
+             * Find the end index of the current run.
+             */
+            if (a[k - 1] < a[k]) {
+
+                // Identify ascending sequence
+                while (++k < high && a[k - 1] <= a[k]);
+
+            } else if (a[k - 1] > a[k]) {
+
+                // Identify descending sequence
+                while (++k < high && a[k - 1] >= a[k]);
+
+                // Reverse into ascending order
+                for (int i = last - 1, j = k; ++i < --j && a[i] > a[j]; ) {
+                    long ai = a[i]; a[i] = a[j]; a[j] = ai;
+                }
+            } else { // Identify constant sequence
+                for (long ak = a[k]; ++k < high && ak == a[k]; );
+
+                if (k < high) {
+                    continue;
+                }
+            }
+
+            /*
+             * Check special cases.
+             */
+            if (run == null) {
+                if (k == high) {
+
+                    /*
+                     * The array is monotonous sequence,
+                     * and therefore already sorted.
+                     */
+                    return true;
+                }
+
+                if (k - low < MIN_FIRST_RUN_SIZE) {
+
+                    /*
+                     * The first run is too small
+                     * to proceed with scanning.
+                     */
+                    return false;
+                }
+
+                run = new int[((size >> 10) | 0x7F) & 0x3FF];
+                run[0] = low;
+
+            } else if (a[last - 1] > a[last]) {
+
+                if (count > (k - low) >> MIN_FIRST_RUNS_FACTOR) {
+
+                    /*
+                     * The first runs are not long
+                     * enough to continue scanning.
+                     */
+                    return false;
+                }
+
+                if (++count == MAX_RUN_CAPACITY) {
+
+                    /*
+                     * Array is not highly structured.
+                     */
+                    return false;
+                }
+
+                if (count == run.length) {
+
+                    /*
+                     * Increase capacity of index array.
+                     */
+                    run = Arrays.copyOf(run, count << 1);
+                }
+            }
+            run[count] = (last = k);
         }
 
         /*
-         * Index run[i] is the start of i-th run
-         * (ascending or descending sequence).
+         * Merge runs of highly structured array.
+         */
+        if (count > 1) {
+            long[] b; int offset = low;
+
+            if (sorter == null || (b = (long[]) sorter.b) == null) {
+                b = new long[size];
+            } else {
+                offset = sorter.offset;
+            }
+            mergeRuns(a, b, offset, 1, sorter != null, run, 0, count);
+        }
+        return true;
+    }
+
+    /**
+     * Merges the specified runs.
+     *
+     * @param a the source array
+     * @param b the temporary buffer used in merging
+     * @param offset the start index in the source, inclusive
+     * @param aim specifies merging: to source ( > 0), buffer ( < 0) or any ( == 0)
+     * @param parallel indicates whether merging is performed in parallel
+     * @param run the start indexes of the runs, inclusive
+     * @param lo the start index of the first run, inclusive
+     * @param hi the start index of the last run, inclusive
+     * @return the destination where runs are merged
+     */
+    private static long[] mergeRuns(long[] a, long[] b, int offset,
+            int aim, boolean parallel, int[] run, int lo, int hi) {
+
+        if (hi - lo == 1) {
+            if (aim >= 0) {
+                return a;
+            }
+            for (int i = run[hi], j = i - offset, low = run[lo]; i > low;
+                b[--j] = a[--i]
+            );
+            return b;
+        }
+
+        /*
+         * Split into approximately equal parts.
+         */
+        int mi = lo, rmi = (run[lo] + run[hi]) >>> 1;
+        while (run[++mi + 1] <= rmi);
+
+        /*
+         * Merge the left and right parts.
          */
-        int[] run = new int[MAX_RUN_COUNT + 1];
-        int count = 0; run[0] = left;
-
-        // Check if the array is nearly sorted
-        for (int k = left; k < right; run[count] = k) {
-            // Equal items in the beginning of the sequence
-            while (k < right && a[k] == a[k + 1])
-                k++;
-            if (k == right) break;  // Sequence finishes with equal items
-            if (a[k] < a[k + 1]) { // ascending
-                while (++k <= right && a[k - 1] <= a[k]);
-            } else if (a[k] > a[k + 1]) { // descending
-                while (++k <= right && a[k - 1] >= a[k]);
-                // Transform into an ascending sequence
-                for (int lo = run[count] - 1, hi = k; ++lo < --hi; ) {
-                    char t = a[lo]; a[lo] = a[hi]; a[hi] = t;
+        long[] a1, a2;
+
+        if (parallel && hi - lo > MIN_RUN_COUNT) {
+            RunMerger merger = new RunMerger(a, b, offset, 0, run, mi, hi).forkMe();
+            a1 = mergeRuns(a, b, offset, -aim, true, run, lo, mi);
+            a2 = (long[]) merger.getDestination();
+        } else {
+            a1 = mergeRuns(a, b, offset, -aim, false, run, lo, mi);
+            a2 = mergeRuns(a, b, offset,    0, false, run, mi, hi);
+        }
+
+        long[] dst = a1 == a ? b : a;
+
+        int k   = a1 == a ? run[lo] - offset : run[lo];
+        int lo1 = a1 == b ? run[lo] - offset : run[lo];
+        int hi1 = a1 == b ? run[mi] - offset : run[mi];
+        int lo2 = a2 == b ? run[mi] - offset : run[mi];
+        int hi2 = a2 == b ? run[hi] - offset : run[hi];
+
+        if (parallel) {
+            new Merger(null, dst, k, a1, lo1, hi1, a2, lo2, hi2).invoke();
+        } else {
+            mergeParts(null, dst, k, a1, lo1, hi1, a2, lo2, hi2);
+        }
+        return dst;
+    }
+
+    /**
+     * Merges the sorted parts.
+     *
+     * @param merger parallel context
+     * @param dst the destination where parts are merged
+     * @param k the start index of the destination, inclusive
+     * @param a1 the first part
+     * @param lo1 the start index of the first part, inclusive
+     * @param hi1 the end index of the first part, exclusive
+     * @param a2 the second part
+     * @param lo2 the start index of the second part, inclusive
+     * @param hi2 the end index of the second part, exclusive
+     */
+    private static void mergeParts(Merger merger, long[] dst, int k,
+            long[] a1, int lo1, int hi1, long[] a2, int lo2, int hi2) {
+
+        if (merger != null && a1 == a2) {
+
+            while (true) {
+
+                /*
+                 * The first part must be larger.
+                 */
+                if (hi1 - lo1 < hi2 - lo2) {
+                    int lo = lo1; lo1 = lo2; lo2 = lo;
+                    int hi = hi1; hi1 = hi2; hi2 = hi;
                 }
-            }
-
-            // Merge a transformed descending sequence followed by an
-            // ascending sequence
-            if (run[count] > left && a[run[count]] >= a[run[count] - 1]) {
-                count--;
-            }
-
-            /*
-             * The array is not highly structured,
-             * use Quicksort instead of merge sort.
-             */
-            if (++count == MAX_RUN_COUNT) {
-                sort(a, left, right, true);
-                return;
+
+                /*
+                 * Small parts will be merged sequentially.
+                 */
+                if (hi1 - lo1 < MIN_PARALLEL_MERGE_PARTS_SIZE) {
+                    break;
+                }
+
+                /*
+                 * Find the median of the larger part.
+                 */
+                int mi1 = (lo1 + hi1) >>> 1;
+                long key = a1[mi1];
+                int mi2 = hi2;
+
+                /*
+                 * Partition the smaller part.
+                 */
+                for (int loo = lo2; loo < mi2; ) {
+                    int t = (loo + mi2) >>> 1;
+
+                    if (key > a2[t]) {
+                        loo = t + 1;
+                    } else {
+                        mi2 = t;
+                    }
+                }
+
+                int d = mi2 - lo2 + mi1 - lo1;
+
+                /*
+                 * Merge the right sub-parts in parallel.
+                 */
+                merger.forkMerger(dst, k + d, a1, mi1, hi1, a2, mi2, hi2);
+
+                /*
+                 * Process the sub-left parts.
+                 */
+                hi1 = mi1;
+                hi2 = mi2;
             }
         }
 
-        // These invariants should hold true:
-        //    run[0] = 0
-        //    run[<last>] = right + 1; (terminator)
-
-        if (count == 0) {
-            // A single equal run
-            return;
-        } else if (count == 1 && run[count] > right) {
-            // Either a single ascending or a transformed descending run.
-            // Always check that a final run is a proper terminator, otherwise
-            // we have an unterminated trailing run, to handle downstream.
-            return;
+        /*
+         * Merge small parts sequentially.
+         */
+        while (lo1 < hi1 && lo2 < hi2) {
+            dst[k++] = a1[lo1] < a2[lo2] ? a1[lo1++] : a2[lo2++];
         }
-        right++;
-        if (run[count] < right) {
-            // Corner case: the final run is not a terminator. This may happen
-            // if a final run is an equals run, or there is a single-element run
-            // at the end. Fix up by adding a proper terminator at the end.
-            // Note that we terminate with (right + 1), incremented earlier.
-            run[++count] = right;
+        if (dst != a1 || k < lo1) {
+            while (lo1 < hi1) {
+                dst[k++] = a1[lo1++];
+            }
         }
-
-        // Determine alternation base for merge
-        byte odd = 0;
-        for (int n = 1; (n <<= 1) < count; odd ^= 1);
-
-        // Use or create temporary array b for merging
-        char[] b;                 // temp array; alternates with a
-        int ao, bo;              // array offsets from 'left'
-        int blen = right - left; // space needed for b
-        if (work == null || workLen < blen || workBase + blen > work.length) {
-            work = new char[blen];
-            workBase = 0;
+        if (dst != a2 || k < lo2) {
+            while (lo2 < hi2) {
+                dst[k++] = a2[lo2++];
+            }
         }
-        if (odd == 0) {
-            System.arraycopy(a, left, work, workBase, blen);
-            b = a;
-            bo = 0;
-            a = work;
-            ao = workBase - left;
+    }
+
+// [byte]
+
+    /**
+     * Sorts the specified range of the array using
+     * counting sort or insertion sort.
+     *
+     * @param a the array to be sorted
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
+     */
+    static void sort(byte[] a, int low, int high) {
+        if (high - low > MIN_BYTE_COUNTING_SORT_SIZE) {
+            countingSort(a, low, high);
         } else {
-            b = work;
-            ao = 0;
-            bo = workBase - left;
-        }
-
-        // Merging
-        for (int last; count > 1; count = last) {
-            for (int k = (last = 0) + 2; k <= count; k += 2) {
-                int hi = run[k], mi = run[k - 1];
-                for (int i = run[k - 2], p = i, q = mi; i < hi; ++i) {
-                    if (q >= hi || p < mi && a[p + ao] <= a[q + ao]) {
-                        b[i + bo] = a[p++ + ao];
-                    } else {
-                        b[i + bo] = a[q++ + ao];
-                    }
-                }
-                run[++last] = hi;
-            }
-            if ((count & 1) != 0) {
-                for (int i = right, lo = run[count - 1]; --i >= lo;
-                    b[i + bo] = a[i + ao]
-                );
-                run[++last] = right;
-            }
-            char[] t = a; a = b; b = t;
-            int o = ao; ao = bo; bo = o;
+            insertionSort(a, low, high);
         }
     }
 
     /**
-     * Sorts the specified range of the array by Dual-Pivot Quicksort.
+     * Sorts the specified range of the array using insertion sort.
+     *
+     * @param a the array to be sorted
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
+     */
+    private static void insertionSort(byte[] a, int low, int high) {
+        for (int i, k = low; ++k < high; ) {
+            byte ai = a[i = k];
+
+            if (ai < a[i - 1]) {
+                while (--i >= low && ai < a[i]) {
+                    a[i + 1] = a[i];
+                }
+                a[i + 1] = ai;
+            }
+        }
+    }
+
+    /**
+     * The number of distinct byte values.
+     */
+    private static final int NUM_BYTE_VALUES = 1 << 8;
+
+    /**
+     * Max index of byte counter.
+     */
+    private static final int MAX_BYTE_INDEX = Byte.MAX_VALUE + NUM_BYTE_VALUES + 1;
+
+    /**
+     * Sorts the specified range of the array using counting sort.
+     *
+     * @param a the array to be sorted
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
+     */
+    private static void countingSort(byte[] a, int low, int high) {
+        int[] count = new int[NUM_BYTE_VALUES];
+
+        /*
+         * Compute a histogram with the number of each values.
+         */
+        for (int i = high; i > low; ++count[a[--i] & 0xFF]);
+
+        /*
+         * Place values on their final positions.
+         */
+        if (high - low > NUM_BYTE_VALUES) {
+            for (int i = MAX_BYTE_INDEX; --i > Byte.MAX_VALUE; ) {
+                int value = i & 0xFF;
+
+                for (low = high - count[value]; high > low;
+                    a[--high] = (byte) value
+                );
+            }
+        } else {
+            for (int i = MAX_BYTE_INDEX; high > low; ) {
+                while (count[--i & 0xFF] == 0);
+
+                int value = i & 0xFF;
+                int c = count[value];
+
+                do {
+                    a[--high] = (byte) value;
+                } while (--c > 0);
+            }
+        }
+    }
+
+// [char]
+
+    /**
+     * Sorts the specified range of the array using
+     * counting sort or Dual-Pivot Quicksort.
      *
      * @param a the array to be sorted
-     * @param left the index of the first element, inclusive, to be sorted
-     * @param right the index of the last element, inclusive, to be sorted
-     * @param leftmost indicates if this part is the leftmost in the range
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
+     */
+    static void sort(char[] a, int low, int high) {
+        if (high - low > MIN_SHORT_OR_CHAR_COUNTING_SORT_SIZE) {
+            countingSort(a, low, high);
+        } else {
+            sort(a, 0, low, high);
+        }
+    }
+
+    /**
+     * Sorts the specified array using the Dual-Pivot Quicksort and/or
+     * other sorts in special-cases, possibly with parallel partitions.
+     *
+     * @param a the array to be sorted
+     * @param bits the combination of recursion depth and bit flag, where
+     *        the right bit "0" indicates that array is the leftmost part
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
      */
-    private static void sort(char[] a, int left, int right, boolean leftmost) {
-        int length = right - left + 1;
-
-        // Use insertion sort on tiny arrays
-        if (length < INSERTION_SORT_THRESHOLD) {
-            if (leftmost) {
-                /*
-                 * Traditional (without sentinel) insertion sort,
-                 * optimized for server VM, is used in case of
-                 * the leftmost part.
-                 */
-                for (int i = left, j = i; i < right; j = ++i) {
-                    char ai = a[i + 1];
-                    while (ai < a[j]) {
-                        a[j + 1] = a[j];
-                        if (j-- == left) {
-                            break;
-                        }
-                    }
-                    a[j + 1] = ai;
+    static void sort(char[] a, int bits, int low, int high) {
+        while (true) {
+            int end = high - 1, size = high - low;
+
+            /*
+             * Invoke insertion sort on small leftmost part.
+             */
+            if (size < MAX_INSERTION_SORT_SIZE) {
+                insertionSort(a, low, high);
+                return;
+            }
+
+            /*
+             * Switch to counting sort if execution
+             * time is becoming quadratic.
+             */
+            if ((bits += DELTA) > MAX_RECURSION_DEPTH) {
+                countingSort(a, low, high);
+                return;
+            }
+
+            /*
+             * Use an inexpensive approximation of the golden ratio
+             * to select five sample elements and determine pivots.
+             */
+            int step = (size >> 3) * 3 + 3;
+
+            /*
+             * Five elements around (and including) the central element
+             * will be used for pivot selection as described below. The
+             * unequal choice of spacing these elements was empirically
+             * determined to work well on a wide variety of inputs.
+             */
+            int e1 = low + step;
+            int e5 = end - step;
+            int e3 = (e1 + e5) >>> 1;
+            int e2 = (e1 + e3) >>> 1;
+            int e4 = (e3 + e5) >>> 1;
+            char a3 = a[e3];
+
+            /*
+             * Sort these elements in place by the combination
+             * of 4-element sorting network and insertion sort.
+             *
+             *    5 ------o-----------o------------
+             *            |           |
+             *    4 ------|-----o-----o-----o------
+             *            |     |           |
+             *    2 ------o-----|-----o-----o------
+             *                  |     |
+             *    1 ------------o-----o------------
+             */
+            if (a[e5] < a[e2]) { char t = a[e5]; a[e5] = a[e2]; a[e2] = t; }
+            if (a[e4] < a[e1]) { char t = a[e4]; a[e4] = a[e1]; a[e1] = t; }
+            if (a[e5] < a[e4]) { char t = a[e5]; a[e5] = a[e4]; a[e4] = t; }
+            if (a[e2] < a[e1]) { char t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
+            if (a[e4] < a[e2]) { char t = a[e4]; a[e4] = a[e2]; a[e2] = t; }
+
+            if (a3 < a[e2]) {
+                if (a3 < a[e1]) {
+                    a[e3] = a[e2]; a[e2] = a[e1]; a[e1] = a3;
+                } else {
+                    a[e3] = a[e2]; a[e2] = a3;
                 }
-            } else {
-                /*
-                 * Skip the longest ascending sequence.
-                 */
-                do {
-                    if (left >= right) {
-                        return;
-                    }
-                } while (a[++left] >= a[left - 1]);
-
-                /*
-                 * Every element from adjoining part plays the role
-                 * of sentinel, therefore this allows us to avoid the
-                 * left range check on each iteration. Moreover, we use
-                 * the more optimized algorithm, so called pair insertion
-                 * sort, which is faster (in the context of Quicksort)
-                 * than traditional implementation of insertion sort.
-                 */
-                for (int k = left; ++left <= right; k = ++left) {
-                    char a1 = a[k], a2 = a[left];
-
-                    if (a1 < a2) {
-                        a2 = a1; a1 = a[left];
-                    }
-                    while (a1 < a[--k]) {
-                        a[k + 2] = a[k];
-                    }
-                    a[++k + 1] = a1;
-
-                    while (a2 < a[--k]) {
-                        a[k + 1] = a[k];
-                    }
-                    a[k + 1] = a2;
-                }
-                char last = a[right];
-
-                while (last < a[--right]) {
-                    a[right + 1] = a[right];
-                }
-                a[right + 1] = last;
-            }
-            return;
-        }
-
-        // Inexpensive approximation of length / 7
-        int seventh = (length >> 3) + (length >> 6) + 1;
-
-        /*
-         * Sort five evenly spaced elements around (and including) the
-         * center element in the range. These elements will be used for
-         * pivot selection as described below. The choice for spacing
-         * these elements was empirically determined to work well on
-         * a wide variety of inputs.
-         */
-        int e3 = (left + right) >>> 1; // The midpoint
-        int e2 = e3 - seventh;
-        int e1 = e2 - seventh;
-        int e4 = e3 + seventh;
-        int e5 = e4 + seventh;
-
-        // Sort these elements using insertion sort
-        if (a[e2] < a[e1]) { char t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
-
-        if (a[e3] < a[e2]) { char t = a[e3]; a[e3] = a[e2]; a[e2] = t;
-            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
-        }
-        if (a[e4] < a[e3]) { char t = a[e4]; a[e4] = a[e3]; a[e3] = t;
-            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
-                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
-            }
-        }
-        if (a[e5] < a[e4]) { char t = a[e5]; a[e5] = a[e4]; a[e4] = t;
-            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
-                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
-                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
+            } else if (a3 > a[e4]) {
+                if (a3 > a[e5]) {
+                    a[e3] = a[e4]; a[e4] = a[e5]; a[e5] = a3;
+                } else {
+                    a[e3] = a[e4]; a[e4] = a3;
                 }
             }
-        }
-
-        // Pointers
-        int less  = left;  // The index of the first element of center part
-        int great = right; // The index before the first element of right part
-
-        if (a[e1] != a[e2] && a[e2] != a[e3] && a[e3] != a[e4] && a[e4] != a[e5]) {
-            /*
-             * Use the second and fourth of the five sorted elements as pivots.
-             * These values are inexpensive approximations of the first and
-             * second terciles of the array. Note that pivot1 <= pivot2.
-             */
-            char pivot1 = a[e2];
-            char pivot2 = a[e4];
-
-            /*
-             * The first and the last elements to be sorted are moved to the
-             * locations formerly occupied by the pivots. When partitioning
-             * is complete, the pivots are swapped back into their final
-             * positions, and excluded from subsequent sorting.
-             */
-            a[e2] = a[left];
-            a[e4] = a[right];
-
-            /*
-             * Skip elements, which are less or greater than pivot values.
-             */
-            while (a[++less] < pivot1);
-            while (a[--great] > pivot2);
+
+            // Pointers
+            int lower = low; // The index of the last element of the left part
+            int upper = end; // The index of the first element of the right part
 
             /*
-             * Partitioning:
-             *
-             *   left part           center part                   right part
-             * +--------------------------------------------------------------+
-             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
-             * +--------------------------------------------------------------+
-             *               ^                          ^       ^
-             *               |                          |       |
-             *              less                        k     great
-             *
-             * Invariants:
-             *
-             *              all in (left, less)   < pivot1
-             *    pivot1 <= all in [less, k)     <= pivot2
-             *              all in (great, right) > pivot2
-             *
-             * Pointer k is the first index of ?-part.
+             * Partitioning with 2 pivots in case of different elements.
              */
-            outer:
-            for (int k = less - 1; ++k <= great; ) {
-                char ak = a[k];
-                if (ak < pivot1) { // Move a[k] to left part
-                    a[k] = a[less];
-                    /*
-                     * Here and below we use "a[i] = b; i++;" instead
-                     * of "a[i++] = b;" due to performance issue.
-                     */
-                    a[less] = ak;
-                    ++less;
-                } else if (ak > pivot2) { // Move a[k] to right part
-                    while (a[great] > pivot2) {
-                        if (great-- == k) {
-                            break outer;
+            if (a[e1] < a[e2] && a[e2] < a[e3] && a[e3] < a[e4] && a[e4] < a[e5]) {
+
+                /*
+                 * Use the first and fifth of the five sorted elements as
+                 * the pivots. These values are inexpensive approximation
+                 * of tertiles. Note, that pivot1 < pivot2.
+                 */
+                char pivot1 = a[e1];
+                char pivot2 = a[e5];
+
+                /*
+                 * The first and the last elements to be sorted are moved
+                 * to the locations formerly occupied by the pivots. When
+                 * partitioning is completed, the pivots are swapped back
+                 * into their final positions, and excluded from the next
+                 * subsequent sorting.
+                 */
+                a[e1] = a[lower];
+                a[e5] = a[upper];
+
+                /*
+                 * Skip elements, which are less or greater than the pivots.
+                 */
+                while (a[++lower] < pivot1);
+                while (a[--upper] > pivot2);
+
+                /*
+                 * Backward 3-interval partitioning
+                 *
+                 *   left part                 central part          right part
+                 * +------------------------------------------------------------+
+                 * |  < pivot1  |   ?   |  pivot1 <= && <= pivot2  |  > pivot2  |
+                 * +------------------------------------------------------------+
+                 *             ^       ^                            ^
+                 *             |       |                            |
+                 *           lower     k                          upper
+                 *
+                 * Invariants:
+                 *
+                 *              all in (low, lower] < pivot1
+                 *    pivot1 <= all in (k, upper)  <= pivot2
+                 *              all in [upper, end) > pivot2
+                 *
+                 * Pointer k is the last index of ?-part
+                 */
+                for (int unused = --lower, k = ++upper; --k > lower; ) {
+                    char ak = a[k];
+
+                    if (ak < pivot1) { // Move a[k] to the left side
+                        while (lower < k) {
+                            if (a[++lower] >= pivot1) {
+                                if (a[lower] > pivot2) {
+                                    a[k] = a[--upper];
+                                    a[upper] = a[lower];
+                                } else {
+                                    a[k] = a[lower];
+                                }
+                                a[lower] = ak;
+                                break;
+                            }
                         }
+                    } else if (ak > pivot2) { // Move a[k] to the right side
+                        a[k] = a[--upper];
+                        a[upper] = ak;
                     }
-                    if (a[great] < pivot1) { // a[great] <= pivot2
-                        a[k] = a[less];
-                        a[less] = a[great];
-                        ++less;
-                    } else { // pivot1 <= a[great] <= pivot2
-                        a[k] = a[great];
-                    }
-                    /*
-                     * Here and below we use "a[i] = b; i--;" instead
-                     * of "a[i--] = b;" due to performance issue.
-                     */
-                    a[great] = ak;
-                    --great;
-                }
-            }
-
-            // Swap pivots into their final positions
-            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
-            a[right] = a[great + 1]; a[great + 1] = pivot2;
-
-            // Sort left and right parts recursively, excluding known pivots
-            sort(a, left, less - 2, leftmost);
-            sort(a, great + 2, right, false);
-
-            /*
-             * If center part is too large (comprises > 4/7 of the array),
-             * swap internal pivot values to ends.
-             */
-            if (less < e1 && e5 < great) {
-                /*
-                 * Skip elements, which are equal to pivot values.
-                 */
-                while (a[less] == pivot1) {
-                    ++less;
-                }
-
-                while (a[great] == pivot2) {
-                    --great;
                 }
 
                 /*
-                 * Partitioning:
+                 * Swap the pivots into their final positions.
+                 */
+                a[low] = a[lower]; a[lower] = pivot1;
+                a[end] = a[upper]; a[upper] = pivot2;
+
+                /*
+                 * Sort non-left parts recursively,
+                 * excluding known pivots.
+                 */
+                sort(a, bits | 1, lower + 1, upper);
+                sort(a, bits | 1, upper + 1, high);
+
+            } else { // Use single pivot in case of many equal elements
+
+                /*
+                 * Use the third of the five sorted elements as the pivot.
+                 * This value is inexpensive approximation of the median.
+                 */
+                char pivot = a[e3];
+
+                /*
+                 * The first element to be sorted is moved to the
+                 * location formerly occupied by the pivot. After
+                 * completion of partitioning the pivot is swapped
+                 * back into its final position, and excluded from
+                 * the next subsequent sorting.
+                 */
+                a[e3] = a[lower];
+
+                /*
+                 * Traditional 3-way (Dutch National Flag) partitioning
                  *
-                 *   left part         center part                  right part
-                 * +----------------------------------------------------------+
-                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
-                 * +----------------------------------------------------------+
-                 *              ^                        ^       ^
-                 *              |                        |       |
-                 *             less                      k     great
+                 *   left part                 central part    right part
+                 * +------------------------------------------------------+
+                 * |   < pivot   |     ?     |   == pivot   |   > pivot   |
+                 * +------------------------------------------------------+
+                 *              ^           ^                ^
+                 *              |           |                |
+                 *            lower         k              upper
                  *
                  * Invariants:
                  *
-                 *              all in (*,  less) == pivot1
-                 *     pivot1 < all in [less,  k)  < pivot2
-                 *              all in (great, *) == pivot2
+                 *   all in (low, lower] < pivot
+                 *   all in (k, upper)  == pivot
+                 *   all in [upper, end] > pivot
                  *
-                 * Pointer k is the first index of ?-part.
+                 * Pointer k is the last index of ?-part
                  */
-                outer:
-                for (int k = less - 1; ++k <= great; ) {
+                for (int k = ++upper; --k > lower; ) {
                     char ak = a[k];
-                    if (ak == pivot1) { // Move a[k] to left part
-                        a[k] = a[less];
-                        a[less] = ak;
-                        ++less;
-                    } else if (ak == pivot2) { // Move a[k] to right part
-                        while (a[great] == pivot2) {
-                            if (great-- == k) {
-                                break outer;
+
+                    if (ak != pivot) {
+                        a[k] = pivot;
+
+                        if (ak < pivot) { // Move a[k] to the left side
+                            while (a[++lower] < pivot);
+
+                            if (a[lower] > pivot) {
+                                a[--upper] = a[lower];
                             }
+                            a[lower] = ak;
+                        } else { // ak > pivot - Move a[k] to the right side
+                            a[--upper] = ak;
                         }
-                        if (a[great] == pivot1) { // a[great] < pivot2
-                            a[k] = a[less];
-                            /*
-                             * Even though a[great] equals to pivot1, the
-                             * assignment a[less] = pivot1 may be incorrect,
-                             * if a[great] and pivot1 are floating-point zeros
-                             * of different signs. Therefore in float and
-                             * double sorting methods we have to use more
-                             * accurate assignment a[less] = a[great].
-                             */
-                            a[less] = pivot1;
-                            ++less;
-                        } else { // pivot1 < a[great] < pivot2
-                            a[k] = a[great];
-                        }
-                        a[great] = ak;
-                        --great;
                     }
                 }
+
+                /*
+                 * Swap the pivot into its final position.
+                 */
+                a[low] = a[lower]; a[lower] = pivot;
+
+                /*
+                 * Sort the right part, excluding known pivot.
+                 * All elements from the central part are
+                 * equal and therefore already sorted.
+                 */
+                sort(a, bits | 1, upper, high);
             }
-
-            // Sort center part recursively
-            sort(a, less, great, false);
-
-        } else { // Partitioning with one pivot
-            /*
-             * Use the third of the five sorted elements as pivot.
-             * This value is inexpensive approximation of the median.
-             */
-            char pivot = a[e3];
-
-            /*
-             * Partitioning degenerates to the traditional 3-way
-             * (or "Dutch National Flag") schema:
-             *
-             *   left part    center part              right part
-             * +-------------------------------------------------+
-             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
-             * +-------------------------------------------------+
-             *              ^              ^        ^
-             *              |              |        |
-             *             less            k      great
-             *
-             * Invariants:
-             *
-             *   all in (left, less)   < pivot
-             *   all in [less, k)     == pivot
-             *   all in (great, right) > pivot
-             *
-             * Pointer k is the first index of ?-part.
-             */
-            for (int k = less; k <= great; ++k) {
-                if (a[k] == pivot) {
-                    continue;
-                }
-                char ak = a[k];
-                if (ak < pivot) { // Move a[k] to left part
-                    a[k] = a[less];
-                    a[less] = ak;
-                    ++less;
-                } else { // a[k] > pivot - Move a[k] to right part
-                    while (a[great] > pivot) {
-                        --great;
-                    }
-                    if (a[great] < pivot) { // a[great] <= pivot
-                        a[k] = a[less];
-                        a[less] = a[great];
-                        ++less;
-                    } else { // a[great] == pivot
-                        /*
-                         * Even though a[great] equals to pivot, the
-                         * assignment a[k] = pivot may be incorrect,
-                         * if a[great] and pivot are floating-point
-                         * zeros of different signs. Therefore in float
-                         * and double sorting methods we have to use
-                         * more accurate assignment a[k] = a[great].
-                         */
-                        a[k] = pivot;
-                    }
-                    a[great] = ak;
-                    --great;
-                }
-            }
-
-            /*
-             * Sort left and right parts recursively.
-             * All elements from center part are equal
-             * and, therefore, already sorted.
-             */
-            sort(a, left, less - 1, leftmost);
-            sort(a, great + 1, right, false);
+            high = lower; // Iterate along the left part
         }
     }
 
-    /** The number of distinct byte values. */
-    private static final int NUM_BYTE_VALUES = 1 << 8;
-
     /**
-     * Sorts the specified range of the array.
+     * Sorts the specified range of the array using insertion sort.
      *
      * @param a the array to be sorted
-     * @param left the index of the first element, inclusive, to be sorted
-     * @param right the index of the last element, inclusive, to be sorted
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
      */
-    static void sort(byte[] a, int left, int right) {
-        // Use counting sort on large arrays
-        if (right - left > COUNTING_SORT_THRESHOLD_FOR_BYTE) {
-            int[] count = new int[NUM_BYTE_VALUES];
-
-            for (int i = left - 1; ++i <= right;
-                count[a[i] - Byte.MIN_VALUE]++
-            );
-            for (int i = NUM_BYTE_VALUES, k = right + 1; k > left; ) {
-                while (count[--i] == 0);
-                byte value = (byte) (i + Byte.MIN_VALUE);
-                int s = count[i];
-
-                do {
-                    a[--k] = value;
-                } while (--s > 0);
-            }
-        } else { // Use insertion sort on small arrays
-            for (int i = left, j = i; i < right; j = ++i) {
-                byte ai = a[i + 1];
-                while (ai < a[j]) {
-                    a[j + 1] = a[j];
-                    if (j-- == left) {
-                        break;
-                    }
+    private static void insertionSort(char[] a, int low, int high) {
+        for (int i, k = low; ++k < high; ) {
+            char ai = a[i = k];
+
+            if (ai < a[i - 1]) {
+                while (--i >= low && ai < a[i]) {
+                    a[i + 1] = a[i];
                 }
-                a[j + 1] = ai;
+                a[i + 1] = ai;
             }
         }
     }
 
     /**
-     * Sorts the specified range of the array using the given
-     * workspace array slice if possible for merging
+     * The number of distinct char values.
+     */
+    private static final int NUM_CHAR_VALUES = 1 << 16;
+
+    /**
+     * Sorts the specified range of the array using counting sort.
+     *
+     * @param a the array to be sorted
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
+     */
+    private static void countingSort(char[] a, int low, int high) {
+        int[] count = new int[NUM_CHAR_VALUES];
+
+        /*
+         * Compute a histogram with the number of each values.
+         */
+        for (int i = high; i > low; ++count[a[--i]]);
+
+        /*
+         * Place values on their final positions.
+         */
+        if (high - low > NUM_CHAR_VALUES) {
+            for (int i = NUM_CHAR_VALUES; i > 0; ) {
+                for (low = high - count[--i]; high > low;
+                    a[--high] = (char) i
+                );
+            }
+        } else {
+            for (int i = NUM_CHAR_VALUES; high > low; ) {
+                while (count[--i] == 0);
+                int c = count[i];
+
+                do {
+                    a[--high] = (char) i;
+                } while (--c > 0);
+            }
+        }
+    }
+
+// [short]
+
+    /**
+     * Sorts the specified range of the array using
+     * counting sort or Dual-Pivot Quicksort.
+     *
+     * @param a the array to be sorted
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
+     */
+    static void sort(short[] a, int low, int high) {
+        if (high - low > MIN_SHORT_OR_CHAR_COUNTING_SORT_SIZE) {
+            countingSort(a, low, high);
+        } else {
+            sort(a, 0, low, high);
+        }
+    }
+
+    /**
+     * Sorts the specified array using the Dual-Pivot Quicksort and/or
+     * other sorts in special-cases, possibly with parallel partitions.
      *
      * @param a the array to be sorted
-     * @param left the index of the first element, inclusive, to be sorted
-     * @param right the index of the last element, inclusive, to be sorted
-     * @param work a workspace array (slice)
-     * @param workBase origin of usable space in work array
-     * @param workLen usable size of work array
+     * @param bits the combination of recursion depth and bit flag, where
+     *        the right bit "0" indicates that array is the leftmost part
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
      */
-    static void sort(float[] a, int left, int right,
-                     float[] work, int workBase, int workLen) {
+    static void sort(short[] a, int bits, int low, int high) {
+        while (true) {
+            int end = high - 1, size = high - low;
+
+            /*
+             * Invoke insertion sort on small leftmost part.
+             */
+            if (size < MAX_INSERTION_SORT_SIZE) {
+                insertionSort(a, low, high);
+                return;
+            }
+
+            /*
+             * Switch to counting sort if execution
+             * time is becoming quadratic.
+             */
+            if ((bits += DELTA) > MAX_RECURSION_DEPTH) {
+                countingSort(a, low, high);
+                return;
+            }
+
+            /*
+             * Use an inexpensive approximation of the golden ratio
+             * to select five sample elements and determine pivots.
+             */
+            int step = (size >> 3) * 3 + 3;
+
+            /*
+             * Five elements around (and including) the central element
+             * will be used for pivot selection as described below. The
+             * unequal choice of spacing these elements was empirically
+             * determined to work well on a wide variety of inputs.
+             */
+            int e1 = low + step;
+            int e5 = end - step;
+            int e3 = (e1 + e5) >>> 1;
+            int e2 = (e1 + e3) >>> 1;
+            int e4 = (e3 + e5) >>> 1;
+            short a3 = a[e3];
+
+            /*
+             * Sort these elements in place by the combination
+             * of 4-element sorting network and insertion sort.
+             *
+             *    5 ------o-----------o------------
+             *            |           |
+             *    4 ------|-----o-----o-----o------
+             *            |     |           |
+             *    2 ------o-----|-----o-----o------
+             *                  |     |
+             *    1 ------------o-----o------------
+             */
+            if (a[e5] < a[e2]) { short t = a[e5]; a[e5] = a[e2]; a[e2] = t; }
+            if (a[e4] < a[e1]) { short t = a[e4]; a[e4] = a[e1]; a[e1] = t; }
+            if (a[e5] < a[e4]) { short t = a[e5]; a[e5] = a[e4]; a[e4] = t; }
+            if (a[e2] < a[e1]) { short t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
+            if (a[e4] < a[e2]) { short t = a[e4]; a[e4] = a[e2]; a[e2] = t; }
+
+            if (a3 < a[e2]) {
+                if (a3 < a[e1]) {
+                    a[e3] = a[e2]; a[e2] = a[e1]; a[e1] = a3;
+                } else {
+                    a[e3] = a[e2]; a[e2] = a3;
+                }
+            } else if (a3 > a[e4]) {
+                if (a3 > a[e5]) {
+                    a[e3] = a[e4]; a[e4] = a[e5]; a[e5] = a3;
+                } else {
+                    a[e3] = a[e4]; a[e4] = a3;
+                }
+            }
+
+            // Pointers
+            int lower = low; // The index of the last element of the left part
+            int upper = end; // The index of the first element of the right part
+
+            /*
+             * Partitioning with 2 pivots in case of different elements.
+             */
+            if (a[e1] < a[e2] && a[e2] < a[e3] && a[e3] < a[e4] && a[e4] < a[e5]) {
+
+                /*
+                 * Use the first and fifth of the five sorted elements as
+                 * the pivots. These values are inexpensive approximation
+                 * of tertiles. Note, that pivot1 < pivot2.
+                 */
+                short pivot1 = a[e1];
+                short pivot2 = a[e5];
+
+                /*
+                 * The first and the last elements to be sorted are moved
+                 * to the locations formerly occupied by the pivots. When
+                 * partitioning is completed, the pivots are swapped back
+                 * into their final positions, and excluded from the next
+                 * subsequent sorting.
+                 */
+                a[e1] = a[lower];
+                a[e5] = a[upper];
+
+                /*
+                 * Skip elements, which are less or greater than the pivots.
+                 */
+                while (a[++lower] < pivot1);
+                while (a[--upper] > pivot2);
+
+                /*
+                 * Backward 3-interval partitioning
+                 *
+                 *   left part                 central part          right part
+                 * +------------------------------------------------------------+
+                 * |  < pivot1  |   ?   |  pivot1 <= && <= pivot2  |  > pivot2  |
+                 * +------------------------------------------------------------+
+                 *             ^       ^                            ^
+                 *             |       |                            |
+                 *           lower     k                          upper
+                 *
+                 * Invariants:
+                 *
+                 *              all in (low, lower] < pivot1
+                 *    pivot1 <= all in (k, upper)  <= pivot2
+                 *              all in [upper, end) > pivot2
+                 *
+                 * Pointer k is the last index of ?-part
+                 */
+                for (int unused = --lower, k = ++upper; --k > lower; ) {
+                    short ak = a[k];
+
+                    if (ak < pivot1) { // Move a[k] to the left side
+                        while (lower < k) {
+                            if (a[++lower] >= pivot1) {
+                                if (a[lower] > pivot2) {
+                                    a[k] = a[--upper];
+                                    a[upper] = a[lower];
+                                } else {
+                                    a[k] = a[lower];
+                                }
+                                a[lower] = ak;
+                                break;
+                            }
+                        }
+                    } else if (ak > pivot2) { // Move a[k] to the right side
+                        a[k] = a[--upper];
+                        a[upper] = ak;
+                    }
+                }
+
+                /*
+                 * Swap the pivots into their final positions.
+                 */
+                a[low] = a[lower]; a[lower] = pivot1;
+                a[end] = a[upper]; a[upper] = pivot2;
+
+                /*
+                 * Sort non-left parts recursively,
+                 * excluding known pivots.
+                 */
+                sort(a, bits | 1, lower + 1, upper);
+                sort(a, bits | 1, upper + 1, high);
+
+            } else { // Use single pivot in case of many equal elements
+
+                /*
+                 * Use the third of the five sorted elements as the pivot.
+                 * This value is inexpensive approximation of the median.
+                 */
+                short pivot = a[e3];
+
+                /*
+                 * The first element to be sorted is moved to the
+                 * location formerly occupied by the pivot. After
+                 * completion of partitioning the pivot is swapped
+                 * back into its final position, and excluded from
+                 * the next subsequent sorting.
+                 */
+                a[e3] = a[lower];
+
+                /*
+                 * Traditional 3-way (Dutch National Flag) partitioning
+                 *
+                 *   left part                 central part    right part
+                 * +------------------------------------------------------+
+                 * |   < pivot   |     ?     |   == pivot   |   > pivot   |
+                 * +------------------------------------------------------+
+                 *              ^           ^                ^
+                 *              |           |                |
+                 *            lower         k              upper
+                 *
+                 * Invariants:
+                 *
+                 *   all in (low, lower] < pivot
+                 *   all in (k, upper)  == pivot
+                 *   all in [upper, end] > pivot
+                 *
+                 * Pointer k is the last index of ?-part
+                 */
+                for (int k = ++upper; --k > lower; ) {
+                    short ak = a[k];
+
+                    if (ak != pivot) {
+                        a[k] = pivot;
+
+                        if (ak < pivot) { // Move a[k] to the left side
+                            while (a[++lower] < pivot);
+
+                            if (a[lower] > pivot) {
+                                a[--upper] = a[lower];
+                            }
+                            a[lower] = ak;
+                        } else { // ak > pivot - Move a[k] to the right side
+                            a[--upper] = ak;
+                        }
+                    }
+                }
+
+                /*
+                 * Swap the pivot into its final position.
+                 */
+                a[low] = a[lower]; a[lower] = pivot;
+
+                /*
+                 * Sort the right part, excluding known pivot.
+                 * All elements from the central part are
+                 * equal and therefore already sorted.
+                 */
+                sort(a, bits | 1, upper, high);
+            }
+            high = lower; // Iterate along the left part
+        }
+    }
+
+    /**
+     * Sorts the specified range of the array using insertion sort.
+     *
+     * @param a the array to be sorted
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
+     */
+    private static void insertionSort(short[] a, int low, int high) {
+        for (int i, k = low; ++k < high; ) {
+            short ai = a[i = k];
+
+            if (ai < a[i - 1]) {
+                while (--i >= low && ai < a[i]) {
+                    a[i + 1] = a[i];
+                }
+                a[i + 1] = ai;
+            }
+        }
+    }
+
+    /**
+     * The number of distinct short values.
+     */
+    private static final int NUM_SHORT_VALUES = 1 << 16;
+
+    /**
+     * Max index of short counter.
+     */
+    private static final int MAX_SHORT_INDEX = Short.MAX_VALUE + NUM_SHORT_VALUES + 1;
+
+    /**
+     * Sorts the specified range of the array using counting sort.
+     *
+     * @param a the array to be sorted
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
+     */
+    private static void countingSort(short[] a, int low, int high) {
+        int[] count = new int[NUM_SHORT_VALUES];
+
         /*
-         * Phase 1: Move NaNs to the end of the array.
+         * Compute a histogram with the number of each values.
+         */
+        for (int i = high; i > low; ++count[a[--i] & 0xFFFF]);
+
+        /*
+         * Place values on their final positions.
          */
-        while (left <= right && Float.isNaN(a[right])) {
-            --right;
+        if (high - low > NUM_SHORT_VALUES) {
+            for (int i = MAX_SHORT_INDEX; --i > Short.MAX_VALUE; ) {
+                int value = i & 0xFFFF;
+
+                for (low = high - count[value]; high > low;
+                    a[--high] = (short) value
+                );
+            }
+        } else {
+            for (int i = MAX_SHORT_INDEX; high > low; ) {
+                while (count[--i & 0xFFFF] == 0);
+
+                int value = i & 0xFFFF;
+                int c = count[value];
+
+                do {
+                    a[--high] = (short) value;
+                } while (--c > 0);
+            }
         }
-        for (int k = right; --k >= left; ) {
-            float ak = a[k];
-            if (ak != ak) { // a[k] is NaN
-                a[k] = a[right];
-                a[right] = ak;
-                --right;
+    }
+
+// [float]
+
+    /**
+     * Sorts the specified range of the array using parallel merge
+     * sort and/or Dual-Pivot Quicksort.
+     *
+     * To balance the faster splitting and parallelism of merge sort
+     * with the faster element partitioning of Quicksort, ranges are
+     * subdivided in tiers such that, if there is enough parallelism,
+     * the four-way parallel merge is started, still ensuring enough
+     * parallelism to process the partitions.
+     *
+     * @param a the array to be sorted
+     * @param parallelism the parallelism level
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
+     */
+    static void sort(float[] a, int parallelism, int low, int high) {
+        /*
+         * Phase 1. Count the number of negative zero -0.0f,
+         * turn them into positive zero, and move all NaNs
+         * to the end of the array.
+         */
+        int numNegativeZero = 0;
+
+        for (int k = high; k > low; ) {
+            float ak = a[--k];
+
+            if (ak == 0.0f && Float.floatToRawIntBits(ak) < 0) { // ak is -0.0f
+                numNegativeZero += 1;
+                a[k] = 0.0f;
+            } else if (ak != ak) { // ak is NaN
+                a[k] = a[--high];
+                a[high] = ak;
             }
         }
 
         /*
-         * Phase 2: Sort everything except NaNs (which are already in place).
+         * Phase 2. Sort everything except NaNs,
+         * which are already in place.
          */
-        doSort(a, left, right, work, workBase, workLen);
-
-        /*
-         * Phase 3: Place negative zeros before positive zeros.
-         */
-        int hi = right;
+        int size = high - low;
+
+        if (parallelism > 1 && size > MIN_PARALLEL_SORT_SIZE) {
+            int depth = getDepth(parallelism, size >> 12);
+            float[] b = depth == 0 ? null : new float[size];
+            new Sorter(null, a, b, low, size, low, depth).invoke();
+        } else {
+            sort(null, a, 0, low, high);
+        }
 
         /*
-         * Find the first zero, or first positive, or last negative element.
+         * Phase 3. Turn positive zero 0.0f
+         * back into negative zero -0.0f.
          */
-        while (left < hi) {
-            int middle = (left + hi) >>> 1;
-            float middleValue = a[middle];
-
-            if (middleValue < 0.0f) {
-                left = middle + 1;
+        if (++numNegativeZero == 1) {
+            return;
+        }
+
+        /*
+         * Find the position one less than
+         * the index of the first zero.
+         */
+        while (low <= high) {
+            int middle = (low + high) >>> 1;
+
+            if (a[middle] < 0) {
+                low = middle + 1;
             } else {
-                hi = middle;
+                high = middle - 1;
             }
         }
 
         /*
-         * Skip the last negative value (if any) or all leading negative zeros.
+         * Replace the required number of 0.0f by -0.0f.
          */
-        while (left <= right && Float.floatToRawIntBits(a[left]) < 0) {
-            ++left;
+        while (--numNegativeZero > 0) {
+            a[++high] = -0.0f;
         }
-
-        /*
-         * Move negative zeros to the beginning of the sub-range.
-         *
-         * Partitioning:
-         *
-         * +----------------------------------------------------+
-         * |   < 0.0   |   -0.0   |   0.0   |   ?  ( >= 0.0 )   |
-         * +----------------------------------------------------+
-         *              ^          ^         ^
-         *              |          |         |
-         *             left        p         k
-         *
-         * Invariants:
-         *
-         *   all in (*,  left)  <  0.0
-         *   all in [left,  p) == -0.0
-         *   all in [p,     k) ==  0.0
-         *   all in [k, right] >=  0.0
-         *
-         * Pointer k is the first index of ?-part.
-         */
-        for (int k = left, p = left - 1; ++k <= right; ) {
-            float ak = a[k];
-            if (ak != 0.0f) {
-                break;
+    }
+
+    /**
+     * Sorts the specified array using the Dual-Pivot Quicksort and/or
+     * other sorts in special-cases, possibly with parallel partitions.
+     *
+     * @param sorter parallel context
+     * @param a the array to be sorted
+     * @param bits the combination of recursion depth and bit flag, where
+     *        the right bit "0" indicates that array is the leftmost part
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
+     */
+    static void sort(Sorter sorter, float[] a, int bits, int low, int high) {
+        while (true) {
+            int end = high - 1, size = high - low;
+
+            /*
+             * Run mixed insertion sort on small non-leftmost parts.
+             */
+            if (size < MAX_MIXED_INSERTION_SORT_SIZE + bits && (bits & 1) > 0) {
+                mixedInsertionSort(a, low, high - 3 * ((size >> 5) << 3), high);
+                return;
+            }
+
+            /*
+             * Invoke insertion sort on small leftmost part.
+             */
+            if (size < MAX_INSERTION_SORT_SIZE) {
+                insertionSort(a, low, high);
+                return;
+            }
+
+            /*
+             * Check if the whole array or large non-leftmost
+             * parts are nearly sorted and then merge runs.
+             */
+            if ((bits == 0 || size > MIN_TRY_MERGE_SIZE && (bits & 1) > 0)
+                    && tryMergeRuns(sorter, a, low, size)) {
+                return;
+            }
+
+            /*
+             * Switch to heap sort if execution
+             * time is becoming quadratic.
+             */
+            if ((bits += DELTA) > MAX_RECURSION_DEPTH) {
+                heapSort(a, low, high);
+                return;
+            }
+
+            /*
+             * Use an inexpensive approximation of the golden ratio
+             * to select five sample elements and determine pivots.
+             */
+            int step = (size >> 3) * 3 + 3;
+
+            /*
+             * Five elements around (and including) the central element
+             * will be used for pivot selection as described below. The
+             * unequal choice of spacing these elements was empirically
+             * determined to work well on a wide variety of inputs.
+             */
+            int e1 = low + step;
+            int e5 = end - step;
+            int e3 = (e1 + e5) >>> 1;
+            int e2 = (e1 + e3) >>> 1;
+            int e4 = (e3 + e5) >>> 1;
+            float a3 = a[e3];
+
+            /*
+             * Sort these elements in place by the combination
+             * of 4-element sorting network and insertion sort.
+             *
+             *    5 ------o-----------o------------
+             *            |           |
+             *    4 ------|-----o-----o-----o------
+             *            |     |           |
+             *    2 ------o-----|-----o-----o------
+             *                  |     |
+             *    1 ------------o-----o------------
+             */
+            if (a[e5] < a[e2]) { float t = a[e5]; a[e5] = a[e2]; a[e2] = t; }
+            if (a[e4] < a[e1]) { float t = a[e4]; a[e4] = a[e1]; a[e1] = t; }
+            if (a[e5] < a[e4]) { float t = a[e5]; a[e5] = a[e4]; a[e4] = t; }
+            if (a[e2] < a[e1]) { float t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
+            if (a[e4] < a[e2]) { float t = a[e4]; a[e4] = a[e2]; a[e2] = t; }
+
+            if (a3 < a[e2]) {
+                if (a3 < a[e1]) {
+                    a[e3] = a[e2]; a[e2] = a[e1]; a[e1] = a3;
+                } else {
+                    a[e3] = a[e2]; a[e2] = a3;
+                }
+            } else if (a3 > a[e4]) {
+                if (a3 > a[e5]) {
+                    a[e3] = a[e4]; a[e4] = a[e5]; a[e5] = a3;
+                } else {
+                    a[e3] = a[e4]; a[e4] = a3;
+                }
             }
-            if (Float.floatToRawIntBits(ak) < 0) { // ak is -0.0f
-                a[k] = 0.0f;
-                a[++p] = -0.0f;
+
+            // Pointers
+            int lower = low; // The index of the last element of the left part
+            int upper = end; // The index of the first element of the right part
+
+            /*
+             * Partitioning with 2 pivots in case of different elements.
+             */
+            if (a[e1] < a[e2] && a[e2] < a[e3] && a[e3] < a[e4] && a[e4] < a[e5]) {
+
+                /*
+                 * Use the first and fifth of the five sorted elements as
+                 * the pivots. These values are inexpensive approximation
+                 * of tertiles. Note, that pivot1 < pivot2.
+                 */
+                float pivot1 = a[e1];
+                float pivot2 = a[e5];
+
+                /*
+                 * The first and the last elements to be sorted are moved
+                 * to the locations formerly occupied by the pivots. When
+                 * partitioning is completed, the pivots are swapped back
+                 * into their final positions, and excluded from the next
+                 * subsequent sorting.
+                 */
+                a[e1] = a[lower];
+                a[e5] = a[upper];
+
+                /*
+                 * Skip elements, which are less or greater than the pivots.
+                 */
+                while (a[++lower] < pivot1);
+                while (a[--upper] > pivot2);
+
+                /*
+                 * Backward 3-interval partitioning
+                 *
+                 *   left part                 central part          right part
+                 * +------------------------------------------------------------+
+                 * |  < pivot1  |   ?   |  pivot1 <= && <= pivot2  |  > pivot2  |
+                 * +------------------------------------------------------------+
+                 *             ^       ^                            ^
+                 *             |       |                            |
+                 *           lower     k                          upper
+                 *
+                 * Invariants:
+                 *
+                 *              all in (low, lower] < pivot1
+                 *    pivot1 <= all in (k, upper)  <= pivot2
+                 *              all in [upper, end) > pivot2
+                 *
+                 * Pointer k is the last index of ?-part
+                 */
+                for (int unused = --lower, k = ++upper; --k > lower; ) {
+                    float ak = a[k];
+
+                    if (ak < pivot1) { // Move a[k] to the left side
+                        while (lower < k) {
+                            if (a[++lower] >= pivot1) {
+                                if (a[lower] > pivot2) {
+                                    a[k] = a[--upper];
+                                    a[upper] = a[lower];
+                                } else {
+                                    a[k] = a[lower];
+                                }
+                                a[lower] = ak;
+                                break;
+                            }
+                        }
+                    } else if (ak > pivot2) { // Move a[k] to the right side
+                        a[k] = a[--upper];
+                        a[upper] = ak;
+                    }
+                }
+
+                /*
+                 * Swap the pivots into their final positions.
+                 */
+                a[low] = a[lower]; a[lower] = pivot1;
+                a[end] = a[upper]; a[upper] = pivot2;
+
+                /*
+                 * Sort non-left parts recursively (possibly in parallel),
+                 * excluding known pivots.
+                 */
+                if (size > MIN_PARALLEL_SORT_SIZE && sorter != null) {
+                    sorter.forkSorter(bits | 1, lower + 1, upper);
+                    sorter.forkSorter(bits | 1, upper + 1, high);
+                } else {
+                    sort(sorter, a, bits | 1, lower + 1, upper);
+                    sort(sorter, a, bits | 1, upper + 1, high);
+                }
+
+            } else { // Use single pivot in case of many equal elements
+
+                /*
+                 * Use the third of the five sorted elements as the pivot.
+                 * This value is inexpensive approximation of the median.
+                 */
+                float pivot = a[e3];
+
+                /*
+                 * The first element to be sorted is moved to the
+                 * location formerly occupied by the pivot. After
+                 * completion of partitioning the pivot is swapped
+                 * back into its final position, and excluded from
+                 * the next subsequent sorting.
+                 */
+                a[e3] = a[lower];
+
+                /*
+                 * Traditional 3-way (Dutch National Flag) partitioning
+                 *
+                 *   left part                 central part    right part
+                 * +------------------------------------------------------+
+                 * |   < pivot   |     ?     |   == pivot   |   > pivot   |
+                 * +------------------------------------------------------+
+                 *              ^           ^                ^
+                 *              |           |                |
+                 *            lower         k              upper
+                 *
+                 * Invariants:
+                 *
+                 *   all in (low, lower] < pivot
+                 *   all in (k, upper)  == pivot
+                 *   all in [upper, end] > pivot
+                 *
+                 * Pointer k is the last index of ?-part
+                 */
+                for (int k = ++upper; --k > lower; ) {
+                    float ak = a[k];
+
+                    if (ak != pivot) {
+                        a[k] = pivot;
+
+                        if (ak < pivot) { // Move a[k] to the left side
+                            while (a[++lower] < pivot);
+
+                            if (a[lower] > pivot) {
+                                a[--upper] = a[lower];
+                            }
+                            a[lower] = ak;
+                        } else { // ak > pivot - Move a[k] to the right side
+                            a[--upper] = ak;
+                        }
+                    }
+                }
+
+                /*
+                 * Swap the pivot into its final position.
+                 */
+                a[low] = a[lower]; a[lower] = pivot;
+
+                /*
+                 * Sort the right part (possibly in parallel), excluding
+                 * known pivot. All elements from the central part are
+                 * equal and therefore already sorted.
+                 */
+                if (size > MIN_PARALLEL_SORT_SIZE && sorter != null) {
+                    sorter.forkSorter(bits | 1, upper, high);
+                } else {
+                    sort(sorter, a, bits | 1, upper, high);
+                }
+            }
+            high = lower; // Iterate along the left part
+        }
+    }
+
+    /**
+     * Sorts the specified range of the array using mixed insertion sort.
+     *
+     * Mixed insertion sort is combination of simple insertion sort,
+     * pin insertion sort and pair insertion sort.
+     *
+     * In the context of Dual-Pivot Quicksort, the pivot element
+     * from the left part plays the role of sentinel, because it
+     * is less than any elements from the given part. Therefore,
+     * expensive check of the left range can be skipped on each
+     * iteration unless it is the leftmost call.
+     *
+     * @param a the array to be sorted
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param end the index of the last element for simple insertion sort
+     * @param high the index of the last element, exclusive, to be sorted
+     */
+    private static void mixedInsertionSort(float[] a, int low, int end, int high) {
+        if (end == high) {
+
+            /*
+             * Invoke simple insertion sort on tiny array.
+             */
+            for (int i; ++low < end; ) {
+                float ai = a[i = low];
+
+                while (ai < a[--i]) {
+                    a[i + 1] = a[i];
+                }
+                a[i + 1] = ai;
+            }
+        } else {
+
+            /*
+             * Start with pin insertion sort on small part.
+             *
+             * Pin insertion sort is extended simple insertion sort.
+             * The main idea of this sort is to put elements larger
+             * than an element called pin to the end of array (the
+             * proper area for such elements). It avoids expensive
+             * movements of these elements through the whole array.
+             */
+            float pin = a[end];
+
+            for (int i, p = high; ++low < end; ) {
+                float ai = a[i = low];
+
+                if (ai < a[i - 1]) { // Small element
+
+                    /*
+                     * Insert small element into sorted part.
+                     */
+                    a[i] = a[--i];
+
+                    while (ai < a[--i]) {
+                        a[i + 1] = a[i];
+                    }
+                    a[i + 1] = ai;
+
+                } else if (p > i && ai > pin) { // Large element
+
+                    /*
+                     * Find element smaller than pin.
+                     */
+                    while (a[--p] > pin);
+
+                    /*
+                     * Swap it with large element.
+                     */
+                    if (p > i) {
+                        ai = a[p];
+                        a[p] = a[i];
+                    }
+
+                    /*
+                     * Insert small element into sorted part.
+                     */
+                    while (ai < a[--i]) {
+                        a[i + 1] = a[i];
+                    }
+                    a[i + 1] = ai;
+                }
+            }
+
+            /*
+             * Continue with pair insertion sort on remain part.
+             */
+            for (int i; low < high; ++low) {
+                float a1 = a[i = low], a2 = a[++low];
+
+                /*
+                 * Insert two elements per iteration: at first, insert the
+                 * larger element and then insert the smaller element, but
+                 * from the position where the larger element was inserted.
+                 */
+                if (a1 > a2) {
+
+                    while (a1 < a[--i]) {
+                        a[i + 2] = a[i];
+                    }
+                    a[++i + 1] = a1;
+
+                    while (a2 < a[--i]) {
+                        a[i + 1] = a[i];
+                    }
+                    a[i + 1] = a2;
+
+                } else if (a1 < a[i - 1]) {
+
+                    while (a2 < a[--i]) {
+                        a[i + 2] = a[i];
+                    }
+                    a[++i + 1] = a2;
+
+                    while (a1 < a[--i]) {
+                        a[i + 1] = a[i];
+                    }
+                    a[i + 1] = a1;
+                }
+            }
+        }
+    }
+
+    /**
+     * Sorts the specified range of the array using insertion sort.
+     *
+     * @param a the array to be sorted
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
+     */
+    private static void insertionSort(float[] a, int low, int high) {
+        for (int i, k = low; ++k < high; ) {
+            float ai = a[i = k];
+
+            if (ai < a[i - 1]) {
+                while (--i >= low && ai < a[i]) {
+                    a[i + 1] = a[i];
+                }
+                a[i + 1] = ai;
             }
         }
     }
 
     /**
-     * Sorts the specified range of the array.
+     * Sorts the specified range of the array using heap sort.
      *
      * @param a the array to be sorted
-     * @param left the index of the first element, inclusive, to be sorted
-     * @param right the index of the last element, inclusive, to be sorted
-     * @param work a workspace array (slice)
-     * @param workBase origin of usable space in work array
-     * @param workLen usable size of work array
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
      */
-    private static void doSort(float[] a, int left, int right,
-                               float[] work, int workBase, int workLen) {
-        // Use Quicksort on small arrays
-        if (right - left < QUICKSORT_THRESHOLD) {
-            sort(a, left, right, true);
-            return;
-        }
-
-        /*
-         * Index run[i] is the start of i-th run
-         * (ascending or descending sequence).
-         */
-        int[] run = new int[MAX_RUN_COUNT + 1];
-        int count = 0; run[0] = left;
-
-        // Check if the array is nearly sorted
-        for (int k = left; k < right; run[count] = k) {
-            // Equal items in the beginning of the sequence
-            while (k < right && a[k] == a[k + 1])
-                k++;
-            if (k == right) break;  // Sequence finishes with equal items
-            if (a[k] < a[k + 1]) { // ascending
-                while (++k <= right && a[k - 1] <= a[k]);
-            } else if (a[k] > a[k + 1]) { // descending
-                while (++k <= right && a[k - 1] >= a[k]);
-                // Transform into an ascending sequence
-                for (int lo = run[count] - 1, hi = k; ++lo < --hi; ) {
-                    float t = a[lo]; a[lo] = a[hi]; a[hi] = t;
-                }
-            }
-
-            // Merge a transformed descending sequence followed by an
-            // ascending sequence
-            if (run[count] > left && a[run[count]] >= a[run[count] - 1]) {
-                count--;
-            }
-
-            /*
-             * The array is not highly structured,
-             * use Quicksort instead of merge sort.
-             */
-            if (++count == MAX_RUN_COUNT) {
-                sort(a, left, right, true);
-                return;
-            }
+    private static void heapSort(float[] a, int low, int high) {
+        for (int k = (low + high) >>> 1; k > low; ) {
+            pushDown(a, --k, a[k], low, high);
         }
-
-        // These invariants should hold true:
-        //    run[0] = 0
-        //    run[<last>] = right + 1; (terminator)
-
-        if (count == 0) {
-            // A single equal run
-            return;
-        } else if (count == 1 && run[count] > right) {
-            // Either a single ascending or a transformed descending run.
-            // Always check that a final run is a proper terminator, otherwise
-            // we have an unterminated trailing run, to handle downstream.
-            return;
-        }
-        right++;
-        if (run[count] < right) {
-            // Corner case: the final run is not a terminator. This may happen
-            // if a final run is an equals run, or there is a single-element run
-            // at the end. Fix up by adding a proper terminator at the end.
-            // Note that we terminate with (right + 1), incremented earlier.
-            run[++count] = right;
-        }
-
-        // Determine alternation base for merge
-        byte odd = 0;
-        for (int n = 1; (n <<= 1) < count; odd ^= 1);
-
-        // Use or create temporary array b for merging
-        float[] b;                 // temp array; alternates with a
-        int ao, bo;              // array offsets from 'left'
-        int blen = right - left; // space needed for b
-        if (work == null || workLen < blen || workBase + blen > work.length) {
-            work = new float[blen];
-            workBase = 0;
-        }
-        if (odd == 0) {
-            System.arraycopy(a, left, work, workBase, blen);
-            b = a;
-            bo = 0;
-            a = work;
-            ao = workBase - left;
-        } else {
-            b = work;
-            ao = 0;
-            bo = workBase - left;
-        }
-
-        // Merging
-        for (int last; count > 1; count = last) {
-            for (int k = (last = 0) + 2; k <= count; k += 2) {
-                int hi = run[k], mi = run[k - 1];
-                for (int i = run[k - 2], p = i, q = mi; i < hi; ++i) {
-                    if (q >= hi || p < mi && a[p + ao] <= a[q + ao]) {
-                        b[i + bo] = a[p++ + ao];
-                    } else {
-                        b[i + bo] = a[q++ + ao];
-                    }
-                }
-                run[++last] = hi;
-            }
-            if ((count & 1) != 0) {
-                for (int i = right, lo = run[count - 1]; --i >= lo;
-                    b[i + bo] = a[i + ao]
-                );
-                run[++last] = right;
-            }
-            float[] t = a; a = b; b = t;
-            int o = ao; ao = bo; bo = o;
+        while (--high > low) {
+            float max = a[low];
+            pushDown(a, low, a[high], low, high);
+            a[high] = max;
         }
     }
 
     /**
-     * Sorts the specified range of the array by Dual-Pivot Quicksort.
+     * Pushes specified element down during heap sort.
      *
-     * @param a the array to be sorted
-     * @param left the index of the first element, inclusive, to be sorted
-     * @param right the index of the last element, inclusive, to be sorted
-     * @param leftmost indicates if this part is the leftmost in the range
+     * @param a the given array
+     * @param p the start index
+     * @param value the given element
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
      */
-    private static void sort(float[] a, int left, int right, boolean leftmost) {
-        int length = right - left + 1;
-
-        // Use insertion sort on tiny arrays
-        if (length < INSERTION_SORT_THRESHOLD) {
-            if (leftmost) {
-                /*
-                 * Traditional (without sentinel) insertion sort,
-                 * optimized for server VM, is used in case of
-                 * the leftmost part.
-                 */
-                for (int i = left, j = i; i < right; j = ++i) {
-                    float ai = a[i + 1];
-                    while (ai < a[j]) {
-                        a[j + 1] = a[j];
-                        if (j-- == left) {
-                            break;
-                        }
-                    }
-                    a[j + 1] = ai;
-                }
-            } else {
-                /*
-                 * Skip the longest ascending sequence.
-                 */
-                do {
-                    if (left >= right) {
-                        return;
-                    }
-                } while (a[++left] >= a[left - 1]);
-
-                /*
-                 * Every element from adjoining part plays the role
-                 * of sentinel, therefore this allows us to avoid the
-                 * left range check on each iteration. Moreover, we use
-                 * the more optimized algorithm, so called pair insertion
-                 * sort, which is faster (in the context of Quicksort)
-                 * than traditional implementation of insertion sort.
-                 */
-                for (int k = left; ++left <= right; k = ++left) {
-                    float a1 = a[k], a2 = a[left];
-
-                    if (a1 < a2) {
-                        a2 = a1; a1 = a[left];
-                    }
-                    while (a1 < a[--k]) {
-                        a[k + 2] = a[k];
-                    }
-                    a[++k + 1] = a1;
-
-                    while (a2 < a[--k]) {
-                        a[k + 1] = a[k];
-                    }
-                    a[k + 1] = a2;
-                }
-                float last = a[right];
-
-                while (last < a[--right]) {
-                    a[right + 1] = a[right];
-                }
-                a[right + 1] = last;
+    private static void pushDown(float[] a, int p, float value, int low, int high) {
+        for (int k ;; a[p] = a[p = k]) {
+            k = (p << 1) - low + 2; // Index of the right child
+
+            if (k > high) {
+                break;
+            }
+            if (k == high || a[k] < a[k - 1]) {
+                --k;
+            }
+            if (a[k] <= value) {
+                break;
             }
-            return;
         }
-
-        // Inexpensive approximation of length / 7
-        int seventh = (length >> 3) + (length >> 6) + 1;
+        a[p] = value;
+    }
+
+    /**
+     * Tries to sort the specified range of the array.
+     *
+     * @param sorter parallel context
+     * @param a the array to be sorted
+     * @param low the index of the first element to be sorted
+     * @param size the array size
+     * @return true if finally sorted, false otherwise
+     */
+    private static boolean tryMergeRuns(Sorter sorter, float[] a, int low, int size) {
 
         /*
-         * Sort five evenly spaced elements around (and including) the
-         * center element in the range. These elements will be used for
-         * pivot selection as described below. The choice for spacing
-         * these elements was empirically determined to work well on
-         * a wide variety of inputs.
+         * The run array is constructed only if initial runs are
+         * long enough to continue, run[i] then holds start index
+         * of the i-th sequence of elements in non-descending order.
          */
-        int e3 = (left + right) >>> 1; // The midpoint
-        int e2 = e3 - seventh;
-        int e1 = e2 - seventh;
-        int e4 = e3 + seventh;
-        int e5 = e4 + seventh;
-
-        // Sort these elements using insertion sort
-        if (a[e2] < a[e1]) { float t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
-
-        if (a[e3] < a[e2]) { float t = a[e3]; a[e3] = a[e2]; a[e2] = t;
-            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
-        }
-        if (a[e4] < a[e3]) { float t = a[e4]; a[e4] = a[e3]; a[e3] = t;
-            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
-                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
-            }
-        }
-        if (a[e5] < a[e4]) { float t = a[e5]; a[e5] = a[e4]; a[e4] = t;
-            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
-                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
-                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
-                }
-            }
-        }
-
-        // Pointers
-        int less  = left;  // The index of the first element of center part
-        int great = right; // The index before the first element of right part
-
-        if (a[e1] != a[e2] && a[e2] != a[e3] && a[e3] != a[e4] && a[e4] != a[e5]) {
-            /*
-             * Use the second and fourth of the five sorted elements as pivots.
-             * These values are inexpensive approximations of the first and
-             * second terciles of the array. Note that pivot1 <= pivot2.
-             */
-            float pivot1 = a[e2];
-            float pivot2 = a[e4];
-
-            /*
-             * The first and the last elements to be sorted are moved to the
-             * locations formerly occupied by the pivots. When partitioning
-             * is complete, the pivots are swapped back into their final
-             * positions, and excluded from subsequent sorting.
-             */
-            a[e2] = a[left];
-            a[e4] = a[right];
-
-            /*
-             * Skip elements, which are less or greater than pivot values.
-             */
-            while (a[++less] < pivot1);
-            while (a[--great] > pivot2);
+        int[] run = null;
+        int high = low + size;
+        int count = 1, last = low;
+
+        /*
+         * Identify all possible runs.
+         */
+        for (int k = low + 1; k < high; ) {
 
             /*
-             * Partitioning:
-             *
-             *   left part           center part                   right part
-             * +--------------------------------------------------------------+
-             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
-             * +--------------------------------------------------------------+
-             *               ^                          ^       ^
-             *               |                          |       |
-             *              less                        k     great
-             *
-             * Invariants:
-             *
-             *              all in (left, less)   < pivot1
-             *    pivot1 <= all in [less, k)     <= pivot2
-             *              all in (great, right) > pivot2
-             *
-             * Pointer k is the first index of ?-part.
+             * Find the end index of the current run.
              */
-            outer:
-            for (int k = less - 1; ++k <= great; ) {
-                float ak = a[k];
-                if (ak < pivot1) { // Move a[k] to left part
-                    a[k] = a[less];
-                    /*
-                     * Here and below we use "a[i] = b; i++;" instead
-                     * of "a[i++] = b;" due to performance issue.
-                     */
-                    a[less] = ak;
-                    ++less;
-                } else if (ak > pivot2) { // Move a[k] to right part
-                    while (a[great] > pivot2) {
-                        if (great-- == k) {
-                            break outer;
-                        }
-                    }
-                    if (a[great] < pivot1) { // a[great] <= pivot2
-                        a[k] = a[less];
-                        a[less] = a[great];
-                        ++less;
-                    } else { // pivot1 <= a[great] <= pivot2
-                        a[k] = a[great];
-                    }
-                    /*
-                     * Here and below we use "a[i] = b; i--;" instead
-                     * of "a[i--] = b;" due to performance issue.
-                     */
-                    a[great] = ak;
-                    --great;
-                }
-            }
-
-            // Swap pivots into their final positions
-            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
-            a[right] = a[great + 1]; a[great + 1] = pivot2;
-
-            // Sort left and right parts recursively, excluding known pivots
-            sort(a, left, less - 2, leftmost);
-            sort(a, great + 2, right, false);
-
-            /*
-             * If center part is too large (comprises > 4/7 of the array),
-             * swap internal pivot values to ends.
-             */
-            if (less < e1 && e5 < great) {
-                /*
-                 * Skip elements, which are equal to pivot values.
-                 */
-                while (a[less] == pivot1) {
-                    ++less;
-                }
-
-                while (a[great] == pivot2) {
-                    --great;
+            if (a[k - 1] < a[k]) {
+
+                // Identify ascending sequence
+                while (++k < high && a[k - 1] <= a[k]);
+
+            } else if (a[k - 1] > a[k]) {
+
+                // Identify descending sequence
+                while (++k < high && a[k - 1] >= a[k]);
+
+                // Reverse into ascending order
+                for (int i = last - 1, j = k; ++i < --j && a[i] > a[j]; ) {
+                    float ai = a[i]; a[i] = a[j]; a[j] = ai;
                 }
-
-                /*
-                 * Partitioning:
-                 *
-                 *   left part         center part                  right part
-                 * +----------------------------------------------------------+
-                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
-                 * +----------------------------------------------------------+
-                 *              ^                        ^       ^
-                 *              |                        |       |
-                 *             less                      k     great
-                 *
-                 * Invariants:
-                 *
-                 *              all in (*,  less) == pivot1
-                 *     pivot1 < all in [less,  k)  < pivot2
-                 *              all in (great, *) == pivot2
-                 *
-                 * Pointer k is the first index of ?-part.
-                 */
-                outer:
-                for (int k = less - 1; ++k <= great; ) {
-                    float ak = a[k];
-                    if (ak == pivot1) { // Move a[k] to left part
-                        a[k] = a[less];
-                        a[less] = ak;
-                        ++less;
-                    } else if (ak == pivot2) { // Move a[k] to right part
-                        while (a[great] == pivot2) {
-                            if (great-- == k) {
-                                break outer;
-                            }
-                        }
-                        if (a[great] == pivot1) { // a[great] < pivot2
-                            a[k] = a[less];
-                            /*
-                             * Even though a[great] equals to pivot1, the
-                             * assignment a[less] = pivot1 may be incorrect,
-                             * if a[great] and pivot1 are floating-point zeros
-                             * of different signs. Therefore in float and
-                             * double sorting methods we have to use more
-                             * accurate assignment a[less] = a[great].
-                             */
-                            a[less] = a[great];
-                            ++less;
-                        } else { // pivot1 < a[great] < pivot2
-                            a[k] = a[great];
-                        }
-                        a[great] = ak;
-                        --great;
-                    }
-                }
-            }
-
-            // Sort center part recursively
-            sort(a, less, great, false);
-
-        } else { // Partitioning with one pivot
-            /*
-             * Use the third of the five sorted elements as pivot.
-             * This value is inexpensive approximation of the median.
-             */
-            float pivot = a[e3];
-
-            /*
-             * Partitioning degenerates to the traditional 3-way
-             * (or "Dutch National Flag") schema:
-             *
-             *   left part    center part              right part
-             * +-------------------------------------------------+
-             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
-             * +-------------------------------------------------+
-             *              ^              ^        ^
-             *              |              |        |
-             *             less            k      great
-             *
-             * Invariants:
-             *
-             *   all in (left, less)   < pivot
-             *   all in [less, k)     == pivot
-             *   all in (great, right) > pivot
-             *
-             * Pointer k is the first index of ?-part.
-             */
-            for (int k = less; k <= great; ++k) {
-                if (a[k] == pivot) {
+            } else { // Identify constant sequence
+                for (float ak = a[k]; ++k < high && ak == a[k]; );
+
+                if (k < high) {
                     continue;
                 }
-                float ak = a[k];
-                if (ak < pivot) { // Move a[k] to left part
-                    a[k] = a[less];
-                    a[less] = ak;
-                    ++less;
-                } else { // a[k] > pivot - Move a[k] to right part
-                    while (a[great] > pivot) {
-                        --great;
-                    }
-                    if (a[great] < pivot) { // a[great] <= pivot
-                        a[k] = a[less];
-                        a[less] = a[great];
-                        ++less;
-                    } else { // a[great] == pivot
-                        /*
-                         * Even though a[great] equals to pivot, the
-                         * assignment a[k] = pivot may be incorrect,
-                         * if a[great] and pivot are floating-point
-                         * zeros of different signs. Therefore in float
-                         * and double sorting methods we have to use
-                         * more accurate assignment a[k] = a[great].
-                         */
-                        a[k] = a[great];
-                    }
-                    a[great] = ak;
-                    --great;
-                }
             }
 
             /*
-             * Sort left and right parts recursively.
-             * All elements from center part are equal
-             * and, therefore, already sorted.
+             * Check special cases.
              */
-            sort(a, left, less - 1, leftmost);
-            sort(a, great + 1, right, false);
+            if (run == null) {
+                if (k == high) {
+
+                    /*
+                     * The array is monotonous sequence,
+                     * and therefore already sorted.
+                     */
+                    return true;
+                }
+
+                if (k - low < MIN_FIRST_RUN_SIZE) {
+
+                    /*
+                     * The first run is too small
+                     * to proceed with scanning.
+                     */
+                    return false;
+                }
+
+                run = new int[((size >> 10) | 0x7F) & 0x3FF];
+                run[0] = low;
+
+            } else if (a[last - 1] > a[last]) {
+
+                if (count > (k - low) >> MIN_FIRST_RUNS_FACTOR) {
+
+                    /*
+                     * The first runs are not long
+                     * enough to continue scanning.
+                     */
+                    return false;
+                }
+
+                if (++count == MAX_RUN_CAPACITY) {
+
+                    /*
+                     * Array is not highly structured.
+                     */
+                    return false;
+                }
+
+                if (count == run.length) {
+
+                    /*
+                     * Increase capacity of index array.
+                     */
+                    run = Arrays.copyOf(run, count << 1);
+                }
+            }
+            run[count] = (last = k);
         }
+
+        /*
+         * Merge runs of highly structured array.
+         */
+        if (count > 1) {
+            float[] b; int offset = low;
+
+            if (sorter == null || (b = (float[]) sorter.b) == null) {
+                b = new float[size];
+            } else {
+                offset = sorter.offset;
+            }
+            mergeRuns(a, b, offset, 1, sorter != null, run, 0, count);
+        }
+        return true;
+    }
+
+    /**
+     * Merges the specified runs.
+     *
+     * @param a the source array
+     * @param b the temporary buffer used in merging
+     * @param offset the start index in the source, inclusive
+     * @param aim specifies merging: to source ( > 0), buffer ( < 0) or any ( == 0)
+     * @param parallel indicates whether merging is performed in parallel
+     * @param run the start indexes of the runs, inclusive
+     * @param lo the start index of the first run, inclusive
+     * @param hi the start index of the last run, inclusive
+     * @return the destination where runs are merged
+     */
+    private static float[] mergeRuns(float[] a, float[] b, int offset,
+            int aim, boolean parallel, int[] run, int lo, int hi) {
+
+        if (hi - lo == 1) {
+            if (aim >= 0) {
+                return a;
+            }
+            for (int i = run[hi], j = i - offset, low = run[lo]; i > low;
+                b[--j] = a[--i]
+            );
+            return b;
+        }
+
+        /*
+         * Split into approximately equal parts.
+         */
+        int mi = lo, rmi = (run[lo] + run[hi]) >>> 1;
+        while (run[++mi + 1] <= rmi);
+
+        /*
+         * Merge the left and right parts.
+         */
+        float[] a1, a2;
+
+        if (parallel && hi - lo > MIN_RUN_COUNT) {
+            RunMerger merger = new RunMerger(a, b, offset, 0, run, mi, hi).forkMe();
+            a1 = mergeRuns(a, b, offset, -aim, true, run, lo, mi);
+            a2 = (float[]) merger.getDestination();
+        } else {
+            a1 = mergeRuns(a, b, offset, -aim, false, run, lo, mi);
+            a2 = mergeRuns(a, b, offset,    0, false, run, mi, hi);
+        }
+
+        float[] dst = a1 == a ? b : a;
+
+        int k   = a1 == a ? run[lo] - offset : run[lo];
+        int lo1 = a1 == b ? run[lo] - offset : run[lo];
+        int hi1 = a1 == b ? run[mi] - offset : run[mi];
+        int lo2 = a2 == b ? run[mi] - offset : run[mi];
+        int hi2 = a2 == b ? run[hi] - offset : run[hi];
+
+        if (parallel) {
+            new Merger(null, dst, k, a1, lo1, hi1, a2, lo2, hi2).invoke();
+        } else {
+            mergeParts(null, dst, k, a1, lo1, hi1, a2, lo2, hi2);
+        }
+        return dst;
     }
 
     /**
-     * Sorts the specified range of the array using the given
-     * workspace array slice if possible for merging
+     * Merges the sorted parts.
+     *
+     * @param merger parallel context
+     * @param dst the destination where parts are merged
+     * @param k the start index of the destination, inclusive
+     * @param a1 the first part
+     * @param lo1 the start index of the first part, inclusive
+     * @param hi1 the end index of the first part, exclusive
+     * @param a2 the second part
+     * @param lo2 the start index of the second part, inclusive
+     * @param hi2 the end index of the second part, exclusive
+     */
+    private static void mergeParts(Merger merger, float[] dst, int k,
+            float[] a1, int lo1, int hi1, float[] a2, int lo2, int hi2) {
+
+        if (merger != null && a1 == a2) {
+
+            while (true) {
+
+                /*
+                 * The first part must be larger.
+                 */
+                if (hi1 - lo1 < hi2 - lo2) {
+                    int lo = lo1; lo1 = lo2; lo2 = lo;
+                    int hi = hi1; hi1 = hi2; hi2 = hi;
+                }
+
+                /*
+                 * Small parts will be merged sequentially.
+                 */
+                if (hi1 - lo1 < MIN_PARALLEL_MERGE_PARTS_SIZE) {
+                    break;
+                }
+
+                /*
+                 * Find the median of the larger part.
+                 */
+                int mi1 = (lo1 + hi1) >>> 1;
+                float key = a1[mi1];
+                int mi2 = hi2;
+
+                /*
+                 * Partition the smaller part.
+                 */
+                for (int loo = lo2; loo < mi2; ) {
+                    int t = (loo + mi2) >>> 1;
+
+                    if (key > a2[t]) {
+                        loo = t + 1;
+                    } else {
+                        mi2 = t;
+                    }
+                }
+
+                int d = mi2 - lo2 + mi1 - lo1;
+
+                /*
+                 * Merge the right sub-parts in parallel.
+                 */
+                merger.forkMerger(dst, k + d, a1, mi1, hi1, a2, mi2, hi2);
+
+                /*
+                 * Process the sub-left parts.
+                 */
+                hi1 = mi1;
+                hi2 = mi2;
+            }
+        }
+
+        /*
+         * Merge small parts sequentially.
+         */
+        while (lo1 < hi1 && lo2 < hi2) {
+            dst[k++] = a1[lo1] < a2[lo2] ? a1[lo1++] : a2[lo2++];
+        }
+        if (dst != a1 || k < lo1) {
+            while (lo1 < hi1) {
+                dst[k++] = a1[lo1++];
+            }
+        }
+        if (dst != a2 || k < lo2) {
+            while (lo2 < hi2) {
+                dst[k++] = a2[lo2++];
+            }
+        }
+    }
+
+// [double]
+
+    /**
+     * Sorts the specified range of the array using parallel merge
+     * sort and/or Dual-Pivot Quicksort.
+     *
+     * To balance the faster splitting and parallelism of merge sort
+     * with the faster element partitioning of Quicksort, ranges are
+     * subdivided in tiers such that, if there is enough parallelism,
+     * the four-way parallel merge is started, still ensuring enough
+     * parallelism to process the partitions.
      *
      * @param a the array to be sorted
-     * @param left the index of the first element, inclusive, to be sorted
-     * @param right the index of the last element, inclusive, to be sorted
-     * @param work a workspace array (slice)
-     * @param workBase origin of usable space in work array
-     * @param workLen usable size of work array
+     * @param parallelism the parallelism level
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
      */
-    static void sort(double[] a, int left, int right,
-                     double[] work, int workBase, int workLen) {
+    static void sort(double[] a, int parallelism, int low, int high) {
+        /*
+         * Phase 1. Count the number of negative zero -0.0d,
+         * turn them into positive zero, and move all NaNs
+         * to the end of the array.
+         */
+        int numNegativeZero = 0;
+
+        for (int k = high; k > low; ) {
+            double ak = a[--k];
+
+            if (ak == 0.0d && Double.doubleToRawLongBits(ak) < 0) { // ak is -0.0d
+                numNegativeZero += 1;
+                a[k] = 0.0d;
+            } else if (ak != ak) { // ak is NaN
+                a[k] = a[--high];
+                a[high] = ak;
+            }
+        }
+
         /*
-         * Phase 1: Move NaNs to the end of the array.
+         * Phase 2. Sort everything except NaNs,
+         * which are already in place.
          */
-        while (left <= right && Double.isNaN(a[right])) {
-            --right;
+        int size = high - low;
+
+        if (parallelism > 1 && size > MIN_PARALLEL_SORT_SIZE) {
+            int depth = getDepth(parallelism, size >> 12);
+            double[] b = depth == 0 ? null : new double[size];
+            new Sorter(null, a, b, low, size, low, depth).invoke();
+        } else {
+            sort(null, a, 0, low, high);
         }
-        for (int k = right; --k >= left; ) {
-            double ak = a[k];
-            if (ak != ak) { // a[k] is NaN
-                a[k] = a[right];
-                a[right] = ak;
-                --right;
+
+        /*
+         * Phase 3. Turn positive zero 0.0d
+         * back into negative zero -0.0d.
+         */
+        if (++numNegativeZero == 1) {
+            return;
+        }
+
+        /*
+         * Find the position one less than
+         * the index of the first zero.
+         */
+        while (low <= high) {
+            int middle = (low + high) >>> 1;
+
+            if (a[middle] < 0) {
+                low = middle + 1;
+            } else {
+                high = middle - 1;
             }
         }
 
         /*
-         * Phase 2: Sort everything except NaNs (which are already in place).
-         */
-        doSort(a, left, right, work, workBase, workLen);
-
-        /*
-         * Phase 3: Place negative zeros before positive zeros.
-         */
-        int hi = right;
-
-        /*
-         * Find the first zero, or first positive, or last negative element.
+         * Replace the required number of 0.0d by -0.0d.
          */
-        while (left < hi) {
-            int middle = (left + hi) >>> 1;
-            double middleValue = a[middle];
-
-            if (middleValue < 0.0d) {
-                left = middle + 1;
-            } else {
-                hi = middle;
-            }
-        }
-
-        /*
-         * Skip the last negative value (if any) or all leading negative zeros.
-         */
-        while (left <= right && Double.doubleToRawLongBits(a[left]) < 0) {
-            ++left;
+        while (--numNegativeZero > 0) {
+            a[++high] = -0.0d;
         }
-
-        /*
-         * Move negative zeros to the beginning of the sub-range.
-         *
-         * Partitioning:
-         *
-         * +----------------------------------------------------+
-         * |   < 0.0   |   -0.0   |   0.0   |   ?  ( >= 0.0 )   |
-         * +----------------------------------------------------+
-         *              ^          ^         ^
-         *              |          |         |
-         *             left        p         k
-         *
-         * Invariants:
-         *
-         *   all in (*,  left)  <  0.0
-         *   all in [left,  p) == -0.0
-         *   all in [p,     k) ==  0.0
-         *   all in [k, right] >=  0.0
-         *
-         * Pointer k is the first index of ?-part.
-         */
-        for (int k = left, p = left - 1; ++k <= right; ) {
-            double ak = a[k];
-            if (ak != 0.0d) {
-                break;
+    }
+
+    /**
+     * Sorts the specified array using the Dual-Pivot Quicksort and/or
+     * other sorts in special-cases, possibly with parallel partitions.
+     *
+     * @param sorter parallel context
+     * @param a the array to be sorted
+     * @param bits the combination of recursion depth and bit flag, where
+     *        the right bit "0" indicates that array is the leftmost part
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
+     */
+    static void sort(Sorter sorter, double[] a, int bits, int low, int high) {
+        while (true) {
+            int end = high - 1, size = high - low;
+
+            /*
+             * Run mixed insertion sort on small non-leftmost parts.
+             */
+            if (size < MAX_MIXED_INSERTION_SORT_SIZE + bits && (bits & 1) > 0) {
+                mixedInsertionSort(a, low, high - 3 * ((size >> 5) << 3), high);
+                return;
+            }
+
+            /*
+             * Invoke insertion sort on small leftmost part.
+             */
+            if (size < MAX_INSERTION_SORT_SIZE) {
+                insertionSort(a, low, high);
+                return;
+            }
+
+            /*
+             * Check if the whole array or large non-leftmost
+             * parts are nearly sorted and then merge runs.
+             */
+            if ((bits == 0 || size > MIN_TRY_MERGE_SIZE && (bits & 1) > 0)
+                    && tryMergeRuns(sorter, a, low, size)) {
+                return;
+            }
+
+            /*
+             * Switch to heap sort if execution
+             * time is becoming quadratic.
+             */
+            if ((bits += DELTA) > MAX_RECURSION_DEPTH) {
+                heapSort(a, low, high);
+                return;
+            }
+
+            /*
+             * Use an inexpensive approximation of the golden ratio
+             * to select five sample elements and determine pivots.
+             */
+            int step = (size >> 3) * 3 + 3;
+
+            /*
+             * Five elements around (and including) the central element
+             * will be used for pivot selection as described below. The
+             * unequal choice of spacing these elements was empirically
+             * determined to work well on a wide variety of inputs.
+             */
+            int e1 = low + step;
+            int e5 = end - step;
+            int e3 = (e1 + e5) >>> 1;
+            int e2 = (e1 + e3) >>> 1;
+            int e4 = (e3 + e5) >>> 1;
+            double a3 = a[e3];
+
+            /*
+             * Sort these elements in place by the combination
+             * of 4-element sorting network and insertion sort.
+             *
+             *    5 ------o-----------o------------
+             *            |           |
+             *    4 ------|-----o-----o-----o------
+             *            |     |           |
+             *    2 ------o-----|-----o-----o------
+             *                  |     |
+             *    1 ------------o-----o------------
+             */
+            if (a[e5] < a[e2]) { double t = a[e5]; a[e5] = a[e2]; a[e2] = t; }
+            if (a[e4] < a[e1]) { double t = a[e4]; a[e4] = a[e1]; a[e1] = t; }
+            if (a[e5] < a[e4]) { double t = a[e5]; a[e5] = a[e4]; a[e4] = t; }
+            if (a[e2] < a[e1]) { double t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
+            if (a[e4] < a[e2]) { double t = a[e4]; a[e4] = a[e2]; a[e2] = t; }
+
+            if (a3 < a[e2]) {
+                if (a3 < a[e1]) {
+                    a[e3] = a[e2]; a[e2] = a[e1]; a[e1] = a3;
+                } else {
+                    a[e3] = a[e2]; a[e2] = a3;
+                }
+            } else if (a3 > a[e4]) {
+                if (a3 > a[e5]) {
+                    a[e3] = a[e4]; a[e4] = a[e5]; a[e5] = a3;
+                } else {
+                    a[e3] = a[e4]; a[e4] = a3;
+                }
             }
-            if (Double.doubleToRawLongBits(ak) < 0) { // ak is -0.0d
-                a[k] = 0.0d;
-                a[++p] = -0.0d;
+
+            // Pointers
+            int lower = low; // The index of the last element of the left part
+            int upper = end; // The index of the first element of the right part
+
+            /*
+             * Partitioning with 2 pivots in case of different elements.
+             */
+            if (a[e1] < a[e2] && a[e2] < a[e3] && a[e3] < a[e4] && a[e4] < a[e5]) {
+
+                /*
+                 * Use the first and fifth of the five sorted elements as
+                 * the pivots. These values are inexpensive approximation
+                 * of tertiles. Note, that pivot1 < pivot2.
+                 */
+                double pivot1 = a[e1];
+                double pivot2 = a[e5];
+
+                /*
+                 * The first and the last elements to be sorted are moved
+                 * to the locations formerly occupied by the pivots. When
+                 * partitioning is completed, the pivots are swapped back
+                 * into their final positions, and excluded from the next
+                 * subsequent sorting.
+                 */
+                a[e1] = a[lower];
+                a[e5] = a[upper];
+
+                /*
+                 * Skip elements, which are less or greater than the pivots.
+                 */
+                while (a[++lower] < pivot1);
+                while (a[--upper] > pivot2);
+
+                /*
+                 * Backward 3-interval partitioning
+                 *
+                 *   left part                 central part          right part
+                 * +------------------------------------------------------------+
+                 * |  < pivot1  |   ?   |  pivot1 <= && <= pivot2  |  > pivot2  |
+                 * +------------------------------------------------------------+
+                 *             ^       ^                            ^
+                 *             |       |                            |
+                 *           lower     k                          upper
+                 *
+                 * Invariants:
+                 *
+                 *              all in (low, lower] < pivot1
+                 *    pivot1 <= all in (k, upper)  <= pivot2
+                 *              all in [upper, end) > pivot2
+                 *
+                 * Pointer k is the last index of ?-part
+                 */
+                for (int unused = --lower, k = ++upper; --k > lower; ) {
+                    double ak = a[k];
+
+                    if (ak < pivot1) { // Move a[k] to the left side
+                        while (lower < k) {
+                            if (a[++lower] >= pivot1) {
+                                if (a[lower] > pivot2) {
+                                    a[k] = a[--upper];
+                                    a[upper] = a[lower];
+                                } else {
+                                    a[k] = a[lower];
+                                }
+                                a[lower] = ak;
+                                break;
+                            }
+                        }
+                    } else if (ak > pivot2) { // Move a[k] to the right side
+                        a[k] = a[--upper];
+                        a[upper] = ak;
+                    }
+                }
+
+                /*
+                 * Swap the pivots into their final positions.
+                 */
+                a[low] = a[lower]; a[lower] = pivot1;
+                a[end] = a[upper]; a[upper] = pivot2;
+
+                /*
+                 * Sort non-left parts recursively (possibly in parallel),
+                 * excluding known pivots.
+                 */
+                if (size > MIN_PARALLEL_SORT_SIZE && sorter != null) {
+                    sorter.forkSorter(bits | 1, lower + 1, upper);
+                    sorter.forkSorter(bits | 1, upper + 1, high);
+                } else {
+                    sort(sorter, a, bits | 1, lower + 1, upper);
+                    sort(sorter, a, bits | 1, upper + 1, high);
+                }
+
+            } else { // Use single pivot in case of many equal elements
+
+                /*
+                 * Use the third of the five sorted elements as the pivot.
+                 * This value is inexpensive approximation of the median.
+                 */
+                double pivot = a[e3];
+
+                /*
+                 * The first element to be sorted is moved to the
+                 * location formerly occupied by the pivot. After
+                 * completion of partitioning the pivot is swapped
+                 * back into its final position, and excluded from
+                 * the next subsequent sorting.
+                 */
+                a[e3] = a[lower];
+
+                /*
+                 * Traditional 3-way (Dutch National Flag) partitioning
+                 *
+                 *   left part                 central part    right part
+                 * +------------------------------------------------------+
+                 * |   < pivot   |     ?     |   == pivot   |   > pivot   |
+                 * +------------------------------------------------------+
+                 *              ^           ^                ^
+                 *              |           |                |
+                 *            lower         k              upper
+                 *
+                 * Invariants:
+                 *
+                 *   all in (low, lower] < pivot
+                 *   all in (k, upper)  == pivot
+                 *   all in [upper, end] > pivot
+                 *
+                 * Pointer k is the last index of ?-part
+                 */
+                for (int k = ++upper; --k > lower; ) {
+                    double ak = a[k];
+
+                    if (ak != pivot) {
+                        a[k] = pivot;
+
+                        if (ak < pivot) { // Move a[k] to the left side
+                            while (a[++lower] < pivot);
+
+                            if (a[lower] > pivot) {
+                                a[--upper] = a[lower];
+                            }
+                            a[lower] = ak;
+                        } else { // ak > pivot - Move a[k] to the right side
+                            a[--upper] = ak;
+                        }
+                    }
+                }
+
+                /*
+                 * Swap the pivot into its final position.
+                 */
+                a[low] = a[lower]; a[lower] = pivot;
+
+                /*
+                 * Sort the right part (possibly in parallel), excluding
+                 * known pivot. All elements from the central part are
+                 * equal and therefore already sorted.
+                 */
+                if (size > MIN_PARALLEL_SORT_SIZE && sorter != null) {
+                    sorter.forkSorter(bits | 1, upper, high);
+                } else {
+                    sort(sorter, a, bits | 1, upper, high);
+                }
+            }
+            high = lower; // Iterate along the left part
+        }
+    }
+
+    /**
+     * Sorts the specified range of the array using mixed insertion sort.
+     *
+     * Mixed insertion sort is combination of simple insertion sort,
+     * pin insertion sort and pair insertion sort.
+     *
+     * In the context of Dual-Pivot Quicksort, the pivot element
+     * from the left part plays the role of sentinel, because it
+     * is less than any elements from the given part. Therefore,
+     * expensive check of the left range can be skipped on each
+     * iteration unless it is the leftmost call.
+     *
+     * @param a the array to be sorted
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param end the index of the last element for simple insertion sort
+     * @param high the index of the last element, exclusive, to be sorted
+     */
+    private static void mixedInsertionSort(double[] a, int low, int end, int high) {
+        if (end == high) {
+
+            /*
+             * Invoke simple insertion sort on tiny array.
+             */
+            for (int i; ++low < end; ) {
+                double ai = a[i = low];
+
+                while (ai < a[--i]) {
+                    a[i + 1] = a[i];
+                }
+                a[i + 1] = ai;
+            }
+        } else {
+
+            /*
+             * Start with pin insertion sort on small part.
+             *
+             * Pin insertion sort is extended simple insertion sort.
+             * The main idea of this sort is to put elements larger
+             * than an element called pin to the end of array (the
+             * proper area for such elements). It avoids expensive
+             * movements of these elements through the whole array.
+             */
+            double pin = a[end];
+
+            for (int i, p = high; ++low < end; ) {
+                double ai = a[i = low];
+
+                if (ai < a[i - 1]) { // Small element
+
+                    /*
+                     * Insert small element into sorted part.
+                     */
+                    a[i] = a[--i];
+
+                    while (ai < a[--i]) {
+                        a[i + 1] = a[i];
+                    }
+                    a[i + 1] = ai;
+
+                } else if (p > i && ai > pin) { // Large element
+
+                    /*
+                     * Find element smaller than pin.
+                     */
+                    while (a[--p] > pin);
+
+                    /*
+                     * Swap it with large element.
+                     */
+                    if (p > i) {
+                        ai = a[p];
+                        a[p] = a[i];
+                    }
+
+                    /*
+                     * Insert small element into sorted part.
+                     */
+                    while (ai < a[--i]) {
+                        a[i + 1] = a[i];
+                    }
+                    a[i + 1] = ai;
+                }
+            }
+
+            /*
+             * Continue with pair insertion sort on remain part.
+             */
+            for (int i; low < high; ++low) {
+                double a1 = a[i = low], a2 = a[++low];
+
+                /*
+                 * Insert two elements per iteration: at first, insert the
+                 * larger element and then insert the smaller element, but
+                 * from the position where the larger element was inserted.
+                 */
+                if (a1 > a2) {
+
+                    while (a1 < a[--i]) {
+                        a[i + 2] = a[i];
+                    }
+                    a[++i + 1] = a1;
+
+                    while (a2 < a[--i]) {
+                        a[i + 1] = a[i];
+                    }
+                    a[i + 1] = a2;
+
+                } else if (a1 < a[i - 1]) {
+
+                    while (a2 < a[--i]) {
+                        a[i + 2] = a[i];
+                    }
+                    a[++i + 1] = a2;
+
+                    while (a1 < a[--i]) {
+                        a[i + 1] = a[i];
+                    }
+                    a[i + 1] = a1;
+                }
             }
         }
     }
 
     /**
-     * Sorts the specified range of the array.
+     * Sorts the specified range of the array using insertion sort.
      *
      * @param a the array to be sorted
-     * @param left the index of the first element, inclusive, to be sorted
-     * @param right the index of the last element, inclusive, to be sorted
-     * @param work a workspace array (slice)
-     * @param workBase origin of usable space in work array
-     * @param workLen usable size of work array
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
      */
-    private static void doSort(double[] a, int left, int right,
-                               double[] work, int workBase, int workLen) {
-        // Use Quicksort on small arrays
-        if (right - left < QUICKSORT_THRESHOLD) {
-            sort(a, left, right, true);
-            return;
-        }
-
-        /*
-         * Index run[i] is the start of i-th run
-         * (ascending or descending sequence).
-         */
-        int[] run = new int[MAX_RUN_COUNT + 1];
-        int count = 0; run[0] = left;
-
-        // Check if the array is nearly sorted
-        for (int k = left; k < right; run[count] = k) {
-            // Equal items in the beginning of the sequence
-            while (k < right && a[k] == a[k + 1])
-                k++;
-            if (k == right) break;  // Sequence finishes with equal items
-            if (a[k] < a[k + 1]) { // ascending
-                while (++k <= right && a[k - 1] <= a[k]);
-            } else if (a[k] > a[k + 1]) { // descending
-                while (++k <= right && a[k - 1] >= a[k]);
-                // Transform into an ascending sequence
-                for (int lo = run[count] - 1, hi = k; ++lo < --hi; ) {
-                    double t = a[lo]; a[lo] = a[hi]; a[hi] = t;
+    private static void insertionSort(double[] a, int low, int high) {
+        for (int i, k = low; ++k < high; ) {
+            double ai = a[i = k];
+
+            if (ai < a[i - 1]) {
+                while (--i >= low && ai < a[i]) {
+                    a[i + 1] = a[i];
                 }
-            }
-
-            // Merge a transformed descending sequence followed by an
-            // ascending sequence
-            if (run[count] > left && a[run[count]] >= a[run[count] - 1]) {
-                count--;
-            }
-
-            /*
-             * The array is not highly structured,
-             * use Quicksort instead of merge sort.
-             */
-            if (++count == MAX_RUN_COUNT) {
-                sort(a, left, right, true);
-                return;
+                a[i + 1] = ai;
             }
         }
-
-        // These invariants should hold true:
-        //    run[0] = 0
-        //    run[<last>] = right + 1; (terminator)
-
-        if (count == 0) {
-            // A single equal run
-            return;
-        } else if (count == 1 && run[count] > right) {
-            // Either a single ascending or a transformed descending run.
-            // Always check that a final run is a proper terminator, otherwise
-            // we have an unterminated trailing run, to handle downstream.
-            return;
-        }
-        right++;
-        if (run[count] < right) {
-            // Corner case: the final run is not a terminator. This may happen
-            // if a final run is an equals run, or there is a single-element run
-            // at the end. Fix up by adding a proper terminator at the end.
-            // Note that we terminate with (right + 1), incremented earlier.
-            run[++count] = right;
+    }
+
+    /**
+     * Sorts the specified range of the array using heap sort.
+     *
+     * @param a the array to be sorted
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
+     */
+    private static void heapSort(double[] a, int low, int high) {
+        for (int k = (low + high) >>> 1; k > low; ) {
+            pushDown(a, --k, a[k], low, high);
         }
-
-        // Determine alternation base for merge
-        byte odd = 0;
-        for (int n = 1; (n <<= 1) < count; odd ^= 1);
-
-        // Use or create temporary array b for merging
-        double[] b;                 // temp array; alternates with a
-        int ao, bo;              // array offsets from 'left'
-        int blen = right - left; // space needed for b
-        if (work == null || workLen < blen || workBase + blen > work.length) {
-            work = new double[blen];
-            workBase = 0;
-        }
-        if (odd == 0) {
-            System.arraycopy(a, left, work, workBase, blen);
-            b = a;
-            bo = 0;
-            a = work;
-            ao = workBase - left;
-        } else {
-            b = work;
-            ao = 0;
-            bo = workBase - left;
-        }
-
-        // Merging
-        for (int last; count > 1; count = last) {
-            for (int k = (last = 0) + 2; k <= count; k += 2) {
-                int hi = run[k], mi = run[k - 1];
-                for (int i = run[k - 2], p = i, q = mi; i < hi; ++i) {
-                    if (q >= hi || p < mi && a[p + ao] <= a[q + ao]) {
-                        b[i + bo] = a[p++ + ao];
-                    } else {
-                        b[i + bo] = a[q++ + ao];
-                    }
-                }
-                run[++last] = hi;
-            }
-            if ((count & 1) != 0) {
-                for (int i = right, lo = run[count - 1]; --i >= lo;
-                    b[i + bo] = a[i + ao]
-                );
-                run[++last] = right;
-            }
-            double[] t = a; a = b; b = t;
-            int o = ao; ao = bo; bo = o;
+        while (--high > low) {
+            double max = a[low];
+            pushDown(a, low, a[high], low, high);
+            a[high] = max;
         }
     }
 
     /**
-     * Sorts the specified range of the array by Dual-Pivot Quicksort.
+     * Pushes specified element down during heap sort.
      *
-     * @param a the array to be sorted
-     * @param left the index of the first element, inclusive, to be sorted
-     * @param right the index of the last element, inclusive, to be sorted
-     * @param leftmost indicates if this part is the leftmost in the range
+     * @param a the given array
+     * @param p the start index
+     * @param value the given element
+     * @param low the index of the first element, inclusive, to be sorted
+     * @param high the index of the last element, exclusive, to be sorted
      */
-    private static void sort(double[] a, int left, int right, boolean leftmost) {
-        int length = right - left + 1;
-
-        // Use insertion sort on tiny arrays
-        if (length < INSERTION_SORT_THRESHOLD) {
-            if (leftmost) {
-                /*
-                 * Traditional (without sentinel) insertion sort,
-                 * optimized for server VM, is used in case of
-                 * the leftmost part.
-                 */
-                for (int i = left, j = i; i < right; j = ++i) {
-                    double ai = a[i + 1];
-                    while (ai < a[j]) {
-                        a[j + 1] = a[j];
-                        if (j-- == left) {
-                            break;
-                        }
-                    }
-                    a[j + 1] = ai;
-                }
-            } else {
-                /*
-                 * Skip the longest ascending sequence.
-                 */
-                do {
-                    if (left >= right) {
-                        return;
-                    }
-                } while (a[++left] >= a[left - 1]);
-
-                /*
-                 * Every element from adjoining part plays the role
-                 * of sentinel, therefore this allows us to avoid the
-                 * left range check on each iteration. Moreover, we use
-                 * the more optimized algorithm, so called pair insertion
-                 * sort, which is faster (in the context of Quicksort)
-                 * than traditional implementation of insertion sort.
-                 */
-                for (int k = left; ++left <= right; k = ++left) {
-                    double a1 = a[k], a2 = a[left];
-
-                    if (a1 < a2) {
-                        a2 = a1; a1 = a[left];
-                    }
-                    while (a1 < a[--k]) {
-                        a[k + 2] = a[k];
-                    }
-                    a[++k + 1] = a1;
-
-                    while (a2 < a[--k]) {
-                        a[k + 1] = a[k];
-                    }
-                    a[k + 1] = a2;
-                }
-                double last = a[right];
-
-                while (last < a[--right]) {
-                    a[right + 1] = a[right];
-                }
-                a[right + 1] = last;
+    private static void pushDown(double[] a, int p, double value, int low, int high) {
+        for (int k ;; a[p] = a[p = k]) {
+            k = (p << 1) - low + 2; // Index of the right child
+
+            if (k > high) {
+                break;
+            }
+            if (k == high || a[k] < a[k - 1]) {
+                --k;
+            }
+            if (a[k] <= value) {
+                break;
             }
-            return;
         }
-
-        // Inexpensive approximation of length / 7
-        int seventh = (length >> 3) + (length >> 6) + 1;
+        a[p] = value;
+    }
+
+    /**
+     * Tries to sort the specified range of the array.
+     *
+     * @param sorter parallel context
+     * @param a the array to be sorted
+     * @param low the index of the first element to be sorted
+     * @param size the array size
+     * @return true if finally sorted, false otherwise
+     */
+    private static boolean tryMergeRuns(Sorter sorter, double[] a, int low, int size) {
 
         /*
-         * Sort five evenly spaced elements around (and including) the
-         * center element in the range. These elements will be used for
-         * pivot selection as described below. The choice for spacing
-         * these elements was empirically determined to work well on
-         * a wide variety of inputs.
+         * The run array is constructed only if initial runs are
+         * long enough to continue, run[i] then holds start index
+         * of the i-th sequence of elements in non-descending order.
          */
-        int e3 = (left + right) >>> 1; // The midpoint
-        int e2 = e3 - seventh;
-        int e1 = e2 - seventh;
-        int e4 = e3 + seventh;
-        int e5 = e4 + seventh;
-
-        // Sort these elements using insertion sort
-        if (a[e2] < a[e1]) { double t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
-
-        if (a[e3] < a[e2]) { double t = a[e3]; a[e3] = a[e2]; a[e2] = t;
-            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
-        }
-        if (a[e4] < a[e3]) { double t = a[e4]; a[e4] = a[e3]; a[e3] = t;
-            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
-                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
-            }
-        }
-        if (a[e5] < a[e4]) { double t = a[e5]; a[e5] = a[e4]; a[e4] = t;
-            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
-                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
-                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
-                }
-            }
-        }
-
-        // Pointers
-        int less  = left;  // The index of the first element of center part
-        int great = right; // The index before the first element of right part
-
-        if (a[e1] != a[e2] && a[e2] != a[e3] && a[e3] != a[e4] && a[e4] != a[e5]) {
-            /*
-             * Use the second and fourth of the five sorted elements as pivots.
-             * These values are inexpensive approximations of the first and
-             * second terciles of the array. Note that pivot1 <= pivot2.
-             */
-            double pivot1 = a[e2];
-            double pivot2 = a[e4];
-
-            /*
-             * The first and the last elements to be sorted are moved to the
-             * locations formerly occupied by the pivots. When partitioning
-             * is complete, the pivots are swapped back into their final
-             * positions, and excluded from subsequent sorting.
-             */
-            a[e2] = a[left];
-            a[e4] = a[right];
-
-            /*
-             * Skip elements, which are less or greater than pivot values.
-             */
-            while (a[++less] < pivot1);
-            while (a[--great] > pivot2);
+        int[] run = null;
+        int high = low + size;
+        int count = 1, last = low;
+
+        /*
+         * Identify all possible runs.
+         */
+        for (int k = low + 1; k < high; ) {
 
             /*
-             * Partitioning:
-             *
-             *   left part           center part                   right part
-             * +--------------------------------------------------------------+
-             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
-             * +--------------------------------------------------------------+
-             *               ^                          ^       ^
-             *               |                          |       |
-             *              less                        k     great
-             *
-             * Invariants:
-             *
-             *              all in (left, less)   < pivot1
-             *    pivot1 <= all in [less, k)     <= pivot2
-             *              all in (great, right) > pivot2
-             *
-             * Pointer k is the first index of ?-part.
+             * Find the end index of the current run.
              */
-            outer:
-            for (int k = less - 1; ++k <= great; ) {
-                double ak = a[k];
-                if (ak < pivot1) { // Move a[k] to left part
-                    a[k] = a[less];
-                    /*
-                     * Here and below we use "a[i] = b; i++;" instead
-                     * of "a[i++] = b;" due to performance issue.
-                     */
-                    a[less] = ak;
-                    ++less;
-                } else if (ak > pivot2) { // Move a[k] to right part
-                    while (a[great] > pivot2) {
-                        if (great-- == k) {
-                            break outer;
-                        }
-                    }
-                    if (a[great] < pivot1) { // a[great] <= pivot2
-                        a[k] = a[less];
-                        a[less] = a[great];
-                        ++less;
-                    } else { // pivot1 <= a[great] <= pivot2
-                        a[k] = a[great];
-                    }
-                    /*
-                     * Here and below we use "a[i] = b; i--;" instead
-                     * of "a[i--] = b;" due to performance issue.
-                     */
-                    a[great] = ak;
-                    --great;
-                }
-            }
-
-            // Swap pivots into their final positions
-            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
-            a[right] = a[great + 1]; a[great + 1] = pivot2;
-
-            // Sort left and right parts recursively, excluding known pivots
-            sort(a, left, less - 2, leftmost);
-            sort(a, great + 2, right, false);
-
-            /*
-             * If center part is too large (comprises > 4/7 of the array),
-             * swap internal pivot values to ends.
-             */
-            if (less < e1 && e5 < great) {
-                /*
-                 * Skip elements, which are equal to pivot values.
-                 */
-                while (a[less] == pivot1) {
-                    ++less;
-                }
-
-                while (a[great] == pivot2) {
-                    --great;
+            if (a[k - 1] < a[k]) {
+
+                // Identify ascending sequence
+                while (++k < high && a[k - 1] <= a[k]);
+
+            } else if (a[k - 1] > a[k]) {
+
+                // Identify descending sequence
+                while (++k < high && a[k - 1] >= a[k]);
+
+                // Reverse into ascending order
+                for (int i = last - 1, j = k; ++i < --j && a[i] > a[j]; ) {
+                    double ai = a[i]; a[i] = a[j]; a[j] = ai;
                 }
-
-                /*
-                 * Partitioning:
-                 *
-                 *   left part         center part                  right part
-                 * +----------------------------------------------------------+
-                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
-                 * +----------------------------------------------------------+
-                 *              ^                        ^       ^
-                 *              |                        |       |
-                 *             less                      k     great
-                 *
-                 * Invariants:
-                 *
-                 *              all in (*,  less) == pivot1
-                 *     pivot1 < all in [less,  k)  < pivot2
-                 *              all in (great, *) == pivot2
-                 *
-                 * Pointer k is the first index of ?-part.
-                 */
-                outer:
-                for (int k = less - 1; ++k <= great; ) {
-                    double ak = a[k];
-                    if (ak == pivot1) { // Move a[k] to left part
-                        a[k] = a[less];
-                        a[less] = ak;
-                        ++less;
-                    } else if (ak == pivot2) { // Move a[k] to right part
-                        while (a[great] == pivot2) {
-                            if (great-- == k) {
-                                break outer;
-                            }
-                        }
-                        if (a[great] == pivot1) { // a[great] < pivot2
-                            a[k] = a[less];
-                            /*
-                             * Even though a[great] equals to pivot1, the
-                             * assignment a[less] = pivot1 may be incorrect,
-                             * if a[great] and pivot1 are floating-point zeros
-                             * of different signs. Therefore in float and
-                             * double sorting methods we have to use more
-                             * accurate assignment a[less] = a[great].
-                             */
-                            a[less] = a[great];
-                            ++less;
-                        } else { // pivot1 < a[great] < pivot2
-                            a[k] = a[great];
-                        }
-                        a[great] = ak;
-                        --great;
-                    }
-                }
-            }
-
-            // Sort center part recursively
-            sort(a, less, great, false);
-
-        } else { // Partitioning with one pivot
-            /*
-             * Use the third of the five sorted elements as pivot.
-             * This value is inexpensive approximation of the median.
-             */
-            double pivot = a[e3];
-
-            /*
-             * Partitioning degenerates to the traditional 3-way
-             * (or "Dutch National Flag") schema:
-             *
-             *   left part    center part              right part
-             * +-------------------------------------------------+
-             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
-             * +-------------------------------------------------+
-             *              ^              ^        ^
-             *              |              |        |
-             *             less            k      great
-             *
-             * Invariants:
-             *
-             *   all in (left, less)   < pivot
-             *   all in [less, k)     == pivot
-             *   all in (great, right) > pivot
-             *
-             * Pointer k is the first index of ?-part.
-             */
-            for (int k = less; k <= great; ++k) {
-                if (a[k] == pivot) {
+            } else { // Identify constant sequence
+                for (double ak = a[k]; ++k < high && ak == a[k]; );
+
+                if (k < high) {
                     continue;
                 }
-                double ak = a[k];
-                if (ak < pivot) { // Move a[k] to left part
-                    a[k] = a[less];
-                    a[less] = ak;
-                    ++less;
-                } else { // a[k] > pivot - Move a[k] to right part
-                    while (a[great] > pivot) {
-                        --great;
-                    }
-                    if (a[great] < pivot) { // a[great] <= pivot
-                        a[k] = a[less];
-                        a[less] = a[great];
-                        ++less;
-                    } else { // a[great] == pivot
-                        /*
-                         * Even though a[great] equals to pivot, the
-                         * assignment a[k] = pivot may be incorrect,
-                         * if a[great] and pivot are floating-point
-                         * zeros of different signs. Therefore in float
-                         * and double sorting methods we have to use
-                         * more accurate assignment a[k] = a[great].
-                         */
-                        a[k] = a[great];
-                    }
-                    a[great] = ak;
-                    --great;
-                }
             }
 
             /*
-             * Sort left and right parts recursively.
-             * All elements from center part are equal
-             * and, therefore, already sorted.
+             * Check special cases.
              */
-            sort(a, left, less - 1, leftmost);
-            sort(a, great + 1, right, false);
+            if (run == null) {
+                if (k == high) {
+
+                    /*
+                     * The array is monotonous sequence,
+                     * and therefore already sorted.
+                     */
+                    return true;
+                }
+
+                if (k - low < MIN_FIRST_RUN_SIZE) {
+
+                    /*
+                     * The first run is too small
+                     * to proceed with scanning.
+                     */
+                    return false;
+                }
+
+                run = new int[((size >> 10) | 0x7F) & 0x3FF];
+                run[0] = low;
+
+            } else if (a[last - 1] > a[last]) {
+
+                if (count > (k - low) >> MIN_FIRST_RUNS_FACTOR) {
+
+                    /*
+                     * The first runs are not long
+                     * enough to continue scanning.
+                     */
+                    return false;
+                }
+
+                if (++count == MAX_RUN_CAPACITY) {
+
+                    /*
+                     * Array is not highly structured.
+                     */
+                    return false;
+                }
+
+                if (count == run.length) {
+
+                    /*
+                     * Increase capacity of index array.
+                     */
+                    run = Arrays.copyOf(run, count << 1);
+                }
+            }
+            run[count] = (last = k);
+        }
+
+        /*
+         * Merge runs of highly structured array.
+         */
+        if (count > 1) {
+            double[] b; int offset = low;
+
+            if (sorter == null || (b = (double[]) sorter.b) == null) {
+                b = new double[size];
+            } else {
+                offset = sorter.offset;
+            }
+            mergeRuns(a, b, offset, 1, sorter != null, run, 0, count);
+        }
+        return true;
+    }
+
+    /**
+     * Merges the specified runs.
+     *
+     * @param a the source array
+     * @param b the temporary buffer used in merging
+     * @param offset the start index in the source, inclusive
+     * @param aim specifies merging: to source ( > 0), buffer ( < 0) or any ( == 0)
+     * @param parallel indicates whether merging is performed in parallel
+     * @param run the start indexes of the runs, inclusive
+     * @param lo the start index of the first run, inclusive
+     * @param hi the start index of the last run, inclusive
+     * @return the destination where runs are merged
+     */
+    private static double[] mergeRuns(double[] a, double[] b, int offset,
+            int aim, boolean parallel, int[] run, int lo, int hi) {
+
+        if (hi - lo == 1) {
+            if (aim >= 0) {
+                return a;
+            }
+            for (int i = run[hi], j = i - offset, low = run[lo]; i > low;
+                b[--j] = a[--i]
+            );
+            return b;
+        }
+
+        /*
+         * Split into approximately equal parts.
+         */
+        int mi = lo, rmi = (run[lo] + run[hi]) >>> 1;
+        while (run[++mi + 1] <= rmi);
+
+        /*
+         * Merge the left and right parts.
+         */
+        double[] a1, a2;
+
+        if (parallel && hi - lo > MIN_RUN_COUNT) {
+            RunMerger merger = new RunMerger(a, b, offset, 0, run, mi, hi).forkMe();
+            a1 = mergeRuns(a, b, offset, -aim, true, run, lo, mi);
+            a2 = (double[]) merger.getDestination();
+        } else {
+            a1 = mergeRuns(a, b, offset, -aim, false, run, lo, mi);
+            a2 = mergeRuns(a, b, offset,    0, false, run, mi, hi);
+        }
+
+        double[] dst = a1 == a ? b : a;
+
+        int k   = a1 == a ? run[lo] - offset : run[lo];
+        int lo1 = a1 == b ? run[lo] - offset : run[lo];
+        int hi1 = a1 == b ? run[mi] - offset : run[mi];
+        int lo2 = a2 == b ? run[mi] - offset : run[mi];
+        int hi2 = a2 == b ? run[hi] - offset : run[hi];
+
+        if (parallel) {
+            new Merger(null, dst, k, a1, lo1, hi1, a2, lo2, hi2).invoke();
+        } else {
+            mergeParts(null, dst, k, a1, lo1, hi1, a2, lo2, hi2);
+        }
+        return dst;
+    }
+
+    /**
+     * Merges the sorted parts.
+     *
+     * @param merger parallel context
+     * @param dst the destination where parts are merged
+     * @param k the start index of the destination, inclusive
+     * @param a1 the first part
+     * @param lo1 the start index of the first part, inclusive
+     * @param hi1 the end index of the first part, exclusive
+     * @param a2 the second part
+     * @param lo2 the start index of the second part, inclusive
+     * @param hi2 the end index of the second part, exclusive
+     */
+    private static void mergeParts(Merger merger, double[] dst, int k,
+            double[] a1, int lo1, int hi1, double[] a2, int lo2, int hi2) {
+
+        if (merger != null && a1 == a2) {
+
+            while (true) {
+
+                /*
+                 * The first part must be larger.
+                 */
+                if (hi1 - lo1 < hi2 - lo2) {
+                    int lo = lo1; lo1 = lo2; lo2 = lo;
+                    int hi = hi1; hi1 = hi2; hi2 = hi;
+                }
+
+                /*
+                 * Small parts will be merged sequentially.
+                 */
+                if (hi1 - lo1 < MIN_PARALLEL_MERGE_PARTS_SIZE) {
+                    break;
+                }
+
+                /*
+                 * Find the median of the larger part.
+                 */
+                int mi1 = (lo1 + hi1) >>> 1;
+                double key = a1[mi1];
+                int mi2 = hi2;
+
+                /*
+                 * Partition the smaller part.
+                 */
+                for (int loo = lo2; loo < mi2; ) {
+                    int t = (loo + mi2) >>> 1;
+
+                    if (key > a2[t]) {
+                        loo = t + 1;
+                    } else {
+                        mi2 = t;
+                    }
+                }
+
+                int d = mi2 - lo2 + mi1 - lo1;
+
+                /*
+                 * Merge the right sub-parts in parallel.
+                 */
+                merger.forkMerger(dst, k + d, a1, mi1, hi1, a2, mi2, hi2);
+
+                /*
+                 * Process the sub-left parts.
+                 */
+                hi1 = mi1;
+                hi2 = mi2;
+            }
+        }
+
+        /*
+         * Merge small parts sequentially.
+         */
+        while (lo1 < hi1 && lo2 < hi2) {
+            dst[k++] = a1[lo1] < a2[lo2] ? a1[lo1++] : a2[lo2++];
+        }
+        if (dst != a1 || k < lo1) {
+            while (lo1 < hi1) {
+                dst[k++] = a1[lo1++];
+            }
+        }
+        if (dst != a2 || k < lo2) {
+            while (lo2 < hi2) {
+                dst[k++] = a2[lo2++];
+            }
+        }
+    }
+
+// [class]
+
+    /**
+     * This class implements parallel sorting.
+     */
+    private static final class Sorter extends CountedCompleter<Void> {
+        private static final long serialVersionUID = 20180818L;
+        private final Object a, b;
+        private final int low, size, offset, depth;
+
+        private Sorter(CountedCompleter<?> parent,
+                Object a, Object b, int low, int size, int offset, int depth) {
+            super(parent);
+            this.a = a;
+            this.b = b;
+            this.low = low;
+            this.size = size;
+            this.offset = offset;
+            this.depth = depth;
+        }
+
+        @Override
+        public final void compute() {
+            if (depth < 0) {
+                setPendingCount(2);
+                int half = size >> 1;
+                new Sorter(this, b, a, low, half, offset, depth + 1).fork();
+                new Sorter(this, b, a, low + half, size - half, offset, depth + 1).compute();
+            } else {
+                if (a instanceof int[]) {
+                    sort(this, (int[]) a, depth, low, low + size);
+                } else if (a instanceof long[]) {
+                    sort(this, (long[]) a, depth, low, low + size);
+                } else if (a instanceof float[]) {
+                    sort(this, (float[]) a, depth, low, low + size);
+                } else if (a instanceof double[]) {
+                    sort(this, (double[]) a, depth, low, low + size);
+                } else {
+                    throw new IllegalArgumentException(
+                        "Unknown type of array: " + a.getClass().getName());
+                }
+            }
+            tryComplete();
+        }
+
+        @Override
+        public final void onCompletion(CountedCompleter<?> caller) {
+            if (depth < 0) {
+                int mi = low + (size >> 1);
+                boolean src = (depth & 1) == 0;
+
+                new Merger(null,
+                    a,
+                    src ? low : low - offset,
+                    b,
+                    src ? low - offset : low,
+                    src ? mi - offset : mi,
+                    b,
+                    src ? mi - offset : mi,
+                    src ? low + size - offset : low + size
+                ).invoke();
+            }
+        }
+
+        private void forkSorter(int depth, int low, int high) {
+            addToPendingCount(1);
+            Object a = this.a; // Use local variable for performance
+            new Sorter(this, a, b, low, high - low, offset, depth).fork();
+        }
+    }
+
+    /**
+     * This class implements parallel merging.
+     */
+    private static final class Merger extends CountedCompleter<Void> {
+        private static final long serialVersionUID = 20180818L;
+        private final Object dst, a1, a2;
+        private final int k, lo1, hi1, lo2, hi2;
+
+        private Merger(CountedCompleter<?> parent, Object dst, int k,
+                Object a1, int lo1, int hi1, Object a2, int lo2, int hi2) {
+            super(parent);
+            this.dst = dst;
+            this.k = k;
+            this.a1 = a1;
+            this.lo1 = lo1;
+            this.hi1 = hi1;
+            this.a2 = a2;
+            this.lo2 = lo2;
+            this.hi2 = hi2;
+        }
+
+        @Override
+        public final void compute() {
+            if (dst instanceof int[]) {
+                mergeParts(this, (int[]) dst, k,
+                    (int[]) a1, lo1, hi1, (int[]) a2, lo2, hi2);
+            } else if (dst instanceof long[]) {
+                mergeParts(this, (long[]) dst, k,
+                    (long[]) a1, lo1, hi1, (long[]) a2, lo2, hi2);
+            } else if (dst instanceof float[]) {
+                mergeParts(this, (float[]) dst, k,
+                    (float[]) a1, lo1, hi1, (float[]) a2, lo2, hi2);
+            } else if (dst instanceof double[]) {
+                mergeParts(this, (double[]) dst, k,
+                    (double[]) a1, lo1, hi1, (double[]) a2, lo2, hi2);
+            } else {
+                throw new IllegalArgumentException(
+                    "Unknown type of array: " + dst.getClass().getName());
+            }
+            propagateCompletion();
+        }
+
+        private void forkMerger(Object dst, int k,
+                Object a1, int lo1, int hi1, Object a2, int lo2, int hi2) {
+            addToPendingCount(1);
+            new Merger(this, dst, k, a1, lo1, hi1, a2, lo2, hi2).fork();
+        }
+    }
+
+    /**
+     * This class implements parallel merging of runs.
+     */
+    private static final class RunMerger extends RecursiveTask<Object> {
+        private static final long serialVersionUID = 20180818L;
+        private final Object a, b;
+        private final int[] run;
+        private final int offset, aim, lo, hi;
+
+        private RunMerger(Object a, Object b, int offset,
+                int aim, int[] run, int lo, int hi) {
+            this.a = a;
+            this.b = b;
+            this.offset = offset;
+            this.aim = aim;
+            this.run = run;
+            this.lo = lo;
+            this.hi = hi;
+        }
+
+        @Override
+        protected final Object compute() {
+            if (a instanceof int[]) {
+                return mergeRuns((int[]) a, (int[]) b, offset, aim, true, run, lo, hi);
+            }
+            if (a instanceof long[]) {
+                return mergeRuns((long[]) a, (long[]) b, offset, aim, true, run, lo, hi);
+            }
+            if (a instanceof float[]) {
+                return mergeRuns((float[]) a, (float[]) b, offset, aim, true, run, lo, hi);
+            }
+            if (a instanceof double[]) {
+                return mergeRuns((double[]) a, (double[]) b, offset, aim, true, run, lo, hi);
+            }
+            throw new IllegalArgumentException(
+                "Unknown type of array: " + a.getClass().getName());
+        }
+
+        private RunMerger forkMe() {
+            fork();
+            return this;
+        }
+
+        private Object getDestination() {
+            join();
+            return getRawResult();
         }
     }
 }
--- a/src/java.base/share/classes/javax/crypto/CryptoPermissions.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/share/classes/javax/crypto/CryptoPermissions.java	Wed Nov 13 09:16:04 2019 +0000
@@ -40,6 +40,8 @@
 import java.io.ObjectOutputStream;
 import java.io.IOException;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 /**
  * This class contains CryptoPermission objects, organized into
  * PermissionCollections according to algorithm names.
@@ -99,7 +101,7 @@
     void load(InputStream in)
         throws IOException, CryptoPolicyParser.ParsingException {
         CryptoPolicyParser parser = new CryptoPolicyParser();
-        parser.read(new BufferedReader(new InputStreamReader(in, "UTF-8")));
+        parser.read(new BufferedReader(new InputStreamReader(in, UTF_8)));
 
         CryptoPermission[] parsingResult = parser.getPermissions();
         for (int i = 0; i < parsingResult.length; i++) {
--- a/src/java.base/share/classes/jdk/internal/PreviewFeature.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/share/classes/jdk/internal/PreviewFeature.java	Wed Nov 13 09:16:04 2019 +0000
@@ -54,7 +54,6 @@
     public boolean essentialAPI() default false;
 
     public enum Feature {
-        SWITCH_EXPRESSIONS,
         TEXT_BLOCKS;
     }
 }
--- a/src/java.base/share/classes/sun/security/pkcs12/PKCS12KeyStore.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/share/classes/sun/security/pkcs12/PKCS12KeyStore.java	Wed Nov 13 09:16:04 2019 +0000
@@ -51,6 +51,8 @@
 import java.security.spec.PKCS8EncodedKeySpec;
 import java.util.*;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 import java.security.AlgorithmParameters;
 import java.security.InvalidAlgorithmParameterException;
 import javax.crypto.spec.PBEParameterSpec;
@@ -687,12 +689,14 @@
                 entry.attributes.addAll(attributes);
             }
             // set the keyId to current date
-            entry.keyId = ("Time " + (entry.date).getTime()).getBytes("UTF8");
+            entry.keyId = ("Time " + (entry.date).getTime()).getBytes(UTF_8);
             // set the alias
             entry.alias = alias.toLowerCase(Locale.ENGLISH);
             // add the entry
             entries.put(alias.toLowerCase(Locale.ENGLISH), entry);
 
+        } catch (KeyStoreException kse) {
+            throw kse;
         } catch (Exception nsae) {
             throw new KeyStoreException("Key protection" +
                        " algorithm not found: " + nsae, nsae);
@@ -746,12 +750,8 @@
                 alias + "'");
         }
 
-        try {
-            // set the keyId to current date
-            entry.keyId = ("Time " + (entry.date).getTime()).getBytes("UTF8");
-        } catch (UnsupportedEncodingException ex) {
-            // Won't happen
-        }
+        // set the keyId to current date
+        entry.keyId = ("Time " + (entry.date).getTime()).getBytes(UTF_8);
         // set the alias
         entry.alias = alias.toLowerCase(Locale.ENGLISH);
 
@@ -2499,18 +2499,18 @@
                        // attribute in pkcs12 with one private key entry and
                        // associated cert-chain
                        if (privateKeyCount == 1) {
-                            keyId = "01".getBytes("UTF8");
+                            keyId = "01".getBytes(UTF_8);
                        } else {
                             continue;
                        }
                     } else {
                         // keyId in a SecretKeyEntry is not significant
-                        keyId = "00".getBytes("UTF8");
+                        keyId = "00".getBytes(UTF_8);
                     }
                 }
                 entry.keyId = keyId;
                 // restore date if it exists
-                String keyIdStr = new String(keyId, "UTF8");
+                String keyIdStr = new String(keyId, UTF_8);
                 Date date = null;
                 if (keyIdStr.startsWith("Time ")) {
                     try {
@@ -2547,7 +2547,7 @@
                 if ((keyId == null) && (privateKeyCount == 1)) {
                     // insert localKeyID only for EE cert or self-signed cert
                     if (i == 0) {
-                        keyId = "01".getBytes("UTF8");
+                        keyId = "01".getBytes(UTF_8);
                     }
                 }
                 // Trusted certificate
--- a/src/java.base/share/classes/sun/security/provider/ConfigFile.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/share/classes/sun/security/provider/ConfigFile.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -46,6 +46,8 @@
 import sun.security.util.PropertyExpander;
 import sun.security.util.ResourcesMgr;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 /**
  * This class represents a default implementation for
  * {@code javax.security.auth.login.Configuration}.
@@ -325,7 +327,7 @@
                           throws IOException {
 
             try (InputStreamReader isr
-                    = new InputStreamReader(getInputStream(config), "UTF-8")) {
+                    = new InputStreamReader(getInputStream(config), UTF_8)) {
                 readConfig(isr, newConfig);
             } catch (FileNotFoundException fnfe) {
                 if (debugConfig != null) {
--- a/src/java.base/share/classes/sun/security/provider/DomainKeyStore.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/share/classes/sun/security/provider/DomainKeyStore.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -33,6 +33,8 @@
 import java.security.cert.CertificateException;
 import java.util.*;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 import sun.security.pkcs.EncryptedPrivateKeyInfo;
 import sun.security.util.PolicyUtil;
 
@@ -768,7 +770,7 @@
 
         try (InputStreamReader configurationReader =
             new InputStreamReader(
-                PolicyUtil.getInputStream(configuration.toURL()), "UTF-8")) {
+                PolicyUtil.getInputStream(configuration.toURL()), UTF_8)) {
             parser.read(configurationReader);
             domains = parser.getDomainEntries();
 
--- a/src/java.base/share/classes/sun/security/provider/JavaKeyStore.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/share/classes/sun/security/provider/JavaKeyStore.java	Wed Nov 13 09:16:04 2019 +0000
@@ -32,6 +32,8 @@
 import java.security.cert.CertificateException;
 import java.util.*;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 import sun.security.pkcs.EncryptedPrivateKeyInfo;
 import sun.security.pkcs12.PKCS12KeyStore;
 import sun.security.util.Debug;
@@ -805,14 +807,14 @@
      * hash with a bit of whitener.
      */
     private MessageDigest getPreKeyedHash(char[] password)
-        throws NoSuchAlgorithmException, UnsupportedEncodingException
+        throws NoSuchAlgorithmException
     {
 
         MessageDigest md = MessageDigest.getInstance("SHA");
         byte[] passwdBytes = convertToBytes(password);
         md.update(passwdBytes);
         Arrays.fill(passwdBytes, (byte) 0x00);
-        md.update("Mighty Aphrodite".getBytes("UTF8"));
+        md.update("Mighty Aphrodite".getBytes(UTF_8));
         return md;
     }
 
--- a/src/java.base/share/classes/sun/security/provider/KeyProtector.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/share/classes/sun/security/provider/KeyProtector.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,6 @@
 package sun.security.provider;
 
 import java.io.IOException;
-import java.io.UnsupportedEncodingException;
 import java.security.Key;
 import java.security.KeyStoreException;
 import java.security.MessageDigest;
--- a/src/java.base/share/classes/sun/security/provider/PolicyFile.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/share/classes/sun/security/provider/PolicyFile.java	Wed Nov 13 09:16:04 2019 +0000
@@ -42,12 +42,14 @@
 import java.net.NetPermission;
 import java.util.concurrent.ConcurrentHashMap;
 import jdk.internal.access.JavaSecurityAccess;
-import static jdk.internal.access.JavaSecurityAccess.ProtectionDomainCache;
 import jdk.internal.access.SharedSecrets;
 import jdk.internal.util.StaticProperty;
 import sun.security.util.*;
 import sun.net.www.ParseUtil;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static jdk.internal.access.JavaSecurityAccess.ProtectionDomainCache;
+
 /**
  * This class represents a default Policy implementation for the
  * "JavaPolicy" type.
@@ -559,8 +561,7 @@
         return false;
     }
 
-    private InputStreamReader getInputStreamReader(InputStream is)
-                              throws IOException {
+    private InputStreamReader getInputStreamReader(InputStream is) {
         /*
          * Read in policy using UTF-8 by default.
          *
@@ -569,7 +570,7 @@
          */
         return (notUtf8)
             ? new InputStreamReader(is)
-            : new InputStreamReader(is, "UTF-8");
+            : new InputStreamReader(is, UTF_8);
     }
 
     private void initStaticPolicy(final PolicyInfo newInfo) {
--- a/src/java.base/share/classes/sun/security/ssl/SSLLogger.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/share/classes/sun/security/ssl/SSLLogger.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -45,6 +45,8 @@
 import sun.security.util.HexDumpEncoder;
 import sun.security.x509.*;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 /**
  * Implementation of SSL logger.
  *
@@ -229,7 +231,7 @@
                 try {
                     String formatted =
                         SSLSimpleFormatter.format(this, level, message, thrwbl);
-                    System.err.write(formatted.getBytes("UTF-8"));
+                    System.err.write(formatted.getBytes(UTF_8));
                 } catch (Exception exp) {
                     // ignore it, just for debugging.
                 }
@@ -243,7 +245,7 @@
                 try {
                     String formatted =
                         SSLSimpleFormatter.format(this, level, message, params);
-                    System.err.write(formatted.getBytes("UTF-8"));
+                    System.err.write(formatted.getBytes(UTF_8));
                 } catch (Exception exp) {
                     // ignore it, just for debugging.
                 }
--- a/src/java.base/share/classes/sun/security/util/DerInputStream.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/share/classes/sun/security/util/DerInputStream.java	Wed Nov 13 09:16:04 2019 +0000
@@ -27,9 +27,12 @@
 
 import java.io.InputStream;
 import java.io.IOException;
+import java.math.BigInteger;
+import java.nio.charset.Charset;
 import java.util.Date;
 import java.util.Vector;
-import java.math.BigInteger;
+
+import static java.nio.charset.StandardCharsets.*;
 
 /**
  * A DER input stream, used for parsing ASN.1 DER-encoded data such as
@@ -457,7 +460,7 @@
      * Read a string that was encoded as a UTF8String DER value.
      */
     public String getUTF8String() throws IOException {
-        return readString(DerValue.tag_UTF8String, "UTF-8", "UTF8");
+        return readString(DerValue.tag_UTF8String, "UTF-8", UTF_8);
     }
 
     /**
@@ -465,7 +468,7 @@
      */
     public String getPrintableString() throws IOException {
         return readString(DerValue.tag_PrintableString, "Printable",
-                          "ASCII");
+                          US_ASCII);
     }
 
     /**
@@ -475,22 +478,21 @@
         /*
          * Works for common characters between T61 and ASCII.
          */
-        return readString(DerValue.tag_T61String, "T61", "ISO-8859-1");
+        return readString(DerValue.tag_T61String, "T61", ISO_8859_1);
     }
 
     /**
-     * Read a string that was encoded as a IA5tring DER value.
+     * Read a string that was encoded as a IA5String DER value.
      */
     public String getIA5String() throws IOException {
-        return readString(DerValue.tag_IA5String, "IA5", "ASCII");
+        return readString(DerValue.tag_IA5String, "IA5", US_ASCII);
     }
 
     /**
      * Read a string that was encoded as a BMPString DER value.
      */
     public String getBMPString() throws IOException {
-        return readString(DerValue.tag_BMPString, "BMP",
-                          "UnicodeBigUnmarked");
+        return readString(DerValue.tag_BMPString, "BMP", UTF_16BE);
     }
 
     /**
@@ -498,7 +500,7 @@
      */
     public String getGeneralString() throws IOException {
         return readString(DerValue.tag_GeneralString, "General",
-                          "ASCII");
+                          US_ASCII);
     }
 
     /**
@@ -510,7 +512,7 @@
      * correspond to the stringTag above.
      */
     private String readString(byte stringTag, String stringName,
-                              String enc) throws IOException {
+                              Charset charset) throws IOException {
 
         if (buffer.read() != stringTag)
             throw new IOException("DER input not a " +
@@ -522,7 +524,7 @@
             throw new IOException("Short read of DER " +
                                   stringName + " string");
 
-        return new String(retval, enc);
+        return new String(retval, charset);
     }
 
     /**
--- a/src/java.base/share/classes/sun/security/util/DerOutputStream.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/share/classes/sun/security/util/DerOutputStream.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -28,14 +28,16 @@
 import java.io.ByteArrayOutputStream;
 import java.io.OutputStream;
 import java.io.IOException;
+import java.math.BigInteger;
+import java.nio.charset.Charset;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.TimeZone;
 import java.util.Comparator;
 import java.util.Arrays;
-import java.math.BigInteger;
 import java.util.Locale;
 
+import static java.nio.charset.StandardCharsets.*;
 
 /**
  * Output stream marshaling DER-encoded data.  This is eventually provided
@@ -398,14 +400,14 @@
      * Marshals a string as a DER encoded UTF8String.
      */
     public void putUTF8String(String s) throws IOException {
-        writeString(s, DerValue.tag_UTF8String, "UTF8");
+        writeString(s, DerValue.tag_UTF8String, UTF_8);
     }
 
     /**
      * Marshals a string as a DER encoded PrintableString.
      */
     public void putPrintableString(String s) throws IOException {
-        writeString(s, DerValue.tag_PrintableString, "ASCII");
+        writeString(s, DerValue.tag_PrintableString, US_ASCII);
     }
 
     /**
@@ -416,28 +418,28 @@
          * Works for characters that are defined in both ASCII and
          * T61.
          */
-        writeString(s, DerValue.tag_T61String, "ISO-8859-1");
+        writeString(s, DerValue.tag_T61String, ISO_8859_1);
     }
 
     /**
      * Marshals a string as a DER encoded IA5String.
      */
     public void putIA5String(String s) throws IOException {
-        writeString(s, DerValue.tag_IA5String, "ASCII");
+        writeString(s, DerValue.tag_IA5String, US_ASCII);
     }
 
     /**
      * Marshals a string as a DER encoded BMPString.
      */
     public void putBMPString(String s) throws IOException {
-        writeString(s, DerValue.tag_BMPString, "UnicodeBigUnmarked");
+        writeString(s, DerValue.tag_BMPString, UTF_16BE);
     }
 
     /**
      * Marshals a string as a DER encoded GeneralString.
      */
     public void putGeneralString(String s) throws IOException {
-        writeString(s, DerValue.tag_GeneralString, "ASCII");
+        writeString(s, DerValue.tag_GeneralString, US_ASCII);
     }
 
     /**
@@ -448,10 +450,10 @@
      * @param enc the name of the encoder that should be used corresponding
      * to the above tag.
      */
-    private void writeString(String s, byte stringTag, String enc)
+    private void writeString(String s, byte stringTag, Charset charset)
         throws IOException {
 
-        byte[] data = s.getBytes(enc);
+        byte[] data = s.getBytes(charset);
         write(stringTag);
         putLength(data.length);
         write(data);
@@ -502,7 +504,7 @@
 
         SimpleDateFormat sdf = new SimpleDateFormat(pattern, Locale.US);
         sdf.setTimeZone(tz);
-        byte[] time = (sdf.format(d)).getBytes("ISO-8859-1");
+        byte[] time = (sdf.format(d)).getBytes(ISO_8859_1);
 
         /*
          * Write the formatted date.
--- a/src/java.base/share/classes/sun/security/util/DerValue.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/share/classes/sun/security/util/DerValue.java	Wed Nov 13 09:16:04 2019 +0000
@@ -27,8 +27,11 @@
 
 import java.io.*;
 import java.math.BigInteger;
+import java.nio.charset.Charset;
 import java.util.Date;
 
+import static java.nio.charset.StandardCharsets.*;
+
 /**
  * Represents a single DER-encoded value.  DER encoding rules are a subset
  * of the "Basic" Encoding Rules (BER), but they only support a single way
@@ -204,7 +207,7 @@
     /**
      * Creates a PrintableString or UTF8string DER value from a string
      */
-    public DerValue(String value) throws IOException {
+    public DerValue(String value) {
         boolean isPrintableString = true;
         for (int i = 0; i < value.length(); i++) {
             if (!isPrintableStringChar(value.charAt(i))) {
@@ -221,7 +224,7 @@
      * @param stringTag the tag for the DER value to create
      * @param value the String object to use for the DER value
      */
-    public DerValue(byte stringTag, String value) throws IOException {
+    public DerValue(byte stringTag, String value) {
         data = init(stringTag, value);
     }
 
@@ -337,9 +340,8 @@
         this(in, true);
     }
 
-    private DerInputStream init(byte stringTag, String value)
-        throws IOException {
-        String enc = null;
+    private DerInputStream init(byte stringTag, String value) {
+        final Charset charset;
 
         tag = stringTag;
 
@@ -347,16 +349,16 @@
         case tag_PrintableString:
         case tag_IA5String:
         case tag_GeneralString:
-            enc = "ASCII";
+            charset = US_ASCII;
             break;
         case tag_T61String:
-            enc = "ISO-8859-1";
+            charset = ISO_8859_1;
             break;
         case tag_BMPString:
-            enc = "UnicodeBigUnmarked";
+            charset = UTF_16BE;
             break;
         case tag_UTF8String:
-            enc = "UTF8";
+            charset = UTF_8;
             break;
             // TBD: Need encoder for UniversalString before it can
             // be handled.
@@ -364,7 +366,7 @@
             throw new IllegalArgumentException("Unsupported DER string type");
         }
 
-        byte[] buf = value.getBytes(enc);
+        byte[] buf = value.getBytes(charset);
         length = buf.length;
         buffer = new DerInputBuffer(buf, true);
         DerInputStream result = new DerInputStream(buffer);
@@ -665,7 +667,7 @@
             throw new IOException(
                 "DerValue.getPrintableString, not a string " + tag);
 
-        return new String(getDataBytes(), "ASCII");
+        return new String(getDataBytes(), US_ASCII);
     }
 
     /**
@@ -678,7 +680,7 @@
             throw new IOException(
                 "DerValue.getT61String, not T61 " + tag);
 
-        return new String(getDataBytes(), "ISO-8859-1");
+        return new String(getDataBytes(), ISO_8859_1);
     }
 
     /**
@@ -691,7 +693,7 @@
             throw new IOException(
                 "DerValue.getIA5String, not IA5 " + tag);
 
-        return new String(getDataBytes(), "ASCII");
+        return new String(getDataBytes(), US_ASCII);
     }
 
     /**
@@ -707,7 +709,7 @@
 
         // BMPString is the same as Unicode in big endian, unmarked
         // format.
-        return new String(getDataBytes(), "UnicodeBigUnmarked");
+        return new String(getDataBytes(), UTF_16BE);
     }
 
     /**
@@ -721,7 +723,7 @@
             throw new IOException(
                 "DerValue.getUTF8String, not UTF-8 " + tag);
 
-        return new String(getDataBytes(), "UTF8");
+        return new String(getDataBytes(), UTF_8);
     }
 
     /**
@@ -735,7 +737,7 @@
             throw new IOException(
                 "DerValue.getGeneralString, not GeneralString " + tag);
 
-        return new String(getDataBytes(), "ASCII");
+        return new String(getDataBytes(), US_ASCII);
     }
 
     /**
--- a/src/java.base/share/classes/sun/security/util/DomainName.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/share/classes/sun/security/util/DomainName.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -45,6 +45,8 @@
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 import sun.security.ssl.SSLLogger;
 
 /**
@@ -151,7 +153,7 @@
         private final boolean hasExceptions;
 
         private Rules(InputStream is) throws IOException {
-            InputStreamReader isr = new InputStreamReader(is, "UTF-8");
+            InputStreamReader isr = new InputStreamReader(is, UTF_8);
             BufferedReader reader = new BufferedReader(isr);
             boolean hasExceptions = false;
 
--- a/src/java.base/share/classes/sun/security/util/HexDumpEncoder.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/share/classes/sun/security/util/HexDumpEncoder.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -34,6 +34,8 @@
 import java.io.IOException;
 import java.nio.ByteBuffer;
 
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
+
 /**
  * This class encodes a buffer into the classic: "Hexadecimal Dump" format of
  * the past. It is useful for analyzing the contents of binary buffers.
@@ -183,17 +185,15 @@
      */
     public String encode(byte aBuffer[]) {
         ByteArrayOutputStream outStream = new ByteArrayOutputStream();
-        ByteArrayInputStream    inStream = new ByteArrayInputStream(aBuffer);
-        String retVal = null;
+        ByteArrayInputStream inStream = new ByteArrayInputStream(aBuffer);
         try {
             encode(inStream, outStream);
             // explicit ascii->unicode conversion
-            retVal = outStream.toString("ISO-8859-1");
-        } catch (Exception IOException) {
+            return outStream.toString(ISO_8859_1);
+        } catch (IOException ignore) {
             // This should never happen.
             throw new Error("CharacterEncoder.encode internal error");
         }
-        return (retVal);
     }
 
     /**
--- a/src/java.base/share/classes/sun/security/x509/AVA.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/share/classes/sun/security/x509/AVA.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -33,6 +33,8 @@
 import java.text.Normalizer;
 import java.util.*;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 import sun.security.action.GetBooleanAction;
 import sun.security.util.*;
 import sun.security.pkcs.PKCS9Attribute;
@@ -525,14 +527,13 @@
         return null;
     }
 
-    private static String getEmbeddedHexString(List<Byte> hexList)
-                                                throws IOException {
+    private static String getEmbeddedHexString(List<Byte> hexList) {
         int n = hexList.size();
         byte[] hexBytes = new byte[n];
         for (int i = 0; i < n; i++) {
-                hexBytes[i] = hexList.get(i).byteValue();
+            hexBytes[i] = hexList.get(i).byteValue();
         }
-        return new String(hexBytes, "UTF8");
+        return new String(hexBytes, UTF_8);
     }
 
     private static boolean isTerminator(int ch, int format) {
@@ -752,7 +753,7 @@
              */
             String valStr = null;
             try {
-                valStr = new String(value.getDataBytes(), "UTF8");
+                valStr = new String(value.getDataBytes(), UTF_8);
             } catch (IOException ie) {
                 throw new IllegalArgumentException("DER Value conversion");
             }
@@ -804,13 +805,7 @@
 
                     // embed non-printable/non-escaped char
                     // as escaped hex pairs for debugging
-                    byte[] valueBytes = null;
-                    try {
-                        valueBytes = Character.toString(c).getBytes("UTF8");
-                    } catch (IOException ie) {
-                        throw new IllegalArgumentException
-                                        ("DER Value conversion");
-                    }
+                    byte[] valueBytes = Character.toString(c).getBytes(UTF_8);
                     for (int j = 0; j < valueBytes.length; j++) {
                         sbuffer.append('\\');
                         char hexChar = Character.forDigit
@@ -905,7 +900,7 @@
              */
             String valStr = null;
             try {
-                valStr = new String(value.getDataBytes(), "UTF8");
+                valStr = new String(value.getDataBytes(), UTF_8);
             } catch (IOException ie) {
                 throw new IllegalArgumentException("DER Value conversion");
             }
@@ -966,13 +961,7 @@
 
                     previousWhite = false;
 
-                    byte[] valueBytes = null;
-                    try {
-                        valueBytes = Character.toString(c).getBytes("UTF8");
-                    } catch (IOException ie) {
-                        throw new IllegalArgumentException
-                                        ("DER Value conversion");
-                    }
+                    byte[] valueBytes = Character.toString(c).getBytes(UTF_8);
                     for (int j = 0; j < valueBytes.length; j++) {
                         sbuffer.append('\\');
                         sbuffer.append(Character.forDigit
@@ -1116,7 +1105,7 @@
 
                         // embed escaped hex pairs
                         byte[] valueBytes =
-                                Character.toString(c).getBytes("UTF8");
+                                Character.toString(c).getBytes(UTF_8);
                         for (int j = 0; j < valueBytes.length; j++) {
                             sbuffer.append('\\');
                             char hexChar = Character.forDigit
--- a/src/java.base/share/classes/sun/security/x509/X509CertImpl.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/share/classes/sun/security/x509/X509CertImpl.java	Wed Nov 13 09:16:04 2019 +0000
@@ -45,6 +45,8 @@
 import sun.security.util.*;
 import sun.security.provider.X509Factory;
 
+import static java.nio.charset.StandardCharsets.US_ASCII;
+
 /**
  * The X509CertImpl class represents an X.509 certificate. These certificates
  * are widely used to support authentication and other functionality in
@@ -250,7 +252,7 @@
         DerValue der = null;
         String line = null;
         BufferedReader certBufferedReader =
-            new BufferedReader(new InputStreamReader(in, "ASCII"));
+            new BufferedReader(new InputStreamReader(in, US_ASCII));
         try {
             line = certBufferedReader.readLine();
         } catch (IOException ioe1) {
--- a/src/java.base/share/classes/sun/util/locale/provider/HostLocaleProviderAdapter.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/share/classes/sun/util/locale/provider/HostLocaleProviderAdapter.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.text.DecimalFormat;
 import java.util.spi.LocaleServiceProvider;
 
 /**
@@ -60,4 +61,19 @@
         }
         return null;
     }
+
+    /**
+     * Utility to make the decimal format specific to integer, called
+     * by the platform dependent adapter implementations.
+     *
+     * @param df A DecimalFormat object
+     * @return The same DecimalFormat object in the argument, modified
+     *          to allow integer formatting/parsing only.
+     */
+    static DecimalFormat makeIntegerFormatter(DecimalFormat df) {
+        df.setMaximumFractionDigits(0);
+        df.setDecimalSeparatorAlwaysShown(false);
+        df.setParseIntegerOnly(true);
+        return df;
+    }
 }
--- a/src/java.base/share/native/libjli/args.c	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/share/native/libjli/args.c	Wed Nov 13 09:16:04 2019 +0000
@@ -337,7 +337,9 @@
     // remaining partial token
     if (ctx.state == IN_TOKEN || ctx.state == IN_QUOTE) {
         if (ctx.parts->size != 0) {
-            JLI_List_add(rv, JLI_List_combine(ctx.parts));
+            token = JLI_List_combine(ctx.parts);
+            checkArg(token);
+            JLI_List_add(rv, token);
         }
     }
     JLI_List_free(ctx.parts);
--- a/src/java.base/windows/classes/sun/util/locale/provider/HostLocaleProviderAdapterImpl.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/windows/classes/sun/util/locale/provider/HostLocaleProviderAdapterImpl.java	Wed Nov 13 09:16:04 2019 +0000
@@ -258,8 +258,9 @@
             @Override
             public NumberFormat getIntegerInstance(Locale locale) {
                 AtomicReferenceArray<String> patterns = getNumberPatterns(locale);
-                return new DecimalFormat(patterns.get(NF_INTEGER),
+                DecimalFormat format = new DecimalFormat(patterns.get(NF_INTEGER),
                     DecimalFormatSymbols.getInstance(locale));
+                return HostLocaleProviderAdapter.makeIntegerFormatter(format);
             }
 
             @Override
--- a/src/java.base/windows/native/libjava/HostLocaleProviderAdapter_md.c	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.base/windows/native/libjava/HostLocaleProviderAdapter_md.c	Wed Nov 13 09:16:04 2019 +0000
@@ -910,7 +910,7 @@
     if (digits > 0) {
         int i;
         for(i = digits;  i > 0; i--) {
-            fractionPattern[i] = L'0';
+            fractionPattern[i] = L'#';
         }
         fractionPattern[0] = L'.';
         fractionPattern[digits+1] = L'\0';
--- a/src/java.net.http/share/classes/jdk/internal/net/http/AuthenticationFilter.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/AuthenticationFilter.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -32,7 +32,6 @@
 import java.net.InetSocketAddress;
 import java.net.URISyntaxException;
 import java.net.URL;
-import java.nio.charset.Charset;
 import java.util.Base64;
 import java.util.LinkedList;
 import java.util.List;
@@ -380,10 +379,18 @@
             return null;
         }
 
+        private static boolean equalsIgnoreCase(String s1, String s2) {
+            return s1 == s2 || (s1 != null && s1.equalsIgnoreCase(s2));
+        }
+
         synchronized void remove(String authscheme, URI domain, boolean proxy) {
-            for (CacheEntry entry : entries) {
-                if (entry.equalsKey(domain, proxy)) {
-                    entries.remove(entry);
+            var iterator = entries.iterator();
+            while (iterator.hasNext()) {
+                var entry = iterator.next();
+                if (equalsIgnoreCase(entry.scheme, authscheme)) {
+                    if (entry.equalsKey(domain, proxy)) {
+                        iterator.remove();
+                    }
                 }
             }
         }
--- a/src/java.security.jgss/share/classes/javax/security/auth/kerberos/KerberosPrincipal.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.security.jgss/share/classes/javax/security/auth/kerberos/KerberosPrincipal.java	Wed Nov 13 09:16:04 2019 +0000
@@ -82,6 +82,8 @@
 
     /**
      * Enterprise name (alias)
+     *
+     * @since 13
      */
     public static final int KRB_NT_ENTERPRISE = 10;
 
--- a/src/java.security.jgss/share/classes/sun/security/jgss/GSSNameImpl.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.security.jgss/share/classes/sun/security/jgss/GSSNameImpl.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -32,11 +32,12 @@
 import java.util.HashSet;
 import java.util.Arrays;
 import java.io.IOException;
-import java.io.UnsupportedEncodingException;
 import sun.security.util.ObjectIdentifier;
 import sun.security.util.DerInputStream;
 import sun.security.util.DerOutputStream;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 /**
  * This is the implementation class for GSSName. Conceptually the
  * GSSName is a container with mechanism specific name elements. Each
@@ -227,13 +228,10 @@
         byte[] bytes = null;
 
         if (appName instanceof String) {
-            try {
-                bytes = ((String) appName).getBytes("UTF-8");
-            } catch (UnsupportedEncodingException e) {
-                // Won't happen
-            }
-        } else
+            bytes = ((String) appName).getBytes(UTF_8);
+        } else {
             bytes = (byte[]) appName;
+        }
 
         if ((bytes[pos++] != 0x04) ||
             (bytes[pos++] != 0x01))
@@ -320,21 +318,14 @@
             if (!this.appNameType.equals(that.appNameType)) {
                 return false;
             }
-            byte[] myBytes = null;
-            byte[] bytes = null;
-            try {
-                myBytes =
+            byte[] myBytes =
                     (this.appNameStr != null ?
-                     this.appNameStr.getBytes("UTF-8") :
+                     this.appNameStr.getBytes(UTF_8) :
                      this.appNameBytes);
-                bytes =
+            byte[] bytes =
                     (that.appNameStr != null ?
-                     that.appNameStr.getBytes("UTF-8") :
+                     that.appNameStr.getBytes(UTF_8) :
                      that.appNameBytes);
-            } catch (UnsupportedEncodingException e) {
-                // Won't happen
-            }
-
             return Arrays.equals(myBytes, bytes);
         }
 
--- a/src/java.security.jgss/share/classes/sun/security/jgss/krb5/Krb5NameElement.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.security.jgss/share/classes/sun/security/jgss/krb5/Krb5NameElement.java	Wed Nov 13 09:16:04 2019 +0000
@@ -32,12 +32,13 @@
 import sun.security.krb5.KrbException;
 
 import javax.security.auth.kerberos.ServicePermission;
-import java.io.UnsupportedEncodingException;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.security.Provider;
 import java.util.Locale;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 /**
  * Implements the GSSNameSpi for the krb5 mechanism.
  *
@@ -51,9 +52,6 @@
     private String gssNameStr = null;
     private Oid gssNameType = null;
 
-    // XXX Move this concept into PrincipalName's asn1Encode() sometime
-    private static String CHAR_ENCODING = "UTF-8";
-
     private Krb5NameElement(PrincipalName principalName,
                             String gssNameStr,
                             Oid gssNameType) {
@@ -285,13 +283,7 @@
      */
     public byte[] export() throws GSSException {
         // XXX Apply the above constraints.
-        byte[] retVal = null;
-        try {
-            retVal = krb5PrincipalName.getName().getBytes(CHAR_ENCODING);
-        } catch (UnsupportedEncodingException e) {
-            // Can't happen
-        }
-        return retVal;
+        return krb5PrincipalName.getName().getBytes(UTF_8);
     }
 
     /**
--- a/src/java.security.jgss/share/classes/sun/security/jgss/wrapper/GSSNameElement.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.security.jgss/share/classes/sun/security/jgss/wrapper/GSSNameElement.java	Wed Nov 13 09:16:04 2019 +0000
@@ -29,7 +29,6 @@
 import java.security.Provider;
 import java.security.Security;
 import java.io.IOException;
-import java.io.UnsupportedEncodingException;
 import sun.security.krb5.Realm;
 import sun.security.jgss.GSSUtil;
 import sun.security.util.ObjectIdentifier;
--- a/src/java.security.jgss/share/classes/sun/security/jgss/wrapper/NativeGSSFactory.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.security.jgss/share/classes/sun/security/jgss/wrapper/NativeGSSFactory.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,6 @@
 
 package sun.security.jgss.wrapper;
 
-import java.io.UnsupportedEncodingException;
 import java.security.Provider;
 import java.util.Vector;
 import org.ietf.jgss.*;
@@ -34,6 +33,8 @@
 import sun.security.jgss.GSSExceptionImpl;
 import sun.security.jgss.spi.*;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 /**
  * JGSS plugin for generic mechanisms provided through native GSS framework.
  *
@@ -80,14 +81,9 @@
 
     public GSSNameSpi getNameElement(String nameStr, Oid nameType)
         throws GSSException {
-        try {
-            byte[] nameBytes =
-                (nameStr == null ? null : nameStr.getBytes("UTF-8"));
-            return new GSSNameElement(nameBytes, nameType, cStub);
-        } catch (UnsupportedEncodingException uee) {
-            // Shouldn't happen
-            throw new GSSExceptionImpl(GSSException.FAILURE, uee);
-        }
+        byte[] nameBytes =
+                (nameStr == null ? null : nameStr.getBytes(UTF_8));
+        return new GSSNameElement(nameBytes, nameType, cStub);
     }
 
     public GSSNameSpi getNameElement(byte[] name, Oid nameType)
--- a/src/java.security.jgss/share/classes/sun/security/krb5/internal/ETypeInfo.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.security.jgss/share/classes/sun/security/krb5/internal/ETypeInfo.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,10 +25,13 @@
 
 package sun.security.krb5.internal;
 
-import sun.security.util.*;
+import java.io.IOException;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 import sun.security.krb5.Asn1Exception;
-import java.io.IOException;
 import sun.security.krb5.internal.util.KerberosString;
+import sun.security.util.*;
 
 /**
  * Implements the ASN.1 ETYPE-INFO-ENTRY type.
@@ -99,7 +102,7 @@
                 // KerberosString in most implementations.
 
                 if (KerberosString.MSNAME) {
-                    this.salt = new String(saltBytes, "UTF8");
+                    this.salt = new String(saltBytes, UTF_8);
                 } else {
                     this.salt = new String(saltBytes);
                 }
@@ -129,7 +132,7 @@
         if (salt != null) {
             temp = new DerOutputStream();
             if (KerberosString.MSNAME) {
-                temp.putOctetString(salt.getBytes("UTF8"));
+                temp.putOctetString(salt.getBytes(UTF_8));
             } else {
                 temp.putOctetString(salt.getBytes());
             }
--- a/src/java.security.jgss/share/classes/sun/security/krb5/internal/PAData.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.security.jgss/share/classes/sun/security/krb5/internal/PAData.java	Wed Nov 13 09:16:04 2019 +0000
@@ -31,13 +31,15 @@
 
 package sun.security.krb5.internal;
 
-import sun.security.krb5.internal.crypto.EType;
-import sun.security.util.*;
-import sun.security.krb5.Asn1Exception;
 import java.io.IOException;
 import java.util.Vector;
 
+import static java.nio.charset.StandardCharsets.*;
+
+import sun.security.krb5.Asn1Exception;
 import sun.security.krb5.internal.util.KerberosString;
+import sun.security.krb5.internal.crypto.EType;
+import sun.security.util.*;
 
 /**
  * Implements the ASN.1 PA-DATA type.
@@ -263,7 +265,7 @@
             switch (p.getType()) {
                 case Krb5.PA_PW_SALT:
                     paPwSalt = new String(p.getValue(),
-                            KerberosString.MSNAME?"UTF8":"8859_1");
+                            KerberosString.MSNAME ? UTF_8 : ISO_8859_1);
                     break;
                 case Krb5.PA_ETYPE_INFO:
                     d = new DerValue(p.getValue());
--- a/src/java.security.jgss/share/classes/sun/security/krb5/internal/PAForUserEnc.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.security.jgss/share/classes/sun/security/krb5/internal/PAForUserEnc.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -33,6 +33,8 @@
 import sun.security.util.DerOutputStream;
 import sun.security.util.DerValue;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 /**
  * Implements the ASN.1 PA-FOR-USER type.
  *
@@ -163,25 +165,20 @@
      * 4. the string value of auth-package field
      */
     public byte[] getS4UByteArray() {
-        try {
-            ByteArrayOutputStream ba = new ByteArrayOutputStream();
-            ba.write(new byte[4]);
-            for (String s: name.getNameStrings()) {
-                ba.write(s.getBytes("UTF-8"));
-            }
-            ba.write(name.getRealm().toString().getBytes("UTF-8"));
-            ba.write(AUTH_PACKAGE.getBytes("UTF-8"));
-            byte[] output = ba.toByteArray();
-            int pnType = name.getNameType();
-            output[0] = (byte)(pnType & 0xff);
-            output[1] = (byte)((pnType>>8) & 0xff);
-            output[2] = (byte)((pnType>>16) & 0xff);
-            output[3] = (byte)((pnType>>24) & 0xff);
-            return output;
-        } catch (IOException ioe) {
-            // not possible
-            throw new AssertionError("Cannot write ByteArrayOutputStream", ioe);
+        ByteArrayOutputStream ba = new ByteArrayOutputStream();
+        ba.writeBytes(new byte[4]);
+        for (String s: name.getNameStrings()) {
+            ba.writeBytes(s.getBytes(UTF_8));
         }
+        ba.writeBytes(name.getRealm().toString().getBytes(UTF_8));
+        ba.writeBytes(AUTH_PACKAGE.getBytes(UTF_8));
+        byte[] output = ba.toByteArray();
+        int pnType = name.getNameType();
+        output[0] = (byte)(pnType & 0xff);
+        output[1] = (byte)((pnType>>8) & 0xff);
+        output[2] = (byte)((pnType>>16) & 0xff);
+        output[3] = (byte)((pnType>>24) & 0xff);
+        return output;
     }
 
     public String toString() {
--- a/src/java.security.jgss/share/classes/sun/security/krb5/internal/ccache/FileCredentialsCache.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.security.jgss/share/classes/sun/security/krb5/internal/ccache/FileCredentialsCache.java	Wed Nov 13 09:16:04 2019 +0000
@@ -51,6 +51,8 @@
 import java.io.BufferedReader;
 import java.io.InputStreamReader;
 
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
+
 /**
  * CredentialsCache stores credentials(tickets, session keys, etc) in a
  * semi-permanent store
@@ -594,7 +596,7 @@
 
             BufferedReader commandResult =
                 new BufferedReader
-                    (new InputStreamReader(p.getInputStream(), "8859_1"));
+                    (new InputStreamReader(p.getInputStream(), ISO_8859_1));
             String s1 = null;
             if ((command.length == 1) &&
                 (command[0].equals("/usr/bin/env"))) {
--- a/src/java.security.jgss/share/classes/sun/security/krb5/internal/crypto/dk/AesDkCrypto.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.security.jgss/share/classes/sun/security/krb5/internal/crypto/dk/AesDkCrypto.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -43,6 +43,8 @@
 import sun.security.krb5.internal.crypto.KeyUsage;
 import java.util.Arrays;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 /**
  * This class provides the implementation of AES Encryption for Kerberos
  * as defined RFC 3962.
@@ -104,7 +106,7 @@
 
         byte[] saltUtf8 = null;
         try {
-            saltUtf8 = salt.getBytes("UTF-8");
+            saltUtf8 = salt.getBytes(UTF_8);
             return stringToKey(password, saltUtf8, s2kparams);
         } catch (Exception e) {
             return null;
--- a/src/java.security.jgss/share/classes/sun/security/krb5/internal/crypto/dk/AesSha2DkCrypto.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.security.jgss/share/classes/sun/security/krb5/internal/crypto/dk/AesSha2DkCrypto.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -41,6 +41,8 @@
 import sun.security.krb5.internal.crypto.KeyUsage;
 import java.util.Arrays;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 /**
  * This class provides the implementation of AES Encryption with
  * HMAC-SHA2 for Kerberos 5
@@ -107,7 +109,7 @@
 
         byte[] saltUtf8 = null;
         try {
-            saltUtf8 = salt.getBytes("UTF-8");
+            saltUtf8 = salt.getBytes(UTF_8);
             return stringToKey(password, saltUtf8, s2kparams);
         } catch (Exception e) {
             return null;
--- a/src/java.security.jgss/share/classes/sun/security/krb5/internal/crypto/dk/DkCrypto.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.security.jgss/share/classes/sun/security/krb5/internal/crypto/dk/DkCrypto.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2019, Oracle and/or its affiliates. All rights reserved.
  */
 
 /*
@@ -33,7 +33,6 @@
 import javax.crypto.Cipher;
 import javax.crypto.Mac;
 import java.security.GeneralSecurityException;
-import java.io.UnsupportedEncodingException;
 import java.util.Arrays;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -45,6 +44,8 @@
 import sun.security.krb5.internal.crypto.KeyUsage;
 import sun.security.krb5.KrbCryptoException;
 
+import static java.nio.charset.StandardCharsets.*;
+
 /**
  * Implements Derive Key cryptography functionality as defined in RFC 3961.
  * http://www.ietf.org/rfc/rfc3961.txt
@@ -672,13 +673,11 @@
         }
     }
 
-// String.getBytes("UTF-8");
+// String.getBytes(UTF_8);
 // Do this instead of using String to avoid making password immutable
     static byte[] charToUtf8(char[] chars) {
-        Charset utf8 = Charset.forName("UTF-8");
-
         CharBuffer cb = CharBuffer.wrap(chars);
-        ByteBuffer bb = utf8.encode(cb);
+        ByteBuffer bb = UTF_8.encode(cb);
         int len = bb.limit();
         byte[] answer = new byte[len];
         bb.get(answer, 0, len);
@@ -686,10 +685,8 @@
     }
 
     static byte[] charToUtf16(char[] chars) {
-        Charset utf8 = Charset.forName("UTF-16LE");
-
         CharBuffer cb = CharBuffer.wrap(chars);
-        ByteBuffer bb = utf8.encode(cb);
+        ByteBuffer bb = UTF_16LE.encode(cb);
         int len = bb.limit();
         byte[] answer = new byte[len];
         bb.get(answer, 0, len);
--- a/src/java.security.jgss/share/classes/sun/security/krb5/internal/ktab/KeyTabEntry.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.security.jgss/share/classes/sun/security/krb5/internal/ktab/KeyTabEntry.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,4 +1,5 @@
 /*
+ * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -32,7 +33,8 @@
 
 import sun.security.krb5.*;
 import sun.security.krb5.internal.*;
-import java.io.UnsupportedEncodingException;
+
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
 
 /**
  * This class represents a Key Table entry. Each entry contains the service principal of
@@ -83,17 +85,10 @@
         int totalPrincipalLength = 0;
         String[] names = service.getNameStrings();
         for (int i = 0; i < names.length; i++) {
-            try {
-                totalPrincipalLength += principalSize + names[i].getBytes("8859_1").length;
-            } catch (UnsupportedEncodingException exc) {
-            }
+            totalPrincipalLength += principalSize + names[i].getBytes(ISO_8859_1).length;
         }
 
-        int realmLen = 0;
-        try {
-            realmLen = realm.toString().getBytes("8859_1").length;
-        } catch (UnsupportedEncodingException exc) {
-        }
+        int realmLen = realm.toString().getBytes(ISO_8859_1).length;
 
         int size = principalComponentSize +  realmSize + realmLen
             + totalPrincipalLength + principalTypeSize
--- a/src/java.security.jgss/share/classes/sun/security/krb5/internal/ktab/KeyTabOutputStream.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.security.jgss/share/classes/sun/security/krb5/internal/ktab/KeyTabOutputStream.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,4 +1,5 @@
 /*
+ * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -35,7 +36,8 @@
 import java.io.IOException;
 import java.io.FileOutputStream;
 import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
+
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
 
 /**
  * This class implements a buffered input stream. It is used for parsing key table
@@ -68,21 +70,16 @@
         }
         else write16(comp_num);
 
-        byte[] realm = null;
-        try {
-            realm = entry.service.getRealmString().getBytes("8859_1");
-        } catch (UnsupportedEncodingException exc) {
-        }
-
+        byte[] realm = entry.service.getRealmString().getBytes(ISO_8859_1);
         write16(realm.length);
         write(realm);
+
         for (int i = 0; i < comp_num; i++) {
-            try {
-                write16(serviceNames[i].getBytes("8859_1").length);
-                write(serviceNames[i].getBytes("8859_1"));
-            } catch (UnsupportedEncodingException exc) {
-            }
+            byte[] serviceName = serviceNames[i].getBytes(ISO_8859_1);
+            write16(serviceName.length);
+            write(serviceName);
         }
+
         write32(entry.service.getNameType());
         //time is long, but we only use 4 bytes to store the data.
         write32((int)(entry.timestamp.getTime()/1000));
--- a/src/java.security.jgss/share/classes/sun/security/krb5/internal/util/KerberosString.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.security.jgss/share/classes/sun/security/krb5/internal/util/KerberosString.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -29,6 +29,8 @@
 import sun.security.action.GetPropertyAction;
 import sun.security.util.DerValue;
 
+import static java.nio.charset.StandardCharsets.*;
+
 /**
  * Implements the ASN.1 KerberosString type.
  *
@@ -71,17 +73,17 @@
             throw new IOException(
                 "KerberosString's tag is incorrect: " + der.tag);
         }
-        s = new String(der.getDataBytes(), MSNAME?"UTF8":"ASCII");
+        s = new String(der.getDataBytes(), MSNAME ? UTF_8 : US_ASCII);
     }
 
     public String toString() {
         return s;
     }
 
-    public DerValue toDerValue() throws IOException {
+    public DerValue toDerValue() {
         // No need to cache the result since this method is
         // only called once.
         return new DerValue(DerValue.tag_GeneralString,
-                s.getBytes(MSNAME?"UTF8":"ASCII"));
+                s.getBytes(MSNAME ? UTF_8 : US_ASCII));
     }
 }
--- a/src/java.security.sasl/share/classes/com/sun/security/sasl/ClientFactoryImpl.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.security.sasl/share/classes/com/sun/security/sasl/ClientFactoryImpl.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -36,6 +36,8 @@
 import javax.security.auth.callback.PasswordCallback;
 import javax.security.auth.callback.UnsupportedCallbackException;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 /**
   * Client factory for EXTERNAL, CRAM-MD5, PLAIN.
   *
@@ -141,7 +143,7 @@
             String authId;
 
             if (pw != null) {
-                bytepw = new String(pw).getBytes("UTF8");
+                bytepw = new String(pw).getBytes(UTF_8);
                 pcb.clearPassword();
             } else {
                 bytepw = null;
--- a/src/java.security.sasl/share/classes/com/sun/security/sasl/CramMD5Client.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.security.sasl/share/classes/com/sun/security/sasl/CramMD5Client.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -31,6 +31,8 @@
 import java.util.logging.Logger;
 import java.util.logging.Level;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 /**
   * Implements the CRAM-MD5 SASL client-side mechanism.
   * (<A HREF="http://www.ietf.org/rfc/rfc2195.txt">RFC 2195</A>).
@@ -82,8 +84,8 @@
      *        data from the server.
      * @return A non-null byte array containing the response to be sent to
      *        the server.
-     * @throws SaslException If platform does not have MD5 support
-     * @throw IllegalStateException if this method is invoked more than once.
+     * @throws SaslException if platform does not have MD5 support
+     * @throws IllegalStateException if this method is invoked more than once.
      */
     public byte[] evaluateChallenge(byte[] challengeData)
         throws SaslException {
@@ -103,7 +105,7 @@
         try {
             if (logger.isLoggable(Level.FINE)) {
                 logger.log(Level.FINE, "CRAMCLNT01:Received challenge: {0}",
-                    new String(challengeData, "UTF8"));
+                    new String(challengeData, UTF_8));
             }
 
             String digest = HMAC_MD5(pw, challengeData);
@@ -118,13 +120,10 @@
 
             completed = true;
 
-            return resp.getBytes("UTF8");
+            return resp.getBytes(UTF_8);
         } catch (java.security.NoSuchAlgorithmException e) {
             aborted = true;
             throw new SaslException("MD5 algorithm not available on platform", e);
-        } catch (java.io.UnsupportedEncodingException e) {
-            aborted = true;
-            throw new SaslException("UTF8 not available on platform", e);
         }
     }
 }
--- a/src/java.security.sasl/share/classes/com/sun/security/sasl/CramMD5Server.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.security.sasl/share/classes/com/sun/security/sasl/CramMD5Server.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,15 +25,15 @@
 
 package com.sun.security.sasl;
 
+import java.io.IOException;
+import java.security.NoSuchAlgorithmException;
+import java.util.logging.Level;
+import java.util.Map;
+import java.util.Random;
 import javax.security.sasl.*;
 import javax.security.auth.callback.*;
-import java.util.Random;
-import java.util.Map;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.security.NoSuchAlgorithmException;
 
-import java.util.logging.Level;
+import static java.nio.charset.StandardCharsets.UTF_8;
 
 /**
   * Implements the CRAM-MD5 SASL server-side mechanism.
@@ -130,7 +130,7 @@
                 logger.log(Level.FINE,
                     "CRAMSRV01:Generated challenge: {0}", challengeStr);
 
-                challengeData = challengeStr.getBytes("UTF8");
+                challengeData = challengeStr.getBytes(UTF_8);
                 return challengeData.clone();
 
             } else {
@@ -138,7 +138,7 @@
                 if(logger.isLoggable(Level.FINE)) {
                     logger.log(Level.FINE,
                         "CRAMSRV02:Received response: {0}",
-                        new String(responseData, "UTF8"));
+                        new String(responseData, UTF_8));
                 }
 
                 // Extract username from response
@@ -154,7 +154,7 @@
                     throw new SaslException(
                         "CRAM-MD5: Invalid response; space missing");
                 }
-                String username = new String(responseData, 0, ulen, "UTF8");
+                String username = new String(responseData, 0, ulen, UTF_8);
 
                 logger.log(Level.FINE,
                     "CRAMSRV03:Extracted username: {0}", username);
@@ -177,7 +177,7 @@
                 for (int i = 0; i < pwChars.length; i++) {
                     pwChars[i] = 0;
                 }
-                pw = pwStr.getBytes("UTF8");
+                pw = pwStr.getBytes(UTF_8);
 
                 // Generate a keyed-MD5 digest from the user's password and
                 // original challenge.
@@ -190,7 +190,7 @@
                 clearPassword();
 
                 // Check whether digest is as expected
-                byte[] expectedDigest = digest.getBytes("UTF8");
+                byte[] expectedDigest = digest.getBytes(UTF_8);
                 int digestLen = responseData.length - ulen - 1;
                 if (expectedDigest.length != digestLen) {
                     aborted = true;
@@ -222,9 +222,6 @@
                 completed = true;
                 return null;
             }
-        } catch (UnsupportedEncodingException e) {
-            aborted = true;
-            throw new SaslException("UTF8 not available on platform", e);
         } catch (NoSuchAlgorithmException e) {
             aborted = true;
             throw new SaslException("MD5 algorithm not available on platform", e);
--- a/src/java.security.sasl/share/classes/com/sun/security/sasl/ExternalClient.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.security.sasl/share/classes/com/sun/security/sasl/ExternalClient.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,8 @@
 
 import javax.security.sasl.*;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 /**
   * Implements the EXTERNAL SASL client mechanism.
   * (<A HREF="http://www.ietf.org/rfc/rfc2222.txt">RFC 2222</A>).
@@ -43,17 +45,10 @@
      * Constructs an External mechanism with optional authorization ID.
      *
      * @param authorizationID If non-null, used to specify authorization ID.
-     * @throws SaslException if cannot convert authorizationID into UTF-8
-     *     representation.
      */
-    ExternalClient(String authorizationID) throws SaslException {
+    ExternalClient(String authorizationID) {
         if (authorizationID != null) {
-            try {
-                username = authorizationID.getBytes("UTF8");
-            } catch (java.io.UnsupportedEncodingException e) {
-                throw new SaslException("Cannot convert " + authorizationID +
-                    " into UTF-8", e);
-            }
+            username = authorizationID.getBytes(UTF_8);
         } else {
             username = new byte[0];
         }
@@ -88,10 +83,9 @@
      *
      * @param challengeData Ignored.
      * @return The possible empty initial response.
-     * @throws SaslException If authentication has already been called.
+     * @throws IllegalStateException If authentication has already been called.
      */
-    public byte[] evaluateChallenge(byte[] challengeData)
-        throws SaslException {
+    public byte[] evaluateChallenge(byte[] challengeData) {
         if (completed) {
             throw new IllegalStateException(
                 "EXTERNAL authentication already completed");
--- a/src/java.security.sasl/share/classes/com/sun/security/sasl/PlainClient.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.security.sasl/share/classes/com/sun/security/sasl/PlainClient.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,8 @@
 
 import javax.security.sasl.*;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 /**
   * Implements the PLAIN SASL client mechanism.
   * (<A
@@ -89,43 +91,37 @@
      *
      * @param challengeData Ignored
      * @return A non-null byte array containing the response to be sent to the server.
-     * @throws SaslException If cannot encode ids in UTF-8
-     * @throw IllegalStateException if authentication already completed
+     * @throws IllegalStateException if authentication already completed
      */
-    public byte[] evaluateChallenge(byte[] challengeData) throws SaslException {
+    public byte[] evaluateChallenge(byte[] challengeData) {
         if (completed) {
             throw new IllegalStateException(
                 "PLAIN authentication already completed");
         }
         completed = true;
+        byte[] authz = (authorizationID != null)
+            ? authorizationID.getBytes(UTF_8)
+            : null;
+        byte[] auth = authenticationID.getBytes(UTF_8);
 
-        try {
-            byte[] authz = (authorizationID != null)?
-                authorizationID.getBytes("UTF8") :
-                null;
-            byte[] auth = authenticationID.getBytes("UTF8");
-
-            byte[] answer = new byte[pw.length + auth.length + 2 +
+        byte[] answer = new byte[pw.length + auth.length + 2 +
                 (authz == null ? 0 : authz.length)];
 
-            int pos = 0;
-            if (authz != null) {
-                System.arraycopy(authz, 0, answer, 0, authz.length);
-                pos = authz.length;
-            }
-            answer[pos++] = SEP;
-            System.arraycopy(auth, 0, answer, pos, auth.length);
+        int pos = 0;
+        if (authz != null) {
+            System.arraycopy(authz, 0, answer, 0, authz.length);
+            pos = authz.length;
+        }
+        answer[pos++] = SEP;
+        System.arraycopy(auth, 0, answer, pos, auth.length);
 
-            pos += auth.length;
-            answer[pos++] = SEP;
-
-            System.arraycopy(pw, 0, answer, pos, pw.length);
+        pos += auth.length;
+        answer[pos++] = SEP;
 
-            clearPassword();
-            return answer;
-        } catch (java.io.UnsupportedEncodingException e) {
-            throw new SaslException("Cannot get UTF-8 encoding of ids", e);
-        }
+        System.arraycopy(pw, 0, answer, pos, pw.length);
+
+        clearPassword();
+        return answer;
     }
 
     /**
--- a/src/java.security.sasl/share/classes/com/sun/security/sasl/digest/DigestMD5Base.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.security.sasl/share/classes/com/sun/security/sasl/digest/DigestMD5Base.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,17 +25,15 @@
 
 package com.sun.security.sasl.digest;
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.math.BigInteger;
+import java.nio.charset.Charset;
 import java.util.Map;
 import java.util.Arrays;
 import java.util.List;
 import java.util.logging.Level;
-import java.math.BigInteger;
 import java.util.Random;
-
-import java.io.ByteArrayOutputStream;
-import java.io.UnsupportedEncodingException;
-import java.io.IOException;
-
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.security.InvalidKeyException;
@@ -43,6 +41,8 @@
 import java.security.spec.InvalidKeySpecException;
 import java.security.InvalidAlgorithmParameterException;
 
+import static java.nio.charset.StandardCharsets.*;
+
 import javax.crypto.Cipher;
 import javax.crypto.SecretKey;
 import javax.crypto.Mac;
@@ -54,11 +54,11 @@
 import javax.crypto.spec.DESKeySpec;
 import javax.crypto.spec.DESedeKeySpec;
 
+import javax.security.auth.callback.CallbackHandler;
 import javax.security.sasl.*;
+
 import com.sun.security.sasl.util.AbstractSaslImpl;
 
-import javax.security.auth.callback.CallbackHandler;
-
 /**
  * Utility class for DIGEST-MD5 mechanism. Provides utility methods
  * and contains two inner classes which implement the SecurityCtx
@@ -151,7 +151,7 @@
     protected String negotiatedQop;
     protected String negotiatedRealm;
     protected boolean useUTF8 = false;
-    protected String encoding = "8859_1";  // default unless server specifies utf-8
+    protected Charset encoding = ISO_8859_1;  // default unless server specifies utf-8
 
     protected String digestUri;
     protected String authzid;       // authzid or canonicalized authzid
@@ -384,8 +384,7 @@
      * @param a non-null byte array
      * @return a non-null String contain the HEX value
      */
-    protected byte[] binaryToHex(byte[] digest) throws
-    UnsupportedEncodingException {
+    protected byte[] binaryToHex(byte[] digest) {
 
         StringBuilder digestString = new StringBuilder();
 
@@ -405,26 +404,21 @@
      * if all chars in string are within the 8859_1 (Latin 1) encoding range.
      *
      * @param a non-null String
-     * @return a non-nuill byte array containing the correct character encoding
+     * @return a non-null byte array containing the correct character encoding
      * for username, paswd or realm.
      */
-    protected byte[] stringToByte_8859_1(String str) throws SaslException {
+    protected byte[] stringToByte_8859_1(String str) {
 
         char[] buffer = str.toCharArray();
 
-        try {
-            if (useUTF8) {
-                for( int i = 0; i< buffer.length; i++ ) {
-                    if( buffer[i] > '\u00FF' ) {
-                        return str.getBytes("UTF8");
-                    }
+        if (useUTF8) {
+            for (int i = 0; i < buffer.length; i++) {
+                if (buffer[i] > '\u00FF') {
+                    return str.getBytes(UTF_8);
                 }
             }
-            return str.getBytes("8859_1");
-        } catch (UnsupportedEncodingException e) {
-            throw new SaslException(
-                "cannot encode string in UTF8 or 8859-1 (Latin-1)", e);
         }
+        return str.getBytes(ISO_8859_1);
     }
 
     protected static byte[] getPlatformCiphers() {
@@ -461,8 +455,6 @@
      * @return A non-null byte array containing the repsonse-value.
      * @throws NoSuchAlgorithmException if the platform does not have MD5
      * digest support.
-     * @throws UnsupportedEncodingException if a an error occurs
-     * encoding a string into either Latin-1 or UTF-8.
      * @throws IOException if an error occurs writing to the output
      * byte array buffer.
      */
@@ -478,7 +470,6 @@
         int nonceCount,
         byte[] authzidValue
         ) throws NoSuchAlgorithmException,
-            UnsupportedEncodingException,
             IOException {
 
         MessageDigest md5 = MessageDigest.getInstance("MD5");
@@ -845,14 +836,9 @@
             try {
                 generateIntegrityKeyPair(clientMode);
 
-            } catch (UnsupportedEncodingException e) {
-                throw new SaslException(
-                    "DIGEST-MD5: Error encoding strings into UTF-8", e);
-
             } catch (IOException e) {
                 throw new SaslException("DIGEST-MD5: Error accessing buffers " +
                     "required to create integrity key pairs", e);
-
             } catch (NoSuchAlgorithmException e) {
                 throw new SaslException("DIGEST-MD5: Unsupported digest " +
                     "algorithm used to create integrity key pairs", e);
@@ -866,16 +852,13 @@
          * Generate client-server, server-client key pairs for DIGEST-MD5
          * integrity checking.
          *
-         * @throws UnsupportedEncodingException if the UTF-8 encoding is not
-         * supported on the platform.
          * @throws IOException if an error occurs when writing to or from the
          * byte array output buffers.
          * @throws NoSuchAlgorithmException if the MD5 message digest algorithm
          * cannot loaded.
          */
         private void generateIntegrityKeyPair(boolean clientMode)
-            throws UnsupportedEncodingException, IOException,
-                NoSuchAlgorithmException {
+            throws IOException, NoSuchAlgorithmException {
 
             byte[] cimagic = CLIENT_INT_MAGIC.getBytes(encoding);
             byte[] simagic = SVR_INT_MAGIC.getBytes(encoding);
@@ -1130,11 +1113,6 @@
 
             } catch (SaslException e) {
                 throw e;
-
-            } catch (UnsupportedEncodingException e) {
-                throw new SaslException(
-                    "DIGEST-MD5: Error encoding string value into UTF-8", e);
-
             } catch (IOException e) {
                 throw new SaslException("DIGEST-MD5: Error accessing " +
                     "buffers required to generate cipher keys", e);
@@ -1152,14 +1130,11 @@
          * byte array output buffers.
          * @throws NoSuchAlgorithmException if the MD5 message digest algorithm
          * cannot loaded.
-         * @throws UnsupportedEncodingException if an UTF-8 encoding is not
-         * supported on the platform.
-         * @throw SaslException if an error occurs initializing the keys and
+         * @throws SaslException if an error occurs initializing the keys and
          * IVs for the chosen cipher.
          */
         private void generatePrivacyKeyPair(boolean clientMode)
-            throws IOException, UnsupportedEncodingException,
-            NoSuchAlgorithmException, SaslException {
+            throws IOException, NoSuchAlgorithmException, SaslException {
 
             byte[] ccmagic = CLIENT_CONF_MAGIC.getBytes(encoding);
             byte[] scmagic = SVR_CONF_MAGIC.getBytes(encoding);
--- a/src/java.security.sasl/share/classes/com/sun/security/sasl/digest/DigestMD5Client.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.security.sasl/share/classes/com/sun/security/sasl/digest/DigestMD5Client.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -28,14 +28,14 @@
 import java.security.NoSuchAlgorithmException;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.UnsupportedEncodingException;
 import java.util.StringTokenizer;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Arrays;
+import java.util.logging.Level;
 
-import java.util.logging.Level;
+import static java.nio.charset.StandardCharsets.UTF_8;
 
 import javax.security.sasl.*;
 import javax.security.auth.callback.CallbackHandler;
@@ -155,13 +155,7 @@
         // authzID can only be encoded in UTF8 - RFC 2222
         if (authzid != null) {
             this.authzid = authzid;
-            try {
-                authzidBytes = authzid.getBytes("UTF8");
-
-            } catch (UnsupportedEncodingException e) {
-                throw new SaslException(
-                    "DIGEST-MD5: Error encoding authzid value into UTF-8", e);
-            }
+            authzidBytes = authzid.getBytes(UTF_8);
         }
 
         if (props != null) {
@@ -272,7 +266,7 @@
     * digest challenge format is detected.
     */
     private void processChallenge(byte[][] challengeVal, List<byte[]> realmChoices)
-        throws SaslException, UnsupportedEncodingException {
+        throws SaslException {
 
         /* CHARSET: optional atmost once */
         if (challengeVal[CHARSET] != null) {
@@ -281,7 +275,7 @@
                     "violation. Unrecognised charset value: " +
                     new String(challengeVal[CHARSET]));
             } else {
-                encoding = "UTF8";
+                encoding = UTF_8;
                 useUTF8 = true;
             }
         }
--- a/src/java.security.sasl/share/classes/com/sun/security/sasl/digest/DigestMD5Server.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/java.security.sasl/share/classes/com/sun/security/sasl/digest/DigestMD5Server.java	Wed Nov 13 09:16:04 2019 +0000
@@ -25,10 +25,9 @@
 
 package com.sun.security.sasl.digest;
 
-import java.security.NoSuchAlgorithmException;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.UnsupportedEncodingException;
+import java.security.NoSuchAlgorithmException;
 import java.util.StringTokenizer;
 import java.util.ArrayList;
 import java.util.List;
@@ -40,6 +39,8 @@
 import javax.security.sasl.*;
 import javax.security.auth.callback.*;
 
+import static java.nio.charset.StandardCharsets.*;
+
 /**
   * An implementation of the DIGEST-MD5 server SASL mechanism.
   * (<a href="http://www.ietf.org/rfc/rfc2831.txt">RFC 2831</a>)
@@ -171,7 +172,7 @@
             }
         }
 
-        encoding = (useUTF8 ? "UTF8" : "8859_1");
+        encoding = (useUTF8 ? UTF_8 : ISO_8859_1);
 
         // By default, use server name as realm
         if (serverRealms.isEmpty()) {
@@ -229,9 +230,6 @@
 
                 step = 3;
                 return challenge;
-            } catch (UnsupportedEncodingException e) {
-                throw new SaslException(
-                    "DIGEST-MD5: Error encoding challenge", e);
             } catch (IOException e) {
                 throw new SaslException(
                     "DIGEST-MD5: Error generating challenge", e);
@@ -247,11 +245,6 @@
                 byte[][] responseVal = parseDirectives(response, DIRECTIVE_KEY,
                     null, REALM);
                 challenge = validateClientResponse(responseVal);
-            } catch (SaslException e) {
-                throw e;
-            } catch (UnsupportedEncodingException e) {
-                throw new SaslException(
-                    "DIGEST-MD5: Error validating client response", e);
             } finally {
                 step = 0;  // Set to invalid state
             }
@@ -298,7 +291,7 @@
      *        auth-param        = token "=" ( token | quoted-string )
      */
     private byte[] generateChallenge(List<String> realms, String qopStr,
-        String cipherStr) throws UnsupportedEncodingException, IOException {
+        String cipherStr) throws IOException {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
 
         // Realms (>= 0)
@@ -389,7 +382,7 @@
      * @return response-value ('rspauth') for client to validate
      */
     private byte[] validateClientResponse(byte[][] responseVal)
-        throws SaslException, UnsupportedEncodingException {
+        throws SaslException {
 
         /* CHARSET: optional atmost once */
         if (responseVal[CHARSET] != null) {
--- a/src/jdk.compiler/share/classes/com/sun/source/tree/CaseTree.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/source/tree/CaseTree.java	Wed Nov 13 09:16:04 2019 +0000
@@ -51,29 +51,18 @@
      * {@code null} if this is the default case.
      * If this case has multiple labels, returns the first label.
      * @return the expression for the case, or null
+     * @deprecated Please use {@link #getExpressions()}.
      */
+    @Deprecated
     ExpressionTree getExpression();
 
     /**
-     * {@preview Associated with switch expressions, a preview feature of
-     *           the Java language.
-     *
-     *           This method is associated with <i>switch expressions</i>, a preview
-     *           feature of the Java language. Preview features
-     *           may be removed in a future release, or upgraded to permanent
-     *           features of the Java language.}
-     *
      * Returns the labels for this case.
      * For default case, returns an empty list.
      *
      * @return labels for this case
      * @since 12
-     *
-     * @preview This method is modeling a case with multiple labels,
-     * which is part of a preview feature and may be removed
-     * if the preview feature is removed.
      */
-    @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.SWITCH_EXPRESSIONS)
     List<? extends ExpressionTree> getExpressions();
 
     /**
@@ -86,14 +75,6 @@
     List<? extends StatementTree> getStatements();
 
     /**
-     * {@preview Associated with switch expressions, a preview feature of
-     *           the Java language.
-     *
-     *           This method is associated with <i>switch expressions</i>, a preview
-     *           feature of the Java language. Preview features
-     *           may be removed in a future release, or upgraded to permanent
-     *           features of the Java language.}
-     *
      * For case with kind {@linkplain CaseKind#RULE},
      * returns the statement or expression after the arrow.
      * Returns {@code null} for case with kind
@@ -102,40 +83,21 @@
      * @return case value or null
      * @since 12
      */
-    @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.SWITCH_EXPRESSIONS)
     public default Tree getBody() {
         return null;
     }
 
     /**
-     * {@preview Associated with switch expressions, a preview feature of
-     *           the Java language.
-     *
-     *           This method is associated with <i>switch expressions</i>, a preview
-     *           feature of the Java language. Preview features
-     *           may be removed in a future release, or upgraded to permanent
-     *           features of the Java language.}
-     *
      * Returns the kind of this case.
      *
      * @return the kind of this case
      * @since 12
      */
-    @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.SWITCH_EXPRESSIONS)
-    @SuppressWarnings("preview")
     public default CaseKind getCaseKind() {
         return CaseKind.STATEMENT;
     }
 
     /**
-     * {@preview Associated with switch expressions, a preview feature of
-     *           the Java language.
-     *
-     *           This enum is associated with <i>switch expressions</i>, a preview
-     *           feature of the Java language. Preview features
-     *           may be removed in a future release, or upgraded to permanent
-     *           features of the Java language.}
-     *
      * The syntatic form of this case:
      * <ul>
      *     <li>STATEMENT: {@code case <expression>: <statements>}</li>
@@ -144,8 +106,6 @@
      *
      * @since 12
      */
-    @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.SWITCH_EXPRESSIONS)
-    @SuppressWarnings("preview")
     public enum CaseKind {
         /**
          * Case is in the form: {@code case <expression>: <statements>}.
--- a/src/jdk.compiler/share/classes/com/sun/source/tree/SwitchExpressionTree.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/source/tree/SwitchExpressionTree.java	Wed Nov 13 09:16:04 2019 +0000
@@ -28,14 +28,6 @@
 import java.util.List;
 
 /**
- * {@preview Associated with switch expressions, a preview feature of
- *           the Java language.
- *
- *           This interface is associated with <i>switch expressions</i>, a preview
- *           feature of the Java language. Preview features
- *           may be removed in a future release, or upgraded to permanent
- *           features of the Java language.}
- *
  * A tree node for a {@code switch} expression.
  *
  * For example:
@@ -49,7 +41,6 @@
  *
  * @since 12
  */
-@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.SWITCH_EXPRESSIONS)
 public interface SwitchExpressionTree extends ExpressionTree {
     /**
      * Returns the expression for the {@code switch} expression.
--- a/src/jdk.compiler/share/classes/com/sun/source/tree/Tree.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/source/tree/Tree.java	Wed Nov 13 09:16:04 2019 +0000
@@ -240,20 +240,10 @@
         SWITCH(SwitchTree.class),
 
         /**
-         * {@preview Associated with switch expressions, a preview feature of
-         *           the Java language.
-         *
-         *           This enum constant is associated with <i>switch expressions</i>, a preview
-         *           feature of the Java language. Preview features
-         *           may be removed in a future release, or upgraded to permanent
-         *           features of the Java language.}
-         *
          * Used for instances of {@link SwitchExpressionTree}.
          *
          * @since 12
          */
-        @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.SWITCH_EXPRESSIONS)
-        @SuppressWarnings("preview")
         SWITCH_EXPRESSION(SwitchExpressionTree.class),
 
         /**
@@ -662,20 +652,10 @@
         OTHER(null),
 
         /**
-         * {@preview Associated with switch expressions, a preview feature of
-         *           the Java language.
-         *
-         *           This enum constant is associated with <i>switch expressions</i>, a preview
-         *           feature of the Java language. Preview features
-         *           may be removed in a future release, or upgraded to permanent
-         *           features of the Java language.}
-         *
          * Used for instances of {@link YieldTree}.
          *
          * @since 13
          */
-        @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.SWITCH_EXPRESSIONS)
-        @SuppressWarnings("preview")
         YIELD(YieldTree.class);
 
 
--- a/src/jdk.compiler/share/classes/com/sun/source/tree/TreeVisitor.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/source/tree/TreeVisitor.java	Wed Nov 13 09:16:04 2019 +0000
@@ -354,14 +354,6 @@
     R visitSwitch(SwitchTree node, P p);
 
     /**
-     * {@preview Associated with switch expressions, a preview feature of
-     *           the Java language.
-     *
-     *           This method is associated with <i>switch expressions</i>, a preview
-     *           feature of the Java language. Preview features
-     *           may be removed in a future release, or upgraded to permanent
-     *           features of the Java language.}
-     *
      * Visits a SwitchExpressionTree node.
      *
      * @param node the node being visited
@@ -369,8 +361,6 @@
      * @return a result value
      * @since 12
      */
-    @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.SWITCH_EXPRESSIONS)
-    @SuppressWarnings("preview")
     R visitSwitchExpression(SwitchExpressionTree node, P p);
 
     /**
@@ -560,21 +550,11 @@
     R visitOther(Tree node, P p);
 
     /**
-     * {@preview Associated with switch expressions, a preview feature of
-     *           the Java language.
-     *
-     *           This method is associated with <i>switch expressions</i>, a preview
-     *           feature of the Java language. Preview features
-     *           may be removed in a future release, or upgraded to permanent
-     *           features of the Java language.}
-     *
      * Visits a YieldTree node.
      * @param node the node being visited
      * @param p a parameter value
      * @return a result value
      * @since 13
      */
-    @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.SWITCH_EXPRESSIONS)
-    @SuppressWarnings("preview")
     R visitYield(YieldTree node, P p);
 }
--- a/src/jdk.compiler/share/classes/com/sun/source/tree/YieldTree.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/source/tree/YieldTree.java	Wed Nov 13 09:16:04 2019 +0000
@@ -26,14 +26,6 @@
 package com.sun.source.tree;
 
 /**
- * {@preview Associated with switch expressions, a preview feature of
- *           the Java language.
- *
- *           This method is associated with <i>switch expressions</i>, a preview
- *           feature of the Java language. Preview features
- *           may be removed in a future release, or upgraded to permanent
- *           features of the Java language.}
- *
  * A tree node for a {@code yield} statement.
  *
  * For example:
@@ -45,7 +37,6 @@
  *
  * @since 13
  */
-@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.SWITCH_EXPRESSIONS)
 public interface YieldTree extends StatementTree {
 
     /**
--- a/src/jdk.compiler/share/classes/com/sun/source/util/SimpleTreeVisitor.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/source/util/SimpleTreeVisitor.java	Wed Nov 13 09:16:04 2019 +0000
@@ -264,14 +264,6 @@
     }
 
     /**
-     * {@preview Associated with switch expressions, a preview feature of
-     *           the Java language.
-     *
-     *           This method is associated with <i>switch expressions</i>, a preview
-     *           feature of the Java language. Preview features
-     *           may be removed in a future release, or upgraded to permanent
-     *           features of the Java language.}
-     *
      * {@inheritDoc} This implementation calls {@code defaultAction}.
      *
      * @param node {@inheritDoc}
@@ -279,8 +271,6 @@
      * @return  the result of {@code defaultAction}
      */
     @Override
-    @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.SWITCH_EXPRESSIONS)
-    @SuppressWarnings("preview")
     public R visitSwitchExpression(SwitchExpressionTree node, P p) {
         return defaultAction(node, p);
     }
@@ -794,8 +784,6 @@
      * @return  the result of {@code defaultAction}
      */
     @Override
-    @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.SWITCH_EXPRESSIONS)
-    @SuppressWarnings("preview")
     public R visitYield(YieldTree node, P p) {
         return defaultAction(node, p);
     }
--- a/src/jdk.compiler/share/classes/com/sun/source/util/TreeScanner.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/source/util/TreeScanner.java	Wed Nov 13 09:16:04 2019 +0000
@@ -334,14 +334,6 @@
     }
 
     /**
-     * {@preview Associated with switch expressions, a preview feature of
-     *           the Java language.
-     *
-     *           This method is associated with <i>switch expressions</i>, a preview
-     *           feature of the Java language. Preview features
-     *           may be removed in a future release, or upgraded to permanent
-     *           features of the Java language.}
-     *
      * {@inheritDoc} This implementation scans the children in left to right order.
      *
      * @param node  {@inheritDoc}
@@ -349,8 +341,6 @@
      * @return the result of scanning
      */
     @Override
-    @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.SWITCH_EXPRESSIONS)
-    @SuppressWarnings("preview")
     public R visitSwitchExpression(SwitchExpressionTree node, P p) {
         R r = scan(node.getExpression(), p);
         r = scanAndReduce(node.getCases(), p, r);
@@ -365,7 +355,6 @@
      * @return the result of scanning
      */
     @Override
-    @SuppressWarnings("preview")
     public R visitCase(CaseTree node, P p) {
         R r = scan(node.getExpressions(), p);
         if (node.getCaseKind() == CaseTree.CaseKind.RULE)
@@ -938,14 +927,6 @@
     }
 
     /**
-     * {@preview Associated with switch expressions, a preview feature of
-     *           the Java language.
-     *
-     *           This method is associated with <i>switch expressions</i>, a preview
-     *           feature of the Java language. Preview features
-     *           may be removed in a future release, or upgraded to permanent
-     *           features of the Java language.}
-     *
      * {@inheritDoc} This implementation returns {@code null}.
      *
      * @param node  {@inheritDoc}
@@ -953,8 +934,6 @@
      * @return the result of scanning
      */
     @Override
-    @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.SWITCH_EXPRESSIONS)
-    @SuppressWarnings("preview")
     public R visitYield(YieldTree node, P p) {
         return scan(node.getValue(), p);
     }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java	Wed Nov 13 09:16:04 2019 +0000
@@ -165,10 +165,7 @@
      * @return true, if given feature is a preview feature.
      */
     public boolean isPreview(Feature feature) {
-        if (feature == Feature.SWITCH_EXPRESSION ||
-            feature == Feature.SWITCH_MULTIPLE_CASE_LABELS ||
-            feature == Feature.SWITCH_RULE ||
-            feature == Feature.TEXT_BLOCKS)
+        if (feature == Feature.TEXT_BLOCKS)
             return true;
         //Note: this is a backdoor which allows to optionally treat all features as 'preview' (for testing).
         //When real preview features will be added, this method can be implemented to return 'true'
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1467,7 +1467,6 @@
             // check that there are no duplicate case labels or default clauses.
             Set<Object> labels = new HashSet<>(); // The set of case labels.
             boolean hasDefault = false;      // Is there a default label?
-            @SuppressWarnings("preview")
             CaseTree.CaseKind caseKind = null;
             boolean wasError = false;
             for (List<JCCase> l = cases; l.nonEmpty(); l = l.tail) {
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1432,7 +1432,6 @@
         }
         List<JCStatement> stats = null;
         JCTree body = null;
-        @SuppressWarnings("preview")
         CaseTree.CaseKind kind;
         switch (token.kind) {
             case ARROW:
@@ -2897,7 +2896,6 @@
                 nextToken();
                 checkSourceLevel(Feature.SWITCH_MULTIPLE_CASE_LABELS);
             };
-            @SuppressWarnings("preview")
             CaseTree.CaseKind caseKind;
             JCTree body = null;
             if (token.kind == ARROW) {
@@ -2922,7 +2920,6 @@
         }
         case DEFAULT: {
             nextToken();
-            @SuppressWarnings("preview")
             CaseTree.CaseKind caseKind;
             JCTree body = null;
             if (token.kind == ARROW) {
@@ -3300,7 +3297,7 @@
             if (allowYieldStatement) {
                 return true;
             } else if (shouldWarn) {
-                log.warning(pos, Warnings.RestrictedTypeNotAllowedPreview(name, Source.JDK13));
+                log.warning(pos, Warnings.RestrictedTypeNotAllowed(name, Source.JDK14));
             }
         }
         return false;
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1249,17 +1249,14 @@
     public static class JCCase extends JCStatement implements CaseTree {
         //as CaseKind is deprecated for removal (as it is part of a preview feature),
         //using indirection through these fields to avoid unnecessary @SuppressWarnings:
-        @SuppressWarnings("preview")
         public static final CaseKind STATEMENT = CaseKind.STATEMENT;
-        @SuppressWarnings("preview")
         public static final CaseKind RULE = CaseKind.RULE;
-        @SuppressWarnings("preview")
         public final CaseKind caseKind;
         public List<JCExpression> pats;
         public List<JCStatement> stats;
         public JCTree body;
         public boolean completesNormally;
-        protected JCCase(@SuppressWarnings("preview") CaseKind caseKind, List<JCExpression> pats,
+        protected JCCase(CaseKind caseKind, List<JCExpression> pats,
                          List<JCStatement> stats, JCTree body) {
             Assert.checkNonNull(pats);
             Assert.check(pats.isEmpty() || pats.head != null);
@@ -1273,21 +1270,17 @@
 
         @Override @DefinedBy(Api.COMPILER_TREE)
         public Kind getKind() { return Kind.CASE; }
-        @Override @DefinedBy(Api.COMPILER_TREE)
+        @Override @Deprecated @DefinedBy(Api.COMPILER_TREE)
         public JCExpression getExpression() { return pats.head; }
         @Override @DefinedBy(Api.COMPILER_TREE)
-        @SuppressWarnings("preview")
         public List<JCExpression> getExpressions() { return pats; }
         @Override @DefinedBy(Api.COMPILER_TREE)
-        @SuppressWarnings("preview")
         public List<JCStatement> getStatements() {
             return caseKind == CaseKind.STATEMENT ? stats : null;
         }
         @Override @DefinedBy(Api.COMPILER_TREE)
-        @SuppressWarnings("preview")
         public JCTree getBody() { return body; }
         @Override @DefinedBy(Api.COMPILER_TREE)
-        @SuppressWarnings("preview")
         public CaseKind getCaseKind() {
             return caseKind;
         }
@@ -1304,7 +1297,6 @@
     /**
      * A "switch ( ) { }" construction.
      */
-    @SuppressWarnings("preview")
     public static class JCSwitchExpression extends JCPolyExpression implements SwitchExpressionTree {
         public JCExpression selector;
         public List<JCCase> cases;
@@ -1585,7 +1577,6 @@
     /**
      * A break-with from a switch expression.
      */
-    @SuppressWarnings("preview")
     public static class JCYield extends JCStatement implements YieldTree {
         public JCExpression value;
         public JCTree target;
@@ -3104,7 +3095,7 @@
         JCLabeledStatement Labelled(Name label, JCStatement body);
         JCSwitch Switch(JCExpression selector, List<JCCase> cases);
         JCSwitchExpression SwitchExpression(JCExpression selector, List<JCCase> cases);
-        JCCase Case(@SuppressWarnings("preview") CaseTree.CaseKind caseKind, List<JCExpression> pat,
+        JCCase Case(CaseTree.CaseKind caseKind, List<JCExpression> pat,
                     List<JCStatement> stats, JCTree body);
         JCSynchronized Synchronized(JCExpression lock, JCBlock body);
         JCTry Try(JCBlock body, List<JCCatch> catchers, JCBlock finalizer);
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeCopier.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeCopier.java	Wed Nov 13 09:16:04 2019 +0000
@@ -144,7 +144,6 @@
     }
 
     @DefinedBy(Api.COMPILER_TREE)
-    @SuppressWarnings("preview")
     public JCTree visitYield(YieldTree node, P p) {
         JCYield t = (JCYield) node;
         JCExpression value = copy(t.value, p);
@@ -380,7 +379,6 @@
     }
 
     @DefinedBy(Api.COMPILER_TREE)
-    @SuppressWarnings("preview")
     public JCTree visitSwitchExpression(SwitchExpressionTree node, P p) {
         JCSwitchExpression t = (JCSwitchExpression) node;
         JCExpression selector = copy(t.selector, p);
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Wed Nov 13 09:16:04 2019 +0000
@@ -274,7 +274,7 @@
         return tree;
     }
 
-    public JCCase Case(@SuppressWarnings("preview") CaseTree.CaseKind caseKind, List<JCExpression> pats,
+    public JCCase Case(CaseTree.CaseKind caseKind, List<JCExpression> pats,
                        List<JCStatement> stats, JCTree body) {
         JCCase tree = new JCCase(caseKind, pats, stats, body);
         tree.pos = pos;
--- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyStore.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyStore.java	Wed Nov 13 09:16:04 2019 +0000
@@ -31,7 +31,8 @@
 import java.io.OutputStream;
 import java.io.IOException;
 import java.io.ByteArrayInputStream;
-import java.io.UnsupportedEncodingException;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
 
 import java.util.Arrays;
 import java.util.Collections;
@@ -2154,11 +2155,7 @@
         if (!printable) {
             return "0x" + Functions.toHexString(bytes);
         } else {
-            try {
-                return new String(bytes, "UTF-8");
-            } catch (UnsupportedEncodingException uee) {
-                return "0x" + Functions.toHexString(bytes);
-            }
+            return new String(bytes, UTF_8);
         }
     }
 
--- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11TlsPrfGenerator.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11TlsPrfGenerator.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -31,6 +31,8 @@
 import javax.crypto.*;
 import javax.crypto.spec.*;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 import sun.security.internal.spec.TlsPrfParameterSpec;
 
 import static sun.security.pkcs11.TemplateManager.*;
@@ -167,7 +169,7 @@
             }
         }
 
-        byte[] label = P11Util.getBytesUTF8(spec.getLabel());
+        byte[] label = spec.getLabel().getBytes(UTF_8);
 
         if (mechanism == CKM_NSS_TLS_PRF_GENERAL) {
             Session session = null;
--- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Util.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Util.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -143,14 +143,6 @@
         return b;
     }
 
-    static byte[] getBytesUTF8(String s) {
-        try {
-            return s.getBytes("UTF8");
-        } catch (java.io.UnsupportedEncodingException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
     static byte[] sha1(byte[] data) {
         try {
             MessageDigest md = MessageDigest.getInstance("SHA-1");
--- a/src/jdk.crypto.ucrypto/solaris/classes/com/oracle/security/ucrypto/Config.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/jdk.crypto.ucrypto/solaris/classes/com/oracle/security/ucrypto/Config.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,15 +26,17 @@
 package com.oracle.security.ucrypto;
 
 import java.io.*;
-import static java.io.StreamTokenizer.*;
 import java.math.BigInteger;
 import java.util.*;
+import java.security.*;
 
-import java.security.*;
+import static java.io.StreamTokenizer.*;
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
 
 import sun.security.action.GetPropertyAction;
 import sun.security.util.PropertyExpander;
 
+
 /**
  * Configuration container and file parsing.
  *
@@ -66,8 +68,8 @@
 
     Config(String filename) throws IOException {
         FileInputStream in = new FileInputStream(expand(filename));
-        reader = new BufferedReader(new InputStreamReader(in, "ISO-8859-1"));
-        parsedKeywords = new HashSet<String>();
+        reader = new BufferedReader(new InputStreamReader(in, ISO_8859_1));
+        parsedKeywords = new HashSet<>();
         st = new StreamTokenizer(reader);
         setupTokenizer();
         parse();
--- a/src/jdk.security.jgss/share/classes/com/sun/security/sasl/gsskerb/GssKrb5Client.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/jdk.security.jgss/share/classes/com/sun/security/sasl/gsskerb/GssKrb5Client.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -30,6 +30,8 @@
 import java.util.logging.Level;
 import javax.security.sasl.*;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 // JAAS
 import javax.security.auth.callback.CallbackHandler;
 
@@ -150,11 +152,7 @@
         }
 
         if (authzID != null && authzID.length() > 0) {
-            try {
-                this.authzID = authzID.getBytes("UTF8");
-            } catch (IOException e) {
-                throw new SaslException("Cannot encode authorization ID", e);
-            }
+            this.authzID = authzID.getBytes(UTF_8);
         }
     }
 
--- a/src/jdk.security.jgss/share/classes/com/sun/security/sasl/gsskerb/GssKrb5Server.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/src/jdk.security.jgss/share/classes/com/sun/security/sasl/gsskerb/GssKrb5Server.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -30,6 +30,8 @@
 import java.util.Map;
 import java.util.logging.Level;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 // JAAS
 import javax.security.auth.callback.*;
 
@@ -300,12 +302,8 @@
 
             // Get authorization identity, if any
             if (gssOutToken.length > 4) {
-                try {
-                    authzid = new String(gssOutToken, 4,
-                        gssOutToken.length - 4, "UTF-8");
-                } catch (UnsupportedEncodingException uee) {
-                    throw new SaslException ("Cannot decode authzid", uee);
-                }
+                authzid = new String(gssOutToken, 4,
+                        gssOutToken.length - 4, UTF_8);
             } else {
                 authzid = peer;
             }
--- a/test/hotspot/gtest/gc/z/test_zForwarding.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/hotspot/gtest/gc/z/test_zForwarding.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -159,7 +159,7 @@
 
     const uint32_t live_objects = size;
     const size_t live_bytes = live_objects * object_size;
-    page.inc_live_atomic(live_objects, live_bytes);
+    page.inc_live(live_objects, live_bytes);
 
     // Setup forwarding
     ZForwarding* const forwarding = ZForwarding::create(&page);
--- a/test/hotspot/gtest/gc/z/test_zLiveMap.cpp	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/hotspot/gtest/gc/z/test_zLiveMap.cpp	Wed Nov 13 09:16:04 2019 +0000
@@ -35,7 +35,7 @@
     uintptr_t object = 0u;
 
     // Mark the object strong.
-    livemap.set_atomic(object, false /* finalizable */, inc_live);
+    livemap.set(object, false /* finalizable */, inc_live);
 
     // Check that both bits are in the same segment.
     ASSERT_EQ(livemap.index_to_segment(0), livemap.index_to_segment(1));
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/compiler/compilercontrol/CompilationModeHighOnlyTest.java	Wed Nov 13 09:16:04 2019 +0000
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2019, Loongson Technology Co. Ltd. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8233885
+ * @summary CompLevel_initial_compile should be CompLevel_full_optimization for high-only mode
+ * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -Xcomp -XX:CompilationMode=high-only
+ *                   compiler.compilercontrol.CompilationModeHighOnlyTest
+ *
+ */
+
+package compiler.compilercontrol;
+
+public class CompilationModeHighOnlyTest{
+    public static void main(String[] args) {
+        System.out.println("Passed");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/compiler/loopopts/TestRemoveMainPostLoops.java	Wed Nov 13 09:16:04 2019 +0000
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8233529
+ * @summary Verify that correct loops are selected when trying to remove main/post.
+ * @run main/othervm -XX:-TieredCompilation -Xbatch
+ *                   -XX:CompileCommand=compileonly,compiler.loopopts.TestRemoveMainPostLoops::test
+ *                   compiler.loopopts.TestRemoveMainPostLoops
+ */
+
+package compiler.loopopts;
+
+public class TestRemoveMainPostLoops {
+    static int cnt1 = 0;
+    int cnt2 = 0;
+
+    void testCallee() {
+        // (5) Only main and post loops are created (no pre loop -> "PeelMainPost") and main is unrolled.
+        for (int i = 0; i < 100; ++i) {
+            // (4) Inner loop is fully unrolled and removed.
+            for (int j = 0; j < 10; ++j) {
+                cnt1 += j;
+            }
+        }
+    }
+
+    void test() {
+        for (int i = 0; i < 10_000; ++i) {
+            // (0) testCallee method is inlined
+            testCallee();
+            cnt2 = 0;
+            // (1) OSR compilation is triggered in this loop.
+            // (2) Pre-/main-/post loops are created.
+            // (3) Main and post loops found empty and removed.
+            // (6) Pre loop is found empty, attempt to remove main and post loop then incorrectly selects main from (5).
+            for (int j = 0; j < 10; ++j) {
+                cnt2 = cnt1 + j;
+            }
+        }
+    }
+
+    public static void main(String[] strArr) {
+        TestRemoveMainPostLoops test = new TestRemoveMainPostLoops();
+        for (int i = 0; i < 100; i++) {
+            cnt1 = 0;
+            test.cnt2 = 0;
+            test.test();
+            if (cnt1 != 45000000 || test.cnt2 != 45000009) {
+                throw new RuntimeException("Incorrect result: " + cnt1 + " " + test.cnt2);
+            }
+        }
+    }
+}
--- a/test/hotspot/jtreg/runtime/CheckUnhandledOops/TestVerifyOops.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/hotspot/jtreg/runtime/CheckUnhandledOops/TestVerifyOops.java	Wed Nov 13 09:16:04 2019 +0000
@@ -21,10 +21,19 @@
  * questions.
  */
 
+// The test fails on sparc because there are errors in VerifyOops.
 /*
  * @test
  * @bug 8231058
- * @requires vm.debug & (os.arch != "sparc") & (os.arch != "sparcv9")
+ * @requires vm.debug & vm.bits == "64"
+ * @requires (os.arch != "sparcv9")
+ * @run main/othervm -XX:+VerifyOops -XX:+UseCompressedOops TestVerifyOops
+ * @run main/othervm -XX:+VerifyOops -XX:-UseCompressedOops TestVerifyOops
+ */
+/*
+ * @test
+ * @bug 8231058
+ * @requires vm.debug & vm.bits == "32"
  * @run main/othervm -XX:+VerifyOops TestVerifyOops
  */
 
--- a/test/hotspot/jtreg/runtime/execstack/TestMT.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/hotspot/jtreg/runtime/execstack/TestMT.java	Wed Nov 13 09:16:04 2019 +0000
@@ -78,7 +78,7 @@
         public void run() {
             for (int i = 0; i < 10; ++i) {
                 TestMT.run(getName());
-                yield();
+                Thread.yield();
             }
         }
     }
--- a/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest02/gctest02.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest02/gctest02.java	Wed Nov 13 09:16:04 2019 +0000
@@ -180,7 +180,7 @@
                 while ( ThreadCount.get() > 0 ) {
                         int buf[] = new int[32];
                         {
-                                                yield();
+                                                Thread.yield();
                         }
                 }
         }
--- a/test/hotspot/jtreg/vmTestbase/jit/regression/b4446672/b4446672.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/hotspot/jtreg/vmTestbase/jit/regression/b4446672/b4446672.java	Wed Nov 13 09:16:04 2019 +0000
@@ -76,7 +76,7 @@
         System.out.println ("GCThread synchronized.");
               while (!done) {
                 gcing=true;
-                yield();
+                Thread.yield();
                 System.gc();
               }
             }
--- a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/stress/thread/strace001.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/stress/thread/strace001.java	Wed Nov 13 09:16:04 2019 +0000
@@ -362,7 +362,7 @@
 
         currentDepth++;
         if (maxDepth > currentDepth) {
-            yield();
+            Thread.yield();
             if (mixed) {
                 int result = recursionNative(maxDepth, currentDepth, true);
 
--- a/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/JDIEventsDebuggee.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/JDIEventsDebuggee.java	Wed Nov 13 09:16:04 2019 +0000
@@ -232,7 +232,7 @@
 
         public void run() {
             while (!startExecution)
-                yield();
+                Thread.yield();
 
             for (int i = 0; (i < actionsNumber) && !stopExecution; i++)
                 executor.doEventAction();
--- a/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/MonitorEventsDebuggee.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/MonitorEventsDebuggee.java	Wed Nov 13 09:16:04 2019 +0000
@@ -53,7 +53,7 @@
         public void run() {
             // wait when interrupted thread switches state to 'TIMED_WAITING'
             while ((threadToInterrupt.getState() != Thread.State.WAITING) && !exitedFromWait) {
-                yield();
+                Thread.yield();
             }
 
             // threadToInterrupt 'spuriously' exited from wait()
@@ -236,7 +236,7 @@
         public void run() {
             // wait when blocked thread switches state to 'BLOCKED'
             while (blockedThread.getState() != Thread.State.BLOCKED)
-                yield();
+                Thread.yield();
 
             lockingThread.releaseLock();
         }
--- a/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/StateTestThread.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/StateTestThread.java	Wed Nov 13 09:16:04 2019 +0000
@@ -111,7 +111,7 @@
             start();
 
             while (!isRunning)
-                yield();
+                Thread.yield();
 
             break;
         case 2:
@@ -119,7 +119,7 @@
             isRunning = false;
 
             while (this.getState() != Thread.State.TIMED_WAITING)
-                yield();
+                Thread.yield();
 
             break;
         case 3:
@@ -129,7 +129,7 @@
             interrupt();
 
             while (getState() != Thread.State.WAITING)
-                yield();
+                Thread.yield();
 
             break;
         case 4:
@@ -141,7 +141,7 @@
             }
 
             while (!readyToBeBlocked || (getState() != Thread.State.BLOCKED))
-                yield();
+                Thread.yield();
 
             break;
         case 5:
--- a/test/hotspot/jtreg/vmTestbase/nsk/share/locks/LockingThread.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/locks/LockingThread.java	Wed Nov 13 09:16:04 2019 +0000
@@ -325,7 +325,7 @@
                 throw new TestBug("Locking thread can't reach required state (state: " + requiredState + " wasn't reached) in 1 minute");
             }
 
-            yield();
+            Thread.yield();
         }
 
         requiredState = null;
--- a/test/hotspot/jtreg/vmTestbase/nsk/share/locks/MonitorLockingThread.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/locks/MonitorLockingThread.java	Wed Nov 13 09:16:04 2019 +0000
@@ -78,7 +78,7 @@
              * should already occur) and then force MonitorLockingThread to release lock
              */
             while (blockedThread.getState() != Thread.State.BLOCKED)
-                yield();
+                Thread.yield();
 
             lockingThread.releaseLock();
         }
@@ -98,7 +98,7 @@
         synchronized (lockToHold) {
             holdsLock = true;
             while (isRunning)
-                yield();
+                Thread.yield();
         }
         holdsLock = false;
     }
@@ -106,12 +106,12 @@
     public void releaseLock() {
         isRunning = false;
         while (holdsLock)
-            yield();
+            Thread.yield();
     }
 
     public void acquireLock() {
         start();
         while (!holdsLock)
-            yield();
+            Thread.yield();
     }
 }
--- a/test/hotspot/jtreg/vmTestbase/nsk/share/runner/ThreadsRunner.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/runner/ThreadsRunner.java	Wed Nov 13 09:16:04 2019 +0000
@@ -81,7 +81,7 @@
                 stresser.start(runParams.getIterations());
                 while (!this.isInterrupted() && stresser.iteration()) {
                     test.run();
-                    yield();
+                    Thread.yield();
                 }
                 waitForOtherThreads();
             } catch (OutOfMemoryError oom) {
--- a/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/GarbageGenerator.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/GarbageGenerator.java	Wed Nov 13 09:16:04 2019 +0000
@@ -84,7 +84,7 @@
         while (!done) {
             for (g = 0; g < ringSize; g++) {
                 gr.add(allocSize);
-                yield();
+                Thread.yield();
             }
             gr.discard();
             try {
--- a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace001.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace001.java	Wed Nov 13 09:16:04 2019 +0000
@@ -295,7 +295,7 @@
         }
 
         if (strace001.DEPTH - currentDepth > 0) {
-            yield();
+            Thread.yield();
             recursiveMethod();
         }
 
--- a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace002.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace002.java	Wed Nov 13 09:16:04 2019 +0000
@@ -304,7 +304,7 @@
         }
 
         if (strace002.DEPTH - currentDepth > 0) {
-            yield();
+            Thread.yield();
             recursiveMethod();
         }
 
--- a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace005.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace005.java	Wed Nov 13 09:16:04 2019 +0000
@@ -387,7 +387,7 @@
 
         if (strace005.DEPTH - currentDepth > 0) {
             try {
-                yield();
+                Thread.yield();
                 recursiveMethod2();
             } catch (StackOverflowError e) {
                 // ignore this exception
--- a/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace006.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace006.java	Wed Nov 13 09:16:04 2019 +0000
@@ -331,7 +331,7 @@
 
         if (strace006.DEPTH - currentDepth > 0) {
             try {
-                yield();
+                Thread.yield();
                 recursiveMethod2();
             } catch (StackOverflowError e) {
                 // ignore this exception
--- a/test/hotspot/jtreg/vmTestbase/nsk/stress/thread/thread005.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/thread/thread005.java	Wed Nov 13 09:16:04 2019 +0000
@@ -160,7 +160,7 @@
      */
     public void run() {
         while (!GO && !timeout())
-            yield();
+            Thread.yield();
         while (!STOP && !timeout())
             ;
     }
--- a/test/hotspot/jtreg/vmTestbase/nsk/stress/thread/thread006.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/stress/thread/thread006.java	Wed Nov 13 09:16:04 2019 +0000
@@ -176,7 +176,7 @@
      */
     public void run() {
         while (!GO && !timeout())
-            yield();
+            Thread.yield();
         while (!STOP && !timeout())
             ;
     }
--- a/test/jdk/ProblemList.txt	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/jdk/ProblemList.txt	Wed Nov 13 09:16:04 2019 +0000
@@ -837,6 +837,8 @@
 
 tools/pack200/CommandLineTests.java                             8059906 generic-all
 
+tools/jlink/JLinkReproducibleTest.java                          8217166 windows-all
+
 ############################################################################
 
 # jdk_jdi
@@ -861,7 +863,6 @@
 
 # svc_tools
 
-sun/tools/jstat/jstatClassloadOutput1.sh                        8173942 generic-all
 sun/tools/jhsdb/BasicLauncherTest.java                          8193639,8211767 solaris-all,linux-ppc64,linux-ppc64le
 sun/tools/jhsdb/HeapDumpTest.java                               8193639 solaris-all
 sun/tools/jhsdb/HeapDumpTestWithActiveProcess.java              8230731,8001227 windows-all
--- a/test/jdk/com/sun/jdi/InvokeHangTest.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/jdk/com/sun/jdi/InvokeHangTest.java	Wed Nov 13 09:16:04 2019 +0000
@@ -64,7 +64,7 @@
     // This is called from the debugger via invokeMethod
     public double invokeee() {
         System.out.println("Debuggee: invokeee in thread "+Thread.currentThread().toString());
-        yield();
+        Thread.yield();
         return longMethod(2);
     }
     public double longMethod(int n) {
--- a/test/jdk/com/sun/jdi/SimulResumerTest.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/jdk/com/sun/jdi/SimulResumerTest.java	Wed Nov 13 09:16:04 2019 +0000
@@ -71,7 +71,7 @@
 
     public void bkpt1(int i) {
         synchronized(name1) {
-            yield();
+            Thread.yield();
         }
     }
 
@@ -85,7 +85,7 @@
 
     public void bkpt2(int i) {
         synchronized(name2) {
-            yield();
+            Thread.yield();
         }
     }
 
--- a/test/jdk/com/sun/jdi/TwoThreadsTest.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/jdk/com/sun/jdi/TwoThreadsTest.java	Wed Nov 13 09:16:04 2019 +0000
@@ -70,7 +70,7 @@
     }
 
     public void bkpt1(int i) {
-        yield();
+        Thread.yield();
     }
 
     public void run1() {
@@ -82,7 +82,7 @@
     }
 
     public void bkpt2(int i) {
-        yield();
+        Thread.yield();
     }
 
     public void run2() {
--- a/test/jdk/java/awt/Graphics2D/MTGraphicsAccessTest/MTGraphicsAccessTest.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/jdk/java/awt/Graphics2D/MTGraphicsAccessTest/MTGraphicsAccessTest.java	Wed Nov 13 09:16:04 2019 +0000
@@ -197,7 +197,7 @@
                 while (!done) {
                     try {
                         testRunnable.run();
-                        yield();
+                        Thread.yield();
                     } catch (Throwable t) {
                         numexceptions++;
                         t.printStackTrace();
--- a/test/jdk/java/lang/String/Formatted.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/jdk/java/lang/String/Formatted.java	Wed Nov 13 09:16:04 2019 +0000
@@ -25,7 +25,7 @@
  * @test
  * bug 8203444
  * @summary Unit tests for instance versions of String#format
- * @compile --enable-preview -source 14 Formatted.java
+ * @compile --enable-preview -source ${jdk.version} Formatted.java
  * @run main/othervm --enable-preview Formatted
  */
 
--- a/test/jdk/java/lang/String/StripIndent.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/jdk/java/lang/String/StripIndent.java	Wed Nov 13 09:16:04 2019 +0000
@@ -25,7 +25,7 @@
  * @test
  * @bug 8223775
  * @summary This exercises String#stripIndent patterns and limits.
- * @compile --enable-preview -source 14 StripIndent.java
+ * @compile --enable-preview -source ${jdk.version} StripIndent.java
  * @run main/othervm --enable-preview StripIndent
  */
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/lang/String/TEST.properties	Wed Nov 13 09:16:04 2019 +0000
@@ -0,0 +1,1 @@
+allowSmartActionArgs=true
--- a/test/jdk/java/lang/String/TranslateEscapes.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/jdk/java/lang/String/TranslateEscapes.java	Wed Nov 13 09:16:04 2019 +0000
@@ -25,7 +25,7 @@
  * @test
  * @bug 8223780
  * @summary This exercises String#translateEscapes patterns and limits.
- * @compile --enable-preview -source 14 TranslateEscapes.java
+ * @compile --enable-preview -source ${jdk.version} TranslateEscapes.java
  * @run main/othervm --enable-preview TranslateEscapes
  */
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/net/httpclient/AuthFilterCacheTest.java	Wed Nov 13 09:16:04 2019 +0000
@@ -0,0 +1,298 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.IOException;
+import java.net.*;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicLong;
+
+import com.sun.net.httpserver.HttpServer;
+import com.sun.net.httpserver.HttpsConfigurator;
+import com.sun.net.httpserver.HttpsServer;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import javax.net.ssl.SSLContext;
+
+/**
+ * @test
+ * @bug 8232853
+ * @summary AuthenticationFilter.Cache::remove may throw ConcurrentModificationException
+ * @library /test/lib http2/server
+ * @build jdk.test.lib.net.SimpleSSLContext HttpServerAdapters DigestEchoServer HttpRedirectTest
+ * @modules java.net.http/jdk.internal.net.http.common
+ * java.net.http/jdk.internal.net.http.frame
+ * java.net.http/jdk.internal.net.http.hpack
+ * java.logging
+ * java.base/sun.net.www.http
+ * java.base/sun.net.www
+ * java.base/sun.net
+ * @run testng/othervm -Dtest.requiresHost=true
+ * -Djdk.httpclient.HttpClient.log=headers
+ * -Djdk.internal.httpclient.debug=false
+ * AuthFilterCacheTest
+ */
+
+public class AuthFilterCacheTest implements HttpServerAdapters {
+
+    static final String RESPONSE_BODY = "Hello World!";
+    static final int REQUEST_COUNT = 5;
+    static final int URI_COUNT = 6;
+    static final CyclicBarrier barrier = new CyclicBarrier(REQUEST_COUNT * URI_COUNT);
+    static final SSLContext context;
+
+    static {
+        try {
+            context = new jdk.test.lib.net.SimpleSSLContext().get();
+            SSLContext.setDefault(context);
+        } catch (Exception x) {
+            throw new ExceptionInInitializerError(x);
+        }
+    }
+
+    HttpTestServer http1Server;
+    HttpTestServer http2Server;
+    HttpTestServer https1Server;
+    HttpTestServer https2Server;
+    DigestEchoServer.TunnelingProxy proxy;
+    URI http1URI;
+    URI https1URI;
+    URI http2URI;
+    URI https2URI;
+    InetSocketAddress proxyAddress;
+    ProxySelector proxySelector;
+    MyAuthenticator auth;
+    HttpClient client;
+    Executor executor = Executors.newCachedThreadPool();
+
+    @DataProvider(name = "uris")
+    Object[][] testURIs() {
+        Object[][] uris = new Object[][]{
+                {List.of(http1URI.resolve("direct/orig/"),
+                        https1URI.resolve("direct/orig/"),
+                        https1URI.resolve("proxy/orig/"),
+                        http2URI.resolve("direct/orig/"),
+                        https2URI.resolve("direct/orig/"),
+                        https2URI.resolve("proxy/orig/"))}
+        };
+        return uris;
+    }
+
+    public HttpClient newHttpClient(ProxySelector ps, Authenticator auth) {
+        HttpClient.Builder builder = HttpClient
+                .newBuilder()
+                .sslContext(context)
+                .authenticator(auth)
+                .proxy(ps);
+        return builder.build();
+    }
+
+    @BeforeClass
+    public void setUp() throws Exception {
+        try {
+            InetSocketAddress sa =
+                    new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
+            auth = new MyAuthenticator();
+
+            // HTTP/1.1
+            HttpServer server1 = HttpServer.create(sa, 0);
+            server1.setExecutor(executor);
+            http1Server = HttpTestServer.of(server1);
+            http1Server.addHandler(new TestHandler(), "/AuthFilterCacheTest/http1/");
+            http1Server.start();
+            http1URI = new URI("http://" + http1Server.serverAuthority()
+                    + "/AuthFilterCacheTest/http1/");
+
+            // HTTPS/1.1
+            HttpsServer sserver1 = HttpsServer.create(sa, 100);
+            sserver1.setExecutor(executor);
+            sserver1.setHttpsConfigurator(new HttpsConfigurator(context));
+            https1Server = HttpTestServer.of(sserver1);
+            https1Server.addHandler(new TestHandler(), "/AuthFilterCacheTest/https1/");
+            https1Server.start();
+            https1URI = new URI("https://" + https1Server.serverAuthority()
+                    + "/AuthFilterCacheTest/https1/");
+
+            // HTTP/2.0
+            http2Server = HttpTestServer.of(
+                    new Http2TestServer("localhost", false, 0));
+            http2Server.addHandler(new TestHandler(), "/AuthFilterCacheTest/http2/");
+            http2Server.start();
+            http2URI = new URI("http://" + http2Server.serverAuthority()
+                    + "/AuthFilterCacheTest/http2/");
+
+            // HTTPS/2.0
+            https2Server = HttpTestServer.of(
+                    new Http2TestServer("localhost", true, 0));
+            https2Server.addHandler(new TestHandler(), "/AuthFilterCacheTest/https2/");
+            https2Server.start();
+            https2URI = new URI("https://" + https2Server.serverAuthority()
+                    + "/AuthFilterCacheTest/https2/");
+
+            proxy = DigestEchoServer.createHttpsProxyTunnel(
+                    DigestEchoServer.HttpAuthSchemeType.NONE);
+            proxyAddress = proxy.getProxyAddress();
+            proxySelector = new HttpProxySelector(proxyAddress);
+            client = newHttpClient(proxySelector, auth);
+
+            System.out.println("Setup: done");
+        } catch (Exception x) {
+            tearDown();
+            throw x;
+        } catch (Error e) {
+            tearDown();
+            throw e;
+        }
+    }
+
+    @AfterClass
+    public void tearDown() {
+        proxy = stop(proxy, DigestEchoServer.TunnelingProxy::stop);
+        http1Server = stop(http1Server, HttpTestServer::stop);
+        https1Server = stop(https1Server, HttpTestServer::stop);
+        http2Server = stop(http2Server, HttpTestServer::stop);
+        https2Server = stop(https2Server, HttpTestServer::stop);
+        client = null;
+
+        System.out.println("Teardown: done");
+    }
+
+    private interface Stoppable<T> {
+        void stop(T service) throws Exception;
+    }
+
+    static <T> T stop(T service, Stoppable<T> stop) {
+        try {
+            if (service != null) stop.stop(service);
+        } catch (Throwable x) {
+        }
+        return null;
+    }
+
+    static class HttpProxySelector extends ProxySelector {
+        private static final List<Proxy> NO_PROXY = List.of(Proxy.NO_PROXY);
+        private final List<Proxy> proxyList;
+
+        HttpProxySelector(InetSocketAddress proxyAddress) {
+            proxyList = List.of(new Proxy(Proxy.Type.HTTP, proxyAddress));
+        }
+
+        @Override
+        public List<Proxy> select(URI uri) {
+            // Our proxy only supports tunneling
+            if (uri.getScheme().equalsIgnoreCase("https")) {
+                if (uri.getPath().contains("/proxy/")) {
+                    return proxyList;
+                }
+            }
+            return NO_PROXY;
+        }
+
+        @Override
+        public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
+            System.err.println("Connection to proxy failed: " + ioe);
+            System.err.println("Proxy: " + sa);
+            System.err.println("\tURI: " + uri);
+            ioe.printStackTrace();
+        }
+    }
+
+    public static class TestHandler implements HttpTestHandler {
+        static final AtomicLong respCounter = new AtomicLong();
+
+        @Override
+        public void handle(HttpTestExchange t) throws IOException {
+            var count = respCounter.incrementAndGet();
+            System.out.println("Responses handled: " + count);
+            t.getRequestBody().readAllBytes();
+
+            if (t.getRequestMethod().equalsIgnoreCase("GET")) {
+                if (!t.getRequestHeaders().containsKey("Authorization")) {
+                    t.getResponseHeaders()
+                            .addHeader("WWW-Authenticate", "Basic realm=\"Earth\"");
+                    t.sendResponseHeaders(401, 0);
+                } else {
+                    byte[] resp = RESPONSE_BODY.getBytes(StandardCharsets.UTF_8);
+                    t.sendResponseHeaders(200, resp.length);
+                    try {
+                        barrier.await();
+                    } catch (Exception e) {
+                        throw new IOException(e);
+                    }
+                    t.getResponseBody().write(resp);
+                }
+            }
+            t.close();
+        }
+    }
+
+    void doClient(List<URI> uris) {
+        assert uris.size() == URI_COUNT;
+        barrier.reset();
+        System.out.println("Client opening connection to: " + uris.toString());
+
+        List<CompletableFuture<HttpResponse<String>>> cfs = new ArrayList<>();
+
+        for (int i = 0; i < REQUEST_COUNT; i++) {
+            for (URI uri : uris) {
+                HttpRequest req = HttpRequest.newBuilder()
+                        .uri(uri)
+                        .build();
+                cfs.add(client.sendAsync(req, HttpResponse.BodyHandlers.ofString()));
+            }
+        }
+        CompletableFuture.allOf(cfs.toArray(new CompletableFuture[0])).join();
+    }
+
+    static class MyAuthenticator extends Authenticator {
+        private int count = 0;
+
+        MyAuthenticator() {
+            super();
+        }
+
+        public PasswordAuthentication getPasswordAuthentication() {
+            System.out.println("Authenticator called: " + ++count);
+            return (new PasswordAuthentication("user" + count,
+                    ("passwordNotCheckedAnyway" + count).toCharArray()));
+        }
+
+        public int getCount() {
+            return count;
+        }
+    }
+
+    @Test(dataProvider = "uris")
+    public void test(List<URI> uris) throws Exception {
+        System.out.println("Server listening at " + uris.toString());
+        doClient(uris);
+    }
+}
--- a/test/jdk/java/util/Arrays/ParallelSorting.java	Tue Nov 12 15:07:15 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2067 +0,0 @@
-/*
- * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/* Adapted from test/java/util/Arrays/Sorting.java
- *
- * Where that test checks Arrays.sort against manual quicksort routines,
- * this test checks parallelSort against either Arrays.sort or manual
- * quicksort routines.
- */
-
-/*
- * @test
- * @bug 8003981
- * @run main ParallelSorting -shortrun
- * @summary Exercise Arrays.parallelSort (adapted from test Sorting)
- *
- * @author Vladimir Yaroslavskiy
- * @author Jon Bentley
- * @author Josh Bloch
- */
-
-import java.util.Arrays;
-import java.util.Random;
-import java.io.PrintStream;
-import java.util.Comparator;
-
-public class ParallelSorting {
-    private static final PrintStream out = System.out;
-    private static final PrintStream err = System.err;
-
-    // Array lengths used in a long run (default)
-    private static final int[] LONG_RUN_LENGTHS = {
-        1000, 10000, 100000, 1000000 };
-
-    // Array lengths used in a short run
-    private static final int[] SHORT_RUN_LENGTHS = {
-        5000, 9000, 10000, 12000 };
-
-    // Random initial values used in a long run (default)
-    private static final long[] LONG_RUN_RANDOMS = { 666, 0xC0FFEE, 999 };
-
-    // Random initial values used in a short run
-    private static final long[] SHORT_RUN_RANDOMS = { 666 };
-
-    public static void main(String[] args) {
-        boolean shortRun = args.length > 0 && args[0].equals("-shortrun");
-        long start = System.currentTimeMillis();
-
-        if (shortRun) {
-            testAndCheck(SHORT_RUN_LENGTHS, SHORT_RUN_RANDOMS);
-        } else {
-            testAndCheck(LONG_RUN_LENGTHS, LONG_RUN_RANDOMS);
-        }
-        long end = System.currentTimeMillis();
-
-        out.format("PASSED in %d sec.\n", Math.round((end - start) / 1E3));
-    }
-
-    private static void testAndCheck(int[] lengths, long[] randoms) {
-        testEmptyAndNullIntArray();
-        testEmptyAndNullLongArray();
-        testEmptyAndNullShortArray();
-        testEmptyAndNullCharArray();
-        testEmptyAndNullByteArray();
-        testEmptyAndNullFloatArray();
-        testEmptyAndNullDoubleArray();
-
-        for (int length : lengths) {
-            testMergeSort(length);
-            testAndCheckRange(length);
-            testAndCheckSubArray(length);
-        }
-        for (long seed : randoms) {
-            for (int length : lengths) {
-                testAndCheckWithInsertionSort(length, new MyRandom(seed));
-                testAndCheckWithCheckSum(length, new MyRandom(seed));
-                testAndCheckWithScrambling(length, new MyRandom(seed));
-                testAndCheckFloat(length, new MyRandom(seed));
-                testAndCheckDouble(length, new MyRandom(seed));
-                testStable(length, new MyRandom(seed));
-            }
-        }
-    }
-
-    private static void testEmptyAndNullIntArray() {
-        ourDescription = "Check empty and null array";
-        Arrays.parallelSort(new int[]{});
-        Arrays.parallelSort(new int[]{}, 0, 0);
-
-        try {
-            Arrays.parallelSort((int[]) null);
-        } catch (NullPointerException expected) {
-            try {
-                Arrays.parallelSort((int[]) null, 0, 0);
-            } catch (NullPointerException expected2) {
-                return;
-            }
-            failed("Arrays.parallelSort(int[],fromIndex,toIndex) shouldn't " +
-                "catch null array");
-        }
-        failed("Arrays.parallelSort(int[]) shouldn't catch null array");
-    }
-
-    private static void testEmptyAndNullLongArray() {
-        ourDescription = "Check empty and null array";
-        Arrays.parallelSort(new long[]{});
-        Arrays.parallelSort(new long[]{}, 0, 0);
-
-        try {
-            Arrays.parallelSort((long[]) null);
-        } catch (NullPointerException expected) {
-            try {
-                Arrays.parallelSort((long[]) null, 0, 0);
-            } catch (NullPointerException expected2) {
-                return;
-            }
-            failed("Arrays.parallelSort(long[],fromIndex,toIndex) shouldn't " +
-                "catch null array");
-        }
-        failed("Arrays.parallelSort(long[]) shouldn't catch null array");
-    }
-
-    private static void testEmptyAndNullShortArray() {
-        ourDescription = "Check empty and null array";
-        Arrays.parallelSort(new short[]{});
-        Arrays.parallelSort(new short[]{}, 0, 0);
-
-        try {
-            Arrays.parallelSort((short[]) null);
-        } catch (NullPointerException expected) {
-            try {
-                Arrays.parallelSort((short[]) null, 0, 0);
-            } catch (NullPointerException expected2) {
-                return;
-            }
-            failed("Arrays.parallelSort(short[],fromIndex,toIndex) shouldn't " +
-                "catch null array");
-        }
-        failed("Arrays.parallelSort(short[]) shouldn't catch null array");
-    }
-
-    private static void testEmptyAndNullCharArray() {
-        ourDescription = "Check empty and null array";
-        Arrays.parallelSort(new char[]{});
-        Arrays.parallelSort(new char[]{}, 0, 0);
-
-        try {
-            Arrays.parallelSort((char[]) null);
-        } catch (NullPointerException expected) {
-            try {
-                Arrays.parallelSort((char[]) null, 0, 0);
-            } catch (NullPointerException expected2) {
-                return;
-            }
-            failed("Arrays.parallelSort(char[],fromIndex,toIndex) shouldn't " +
-                "catch null array");
-        }
-        failed("Arrays.parallelSort(char[]) shouldn't catch null array");
-    }
-
-    private static void testEmptyAndNullByteArray() {
-        ourDescription = "Check empty and null array";
-        Arrays.parallelSort(new byte[]{});
-        Arrays.parallelSort(new byte[]{}, 0, 0);
-
-        try {
-            Arrays.parallelSort((byte[]) null);
-        } catch (NullPointerException expected) {
-            try {
-                Arrays.parallelSort((byte[]) null, 0, 0);
-            } catch (NullPointerException expected2) {
-                return;
-            }
-            failed("Arrays.parallelSort(byte[],fromIndex,toIndex) shouldn't " +
-                "catch null array");
-        }
-        failed("Arrays.parallelSort(byte[]) shouldn't catch null array");
-    }
-
-    private static void testEmptyAndNullFloatArray() {
-        ourDescription = "Check empty and null array";
-        Arrays.parallelSort(new float[]{});
-        Arrays.parallelSort(new float[]{}, 0, 0);
-
-        try {
-            Arrays.parallelSort((float[]) null);
-        } catch (NullPointerException expected) {
-            try {
-                Arrays.parallelSort((float[]) null, 0, 0);
-            } catch (NullPointerException expected2) {
-                return;
-            }
-            failed("Arrays.parallelSort(float[],fromIndex,toIndex) shouldn't " +
-                "catch null array");
-        }
-        failed("Arrays.parallelSort(float[]) shouldn't catch null array");
-    }
-
-    private static void testEmptyAndNullDoubleArray() {
-        ourDescription = "Check empty and null array";
-        Arrays.parallelSort(new double[]{});
-        Arrays.parallelSort(new double[]{}, 0, 0);
-
-        try {
-            Arrays.parallelSort((double[]) null);
-        } catch (NullPointerException expected) {
-            try {
-                Arrays.parallelSort((double[]) null, 0, 0);
-            } catch (NullPointerException expected2) {
-                return;
-            }
-            failed("Arrays.parallelSort(double[],fromIndex,toIndex) shouldn't " +
-                "catch null array");
-        }
-        failed("Arrays.parallelSort(double[]) shouldn't catch null array");
-    }
-
-    private static void testAndCheckSubArray(int length) {
-        ourDescription = "Check sorting of subarray";
-        int[] golden = new int[length];
-        boolean newLine = false;
-
-        for (int m = 1; m < length / 2; m *= 2) {
-            newLine = true;
-            int fromIndex = m;
-            int toIndex = length - m;
-
-            prepareSubArray(golden, fromIndex, toIndex, m);
-            int[] test = golden.clone();
-
-            for (TypeConverter converter : TypeConverter.values()) {
-                out.println("Test 'subarray': " + converter +
-                   " length = " + length + ", m = " + m);
-                Object convertedGolden = converter.convert(golden);
-                Object convertedTest = converter.convert(test);
-                sortSubArray(convertedTest, fromIndex, toIndex);
-                checkSubArray(convertedTest, fromIndex, toIndex, m);
-            }
-        }
-        if (newLine) {
-            out.println();
-        }
-    }
-
-    private static void testAndCheckRange(int length) {
-        ourDescription = "Check range check";
-        int[] golden = new int[length];
-
-        for (int m = 1; m < 2 * length; m *= 2) {
-            for (int i = 1; i <= length; i++) {
-                golden[i - 1] = i % m + m % i;
-            }
-            for (TypeConverter converter : TypeConverter.values()) {
-                out.println("Test 'range': " + converter +
-                   ", length = " + length + ", m = " + m);
-                Object convertedGolden = converter.convert(golden);
-                checkRange(convertedGolden, m);
-            }
-        }
-        out.println();
-    }
-
-    private static void testStable(int length, MyRandom random) {
-        ourDescription = "Check if sorting is stable";
-        Pair[] a = build(length, random);
-
-        out.println("Test 'stable': " + "random = " + random.getSeed() +
-            ", length = " + length);
-        Arrays.parallelSort(a);
-        checkSorted(a);
-        checkStable(a);
-        out.println();
-
-        a = build(length, random);
-
-        out.println("Test 'stable' comparator: " + "random = " + random.getSeed() +
-            ", length = " + length);
-        Arrays.parallelSort(a, pairCmp);
-        checkSorted(a);
-        checkStable(a);
-        out.println();
-
-    }
-
-    private static void checkSorted(Pair[] a) {
-        for (int i = 0; i < a.length - 1; i++) {
-            if (a[i].getKey() > a[i + 1].getKey()) {
-                failedSort(i, "" + a[i].getKey(), "" + a[i + 1].getKey());
-            }
-        }
-    }
-
-    private static void checkStable(Pair[] a) {
-        for (int i = 0; i < a.length / 4; ) {
-            int key1 = a[i].getKey();
-            int value1 = a[i++].getValue();
-            int key2 = a[i].getKey();
-            int value2 = a[i++].getValue();
-            int key3 = a[i].getKey();
-            int value3 = a[i++].getValue();
-            int key4 = a[i].getKey();
-            int value4 = a[i++].getValue();
-
-            if (!(key1 == key2 && key2 == key3 && key3 == key4)) {
-                failed("On position " + i + " keys are different " +
-                    key1 + ", " + key2 + ", " + key3 + ", " + key4);
-            }
-            if (!(value1 < value2 && value2 < value3 && value3 < value4)) {
-                failed("Sorting is not stable at position " + i +
-                    ". Second values have been changed: " +  value1 + ", " +
-                    value2 + ", " + value3 + ", " + value4);
-            }
-        }
-    }
-
-    private static Pair[] build(int length, Random random) {
-        Pair[] a = new Pair[length * 4];
-
-        for (int i = 0; i < a.length; ) {
-            int key = random.nextInt();
-            a[i++] = new Pair(key, 1);
-            a[i++] = new Pair(key, 2);
-            a[i++] = new Pair(key, 3);
-            a[i++] = new Pair(key, 4);
-        }
-        return a;
-    }
-
-    private static Comparator<Pair> pairCmp = new Comparator<Pair>() {
-        public int compare(Pair p1, Pair p2) {
-            return p1.compareTo(p2);
-        }
-    };
-
-    private static final class Pair implements Comparable<Pair> {
-        Pair(int key, int value) {
-            myKey = key;
-            myValue = value;
-        }
-
-        int getKey() {
-            return myKey;
-        }
-
-        int getValue() {
-            return myValue;
-        }
-
-        public int compareTo(Pair pair) {
-            if (myKey < pair.myKey) {
-                return -1;
-            }
-            if (myKey > pair.myKey) {
-                return 1;
-            }
-            return 0;
-        }
-
-        @Override
-        public String toString() {
-            return "(" + myKey + ", " + myValue + ")";
-        }
-
-        private int myKey;
-        private int myValue;
-    }
-
-
-    private static void testAndCheckWithInsertionSort(int length, MyRandom random) {
-        if (length > 1000) {
-            return;
-        }
-        ourDescription = "Check sorting with insertion sort";
-        int[] golden = new int[length];
-
-        for (int m = 1; m < 2 * length; m *= 2) {
-            for (UnsortedBuilder builder : UnsortedBuilder.values()) {
-                builder.build(golden, m, random);
-                int[] test = golden.clone();
-
-                for (TypeConverter converter : TypeConverter.values()) {
-                    out.println("Test 'insertion sort': " + converter +
-                        " " + builder + "random = " + random.getSeed() +
-                        ", length = " + length + ", m = " + m);
-                    Object convertedGolden = converter.convert(golden);
-                    Object convertedTest1 = converter.convert(test);
-                    Object convertedTest2 = converter.convert(test);
-                    sort(convertedTest1);
-                    sortByInsertionSort(convertedTest2);
-                    compare(convertedTest1, convertedTest2);
-                }
-            }
-        }
-        out.println();
-    }
-
-    private static void testMergeSort(int length) {
-        if (length < 1000) {
-            return;
-        }
-        ourDescription = "Check merge sorting";
-        int[] golden = new int[length];
-        int period = 67; // java.util.DualPivotQuicksort.MAX_RUN_COUNT
-
-        for (int m = period - 2; m <= period + 2; m++) {
-            for (MergeBuilder builder : MergeBuilder.values()) {
-                builder.build(golden, m);
-                int[] test = golden.clone();
-
-                for (TypeConverter converter : TypeConverter.values()) {
-                    out.println("Test 'merge sort': " + converter + " " +
-                        builder + "length = " + length + ", m = " + m);
-                    Object convertedGolden = converter.convert(golden);
-                    sort(convertedGolden);
-                    checkSorted(convertedGolden);
-                }
-            }
-        }
-        out.println();
-    }
-
-    private static void testAndCheckWithCheckSum(int length, MyRandom random) {
-        ourDescription = "Check sorting with check sum";
-        int[] golden = new int[length];
-
-        for (int m = 1; m < 2 * length; m *= 2) {
-            for (UnsortedBuilder builder : UnsortedBuilder.values()) {
-                builder.build(golden, m, random);
-                int[] test = golden.clone();
-
-                for (TypeConverter converter : TypeConverter.values()) {
-                    out.println("Test 'check sum': " + converter +
-                        " " + builder + "random = " + random.getSeed() +
-                        ", length = " + length + ", m = " + m);
-                    Object convertedGolden = converter.convert(golden);
-                    Object convertedTest = converter.convert(test);
-                    sort(convertedTest);
-                    checkWithCheckSum(convertedTest, convertedGolden);
-                }
-            }
-        }
-        out.println();
-    }
-
-    private static void testAndCheckWithScrambling(int length, MyRandom random) {
-        ourDescription = "Check sorting with scrambling";
-        int[] golden = new int[length];
-
-        for (int m = 1; m <= 7; m++) {
-            if (m > length) {
-                break;
-            }
-            for (SortedBuilder builder : SortedBuilder.values()) {
-                builder.build(golden, m);
-                int[] test = golden.clone();
-                scramble(test, random);
-
-                for (TypeConverter converter : TypeConverter.values()) {
-                    out.println("Test 'scrambling': " + converter +
-                       " " + builder + "random = " + random.getSeed() +
-                       ", length = " + length + ", m = " + m);
-                    Object convertedGolden = converter.convert(golden);
-                    Object convertedTest = converter.convert(test);
-                    sort(convertedTest);
-                    compare(convertedTest, convertedGolden);
-                }
-            }
-        }
-        out.println();
-    }
-
-    private static void testAndCheckFloat(int length, MyRandom random) {
-        ourDescription = "Check float sorting";
-        float[] golden = new float[length];
-        final int MAX = 10;
-        boolean newLine = false;
-
-        for (int a = 0; a <= MAX; a++) {
-            for (int g = 0; g <= MAX; g++) {
-                for (int z = 0; z <= MAX; z++) {
-                    for (int n = 0; n <= MAX; n++) {
-                        for (int p = 0; p <= MAX; p++) {
-                            if (a + g + z + n + p > length) {
-                                continue;
-                            }
-                            if (a + g + z + n + p < length) {
-                                continue;
-                            }
-                            for (FloatBuilder builder : FloatBuilder.values()) {
-                                out.println("Test 'float': random = " + random.getSeed() +
-                                   ", length = " + length + ", a = " + a + ", g = " +
-                                   g + ", z = " + z + ", n = " + n + ", p = " + p);
-                                builder.build(golden, a, g, z, n, p, random);
-                                float[] test = golden.clone();
-                                scramble(test, random);
-                                sort(test);
-                                compare(test, golden, a, n, g);
-                            }
-                            newLine = true;
-                        }
-                    }
-                }
-            }
-        }
-        if (newLine) {
-            out.println();
-        }
-    }
-
-    private static void testAndCheckDouble(int length, MyRandom random) {
-        ourDescription = "Check double sorting";
-        double[] golden = new double[length];
-        final int MAX = 10;
-        boolean newLine = false;
-
-        for (int a = 0; a <= MAX; a++) {
-            for (int g = 0; g <= MAX; g++) {
-                for (int z = 0; z <= MAX; z++) {
-                    for (int n = 0; n <= MAX; n++) {
-                        for (int p = 0; p <= MAX; p++) {
-                            if (a + g + z + n + p > length) {
-                                continue;
-                            }
-                            if (a + g + z + n + p < length) {
-                                continue;
-                            }
-                            for (DoubleBuilder builder : DoubleBuilder.values()) {
-                                out.println("Test 'double': random = " + random.getSeed() +
-                                   ", length = " + length + ", a = " + a + ", g = " +
-                                   g + ", z = " + z + ", n = " + n + ", p = " + p);
-                                builder.build(golden, a, g, z, n, p, random);
-                                double[] test = golden.clone();
-                                scramble(test, random);
-                                sort(test);
-                                compare(test, golden, a, n, g);
-                            }
-                            newLine = true;
-                        }
-                    }
-                }
-            }
-        }
-        if (newLine) {
-            out.println();
-        }
-    }
-
-    private static void prepareSubArray(int[] a, int fromIndex, int toIndex, int m) {
-        for (int i = 0; i < fromIndex; i++) {
-            a[i] = 0xDEDA;
-        }
-        int middle = (fromIndex + toIndex) >>> 1;
-        int k = 0;
-
-        for (int i = fromIndex; i < middle; i++) {
-            a[i] = k++;
-        }
-        for (int i = middle; i < toIndex; i++) {
-            a[i] = k--;
-        }
-        for (int i = toIndex; i < a.length; i++) {
-            a[i] = 0xBABA;
-        }
-    }
-
-    private static void scramble(int[] a, Random random) {
-        for (int i = 0; i < a.length * 7; i++) {
-            swap(a, random.nextInt(a.length), random.nextInt(a.length));
-        }
-    }
-
-    private static void scramble(float[] a, Random random) {
-        for (int i = 0; i < a.length * 7; i++) {
-            swap(a, random.nextInt(a.length), random.nextInt(a.length));
-        }
-    }
-
-    private static void scramble(double[] a, Random random) {
-        for (int i = 0; i < a.length * 7; i++) {
-            swap(a, random.nextInt(a.length), random.nextInt(a.length));
-        }
-    }
-
-    private static void swap(int[] a, int i, int j) {
-        int t = a[i];
-        a[i] = a[j];
-        a[j] = t;
-    }
-
-    private static void swap(float[] a, int i, int j) {
-        float t = a[i];
-        a[i] = a[j];
-        a[j] = t;
-    }
-
-    private static void swap(double[] a, int i, int j) {
-        double t = a[i];
-        a[i] = a[j];
-        a[j] = t;
-    }
-
-    private static enum TypeConverter {
-        INT {
-            Object convert(int[] a) {
-                return a.clone();
-            }
-        },
-        LONG {
-            Object convert(int[] a) {
-                long[] b = new long[a.length];
-
-                for (int i = 0; i < a.length; i++) {
-                    b[i] = (long) a[i];
-                }
-                return b;
-            }
-        },
-        BYTE {
-            Object convert(int[] a) {
-                byte[] b = new byte[a.length];
-
-                for (int i = 0; i < a.length; i++) {
-                    b[i] = (byte) a[i];
-                }
-                return b;
-            }
-        },
-        SHORT {
-            Object convert(int[] a) {
-                short[] b = new short[a.length];
-
-                for (int i = 0; i < a.length; i++) {
-                    b[i] = (short) a[i];
-                }
-                return b;
-            }
-        },
-        CHAR {
-            Object convert(int[] a) {
-                char[] b = new char[a.length];
-
-                for (int i = 0; i < a.length; i++) {
-                    b[i] = (char) a[i];
-                }
-                return b;
-            }
-        },
-        FLOAT {
-            Object convert(int[] a) {
-                float[] b = new float[a.length];
-
-                for (int i = 0; i < a.length; i++) {
-                    b[i] = (float) a[i];
-                }
-                return b;
-            }
-        },
-        DOUBLE {
-            Object convert(int[] a) {
-                double[] b = new double[a.length];
-
-                for (int i = 0; i < a.length; i++) {
-                    b[i] = (double) a[i];
-                }
-                return b;
-            }
-        },
-        INTEGER {
-            Object convert(int[] a) {
-                Integer[] b = new Integer[a.length];
-
-                for (int i = 0; i < a.length; i++) {
-                    b[i] = new Integer(a[i]);
-                }
-                return b;
-            }
-        };
-
-        abstract Object convert(int[] a);
-
-        @Override public String toString() {
-            String name = name();
-
-            for (int i = name.length(); i < 9; i++) {
-                name += " ";
-            }
-            return name;
-        }
-    }
-
-    private static enum FloatBuilder {
-        SIMPLE {
-            void build(float[] x, int a, int g, int z, int n, int p, Random random) {
-                int fromIndex = 0;
-                float negativeValue = -random.nextFloat();
-                float positiveValue =  random.nextFloat();
-
-                writeValue(x, negativeValue, fromIndex, n);
-                fromIndex += n;
-
-                writeValue(x, -0.0f, fromIndex, g);
-                fromIndex += g;
-
-                writeValue(x, 0.0f, fromIndex, z);
-                fromIndex += z;
-
-                writeValue(x, positiveValue, fromIndex, p);
-                fromIndex += p;
-
-                writeValue(x, Float.NaN, fromIndex, a);
-            }
-        };
-
-        abstract void build(float[] x, int a, int g, int z, int n, int p, Random random);
-    }
-
-    private static enum DoubleBuilder {
-        SIMPLE {
-            void build(double[] x, int a, int g, int z, int n, int p, Random random) {
-                int fromIndex = 0;
-                double negativeValue = -random.nextFloat();
-                double positiveValue =  random.nextFloat();
-
-                writeValue(x, negativeValue, fromIndex, n);
-                fromIndex += n;
-
-                writeValue(x, -0.0d, fromIndex, g);
-                fromIndex += g;
-
-                writeValue(x, 0.0d, fromIndex, z);
-                fromIndex += z;
-
-                writeValue(x, positiveValue, fromIndex, p);
-                fromIndex += p;
-
-                writeValue(x, Double.NaN, fromIndex, a);
-            }
-        };
-
-        abstract void build(double[] x, int a, int g, int z, int n, int p, Random random);
-    }
-
-    private static void writeValue(float[] a, float value, int fromIndex, int count) {
-        for (int i = fromIndex; i < fromIndex + count; i++) {
-            a[i] = value;
-        }
-    }
-
-    private static void compare(float[] a, float[] b, int numNaN, int numNeg, int numNegZero) {
-        for (int i = a.length - numNaN; i < a.length; i++) {
-            if (a[i] == a[i]) {
-                failed("On position " + i + " must be NaN instead of " + a[i]);
-            }
-        }
-        final int NEGATIVE_ZERO = Float.floatToIntBits(-0.0f);
-
-        for (int i = numNeg; i < numNeg + numNegZero; i++) {
-            if (NEGATIVE_ZERO != Float.floatToIntBits(a[i])) {
-                failed("On position " + i + " must be -0.0 instead of " + a[i]);
-            }
-        }
-        for (int i = 0; i < a.length - numNaN; i++) {
-            if (a[i] != b[i]) {
-                failedCompare(i, "" + a[i], "" + b[i]);
-            }
-        }
-    }
-
-    private static void writeValue(double[] a, double value, int fromIndex, int count) {
-        for (int i = fromIndex; i < fromIndex + count; i++) {
-            a[i] = value;
-        }
-    }
-
-    private static void compare(double[] a, double[] b, int numNaN, int numNeg, int numNegZero) {
-        for (int i = a.length - numNaN; i < a.length; i++) {
-            if (a[i] == a[i]) {
-                failed("On position " + i + " must be NaN instead of " + a[i]);
-            }
-        }
-        final long NEGATIVE_ZERO = Double.doubleToLongBits(-0.0d);
-
-        for (int i = numNeg; i < numNeg + numNegZero; i++) {
-            if (NEGATIVE_ZERO != Double.doubleToLongBits(a[i])) {
-                failed("On position " + i + " must be -0.0 instead of " + a[i]);
-            }
-        }
-        for (int i = 0; i < a.length - numNaN; i++) {
-            if (a[i] != b[i]) {
-                failedCompare(i, "" + a[i], "" + b[i]);
-            }
-        }
-    }
-
-    private static enum SortedBuilder {
-        REPEATED {
-            void build(int[] a, int m) {
-                int period = a.length / m;
-                int i = 0;
-                int k = 0;
-
-                while (true) {
-                    for (int t = 1; t <= period; t++) {
-                        if (i >= a.length) {
-                            return;
-                        }
-                        a[i++] = k;
-                    }
-                    if (i >= a.length) {
-                        return;
-                    }
-                    k++;
-                }
-            }
-        },
-        ORGAN_PIPES {
-            void build(int[] a, int m) {
-                int i = 0;
-                int k = m;
-
-                while (true) {
-                    for (int t = 1; t <= m; t++) {
-                        if (i >= a.length) {
-                            return;
-                        }
-                        a[i++] = k;
-                    }
-                }
-            }
-        };
-
-        abstract void build(int[] a, int m);
-
-        @Override public String toString() {
-            String name = name();
-
-            for (int i = name.length(); i < 12; i++) {
-                name += " ";
-            }
-            return name;
-        }
-    }
-
-    private static enum MergeBuilder {
-        ASCENDING {
-            void build(int[] a, int m) {
-                int period = a.length / m;
-                int v = 1, i = 0;
-
-                for (int k = 0; k < m; k++) {
-                    v = 1;
-                    for (int p = 0; p < period; p++) {
-                        a[i++] = v++;
-                    }
-                }
-                for (int j = i; j < a.length - 1; j++) {
-                    a[j] = v++;
-                }
-                a[a.length - 1] = 0;
-            }
-        },
-        DESCENDING {
-            void build(int[] a, int m) {
-                int period = a.length / m;
-                int v = -1, i = 0;
-
-                for (int k = 0; k < m; k++) {
-                    v = -1;
-                    for (int p = 0; p < period; p++) {
-                        a[i++] = v--;
-                    }
-                }
-                for (int j = i; j < a.length - 1; j++) {
-                    a[j] = v--;
-                }
-                a[a.length - 1] = 0;
-            }
-        };
-
-        abstract void build(int[] a, int m);
-
-        @Override public String toString() {
-            String name = name();
-
-            for (int i = name.length(); i < 12; i++) {
-                name += " ";
-            }
-            return name;
-        }
-    }
-
-    private static enum UnsortedBuilder {
-        RANDOM {
-            void build(int[] a, int m, Random random) {
-                for (int i = 0; i < a.length; i++) {
-                    a[i] = random.nextInt();
-                }
-            }
-        },
-        ASCENDING {
-            void build(int[] a, int m, Random random) {
-                for (int i = 0; i < a.length; i++) {
-                    a[i] = m + i;
-                }
-            }
-        },
-        DESCENDING {
-            void build(int[] a, int m, Random random) {
-                for (int i = 0; i < a.length; i++) {
-                    a[i] = a.length - m - i;
-                }
-            }
-        },
-        ALL_EQUAL {
-            void build(int[] a, int m, Random random) {
-                for (int i = 0; i < a.length; i++) {
-                    a[i] = m;
-                }
-            }
-        },
-        SAW {
-            void build(int[] a, int m, Random random) {
-                int incCount = 1;
-                int decCount = a.length;
-                int i = 0;
-                int period = m--;
-
-                while (true) {
-                    for (int k = 1; k <= period; k++) {
-                        if (i >= a.length) {
-                            return;
-                        }
-                        a[i++] = incCount++;
-                    }
-                    period += m;
-
-                    for (int k = 1; k <= period; k++) {
-                        if (i >= a.length) {
-                            return;
-                        }
-                        a[i++] = decCount--;
-                    }
-                    period += m;
-                }
-            }
-        },
-        REPEATED {
-            void build(int[] a, int m, Random random) {
-                for (int i = 0; i < a.length; i++) {
-                    a[i] = i % m;
-                }
-            }
-        },
-        DUPLICATED {
-            void build(int[] a, int m, Random random) {
-                for (int i = 0; i < a.length; i++) {
-                    a[i] = random.nextInt(m);
-                }
-            }
-        },
-        ORGAN_PIPES {
-            void build(int[] a, int m, Random random) {
-                int middle = a.length / (m + 1);
-
-                for (int i = 0; i < middle; i++) {
-                    a[i] = i;
-                }
-                for (int i = middle; i < a.length; i++) {
-                    a[i] = a.length - i - 1;
-                }
-            }
-        },
-        STAGGER {
-            void build(int[] a, int m, Random random) {
-                for (int i = 0; i < a.length; i++) {
-                    a[i] = (i * m + i) % a.length;
-                }
-            }
-        },
-        PLATEAU {
-            void build(int[] a, int m, Random random) {
-                for (int i = 0; i < a.length; i++) {
-                    a[i] = Math.min(i, m);
-                }
-            }
-        },
-        SHUFFLE {
-            void build(int[] a, int m, Random random) {
-                int x = 0, y = 0;
-                for (int i = 0; i < a.length; i++) {
-                    a[i] = random.nextBoolean() ? (x += 2) : (y += 2);
-                }
-            }
-        };
-
-        abstract void build(int[] a, int m, Random random);
-
-        @Override public String toString() {
-            String name = name();
-
-            for (int i = name.length(); i < 12; i++) {
-                name += " ";
-            }
-            return name;
-        }
-    }
-
-    private static void checkWithCheckSum(Object test, Object golden) {
-        checkSorted(test);
-        checkCheckSum(test, golden);
-    }
-
-    private static void failed(String message) {
-        err.format("\n*** TEST FAILED - %s.\n\n%s.\n\n", ourDescription, message);
-        throw new RuntimeException("Test failed - see log file for details");
-    }
-
-    private static void failedSort(int index, String value1, String value2) {
-        failed("Array is not sorted at " + index + "-th position: " +
-            value1 + " and " + value2);
-    }
-
-    private static void failedCompare(int index, String value1, String value2) {
-        failed("On position " + index + " must be " + value2 + " instead of " + value1);
-    }
-
-    private static void compare(Object test, Object golden) {
-        if (test instanceof int[]) {
-            compare((int[]) test, (int[]) golden);
-        } else if (test instanceof long[]) {
-            compare((long[]) test, (long[]) golden);
-        } else if (test instanceof short[]) {
-            compare((short[]) test, (short[]) golden);
-        } else if (test instanceof byte[]) {
-            compare((byte[]) test, (byte[]) golden);
-        } else if (test instanceof char[]) {
-            compare((char[]) test, (char[]) golden);
-        } else if (test instanceof float[]) {
-            compare((float[]) test, (float[]) golden);
-        } else if (test instanceof double[]) {
-            compare((double[]) test, (double[]) golden);
-        } else if (test instanceof Integer[]) {
-            compare((Integer[]) test, (Integer[]) golden);
-        } else {
-            failed("Unknow type of array: " + test + " of class " +
-                test.getClass().getName());
-        }
-    }
-
-    private static void compare(int[] a, int[] b) {
-        for (int i = 0; i < a.length; i++) {
-            if (a[i] != b[i]) {
-                failedCompare(i, "" + a[i], "" + b[i]);
-            }
-        }
-    }
-
-    private static void compare(long[] a, long[] b) {
-        for (int i = 0; i < a.length; i++) {
-            if (a[i] != b[i]) {
-                failedCompare(i, "" + a[i], "" + b[i]);
-            }
-        }
-    }
-
-    private static void compare(short[] a, short[] b) {
-        for (int i = 0; i < a.length; i++) {
-            if (a[i] != b[i]) {
-                failedCompare(i, "" + a[i], "" + b[i]);
-            }
-        }
-    }
-
-    private static void compare(byte[] a, byte[] b) {
-        for (int i = 0; i < a.length; i++) {
-            if (a[i] != b[i]) {
-                failedCompare(i, "" + a[i], "" + b[i]);
-            }
-        }
-    }
-
-    private static void compare(char[] a, char[] b) {
-        for (int i = 0; i < a.length; i++) {
-            if (a[i] != b[i]) {
-                failedCompare(i, "" + a[i], "" + b[i]);
-            }
-        }
-    }
-
-    private static void compare(float[] a, float[] b) {
-        for (int i = 0; i < a.length; i++) {
-            if (a[i] != b[i]) {
-                failedCompare(i, "" + a[i], "" + b[i]);
-            }
-        }
-    }
-
-    private static void compare(double[] a, double[] b) {
-        for (int i = 0; i < a.length; i++) {
-            if (a[i] != b[i]) {
-                failedCompare(i, "" + a[i], "" + b[i]);
-            }
-        }
-    }
-
-    private static void compare(Integer[] a, Integer[] b) {
-        for (int i = 0; i < a.length; i++) {
-            if (a[i].compareTo(b[i]) != 0) {
-                failedCompare(i, "" + a[i], "" + b[i]);
-            }
-        }
-    }
-
-    private static void checkSorted(Object object) {
-        if (object instanceof int[]) {
-            checkSorted((int[]) object);
-        } else if (object instanceof long[]) {
-            checkSorted((long[]) object);
-        } else if (object instanceof short[]) {
-            checkSorted((short[]) object);
-        } else if (object instanceof byte[]) {
-            checkSorted((byte[]) object);
-        } else if (object instanceof char[]) {
-            checkSorted((char[]) object);
-        } else if (object instanceof float[]) {
-            checkSorted((float[]) object);
-        } else if (object instanceof double[]) {
-            checkSorted((double[]) object);
-        } else if (object instanceof Integer[]) {
-            checkSorted((Integer[]) object);
-        } else {
-            failed("Unknow type of array: " + object + " of class " +
-                object.getClass().getName());
-        }
-    }
-
-    private static void checkSorted(int[] a) {
-        for (int i = 0; i < a.length - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
-            }
-        }
-    }
-
-    private static void checkSorted(long[] a) {
-        for (int i = 0; i < a.length - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
-            }
-        }
-    }
-
-    private static void checkSorted(short[] a) {
-        for (int i = 0; i < a.length - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
-            }
-        }
-    }
-
-    private static void checkSorted(byte[] a) {
-        for (int i = 0; i < a.length - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
-            }
-        }
-    }
-
-    private static void checkSorted(char[] a) {
-        for (int i = 0; i < a.length - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
-            }
-        }
-    }
-
-    private static void checkSorted(float[] a) {
-        for (int i = 0; i < a.length - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
-            }
-        }
-    }
-
-    private static void checkSorted(double[] a) {
-        for (int i = 0; i < a.length - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
-            }
-        }
-    }
-
-    private static void checkSorted(Integer[] a) {
-        for (int i = 0; i < a.length - 1; i++) {
-            if (a[i].intValue() > a[i + 1].intValue()) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
-            }
-        }
-    }
-
-    private static void checkCheckSum(Object test, Object golden) {
-        if (checkSumXor(test) != checkSumXor(golden)) {
-            failed("Original and sorted arrays are not identical [xor]");
-        }
-        if (checkSumPlus(test) != checkSumPlus(golden)) {
-            failed("Original and sorted arrays are not identical [plus]");
-        }
-    }
-
-    private static int checkSumXor(Object object) {
-        if (object instanceof int[]) {
-            return checkSumXor((int[]) object);
-        } else if (object instanceof long[]) {
-            return checkSumXor((long[]) object);
-        } else if (object instanceof short[]) {
-            return checkSumXor((short[]) object);
-        } else if (object instanceof byte[]) {
-            return checkSumXor((byte[]) object);
-        } else if (object instanceof char[]) {
-            return checkSumXor((char[]) object);
-        } else if (object instanceof float[]) {
-            return checkSumXor((float[]) object);
-        } else if (object instanceof double[]) {
-            return checkSumXor((double[]) object);
-        } else if (object instanceof Integer[]) {
-            return checkSumXor((Integer[]) object);
-        } else {
-            failed("Unknow type of array: " + object + " of class " +
-                object.getClass().getName());
-            return -1;
-        }
-    }
-
-    private static int checkSumXor(Integer[] a) {
-        int checkSum = 0;
-
-        for (Integer e : a) {
-            checkSum ^= e.intValue();
-        }
-        return checkSum;
-    }
-
-    private static int checkSumXor(int[] a) {
-        int checkSum = 0;
-
-        for (int e : a) {
-            checkSum ^= e;
-        }
-        return checkSum;
-    }
-
-    private static int checkSumXor(long[] a) {
-        long checkSum = 0;
-
-        for (long e : a) {
-            checkSum ^= e;
-        }
-        return (int) checkSum;
-    }
-
-    private static int checkSumXor(short[] a) {
-        short checkSum = 0;
-
-        for (short e : a) {
-            checkSum ^= e;
-        }
-        return (int) checkSum;
-    }
-
-    private static int checkSumXor(byte[] a) {
-        byte checkSum = 0;
-
-        for (byte e : a) {
-            checkSum ^= e;
-        }
-        return (int) checkSum;
-    }
-
-    private static int checkSumXor(char[] a) {
-        char checkSum = 0;
-
-        for (char e : a) {
-            checkSum ^= e;
-        }
-        return (int) checkSum;
-    }
-
-    private static int checkSumXor(float[] a) {
-        int checkSum = 0;
-
-        for (float e : a) {
-            checkSum ^= (int) e;
-        }
-        return checkSum;
-    }
-
-    private static int checkSumXor(double[] a) {
-        int checkSum = 0;
-
-        for (double e : a) {
-            checkSum ^= (int) e;
-        }
-        return checkSum;
-    }
-
-    private static int checkSumPlus(Object object) {
-        if (object instanceof int[]) {
-            return checkSumPlus((int[]) object);
-        } else if (object instanceof long[]) {
-            return checkSumPlus((long[]) object);
-        } else if (object instanceof short[]) {
-            return checkSumPlus((short[]) object);
-        } else if (object instanceof byte[]) {
-            return checkSumPlus((byte[]) object);
-        } else if (object instanceof char[]) {
-            return checkSumPlus((char[]) object);
-        } else if (object instanceof float[]) {
-            return checkSumPlus((float[]) object);
-        } else if (object instanceof double[]) {
-            return checkSumPlus((double[]) object);
-        } else if (object instanceof Integer[]) {
-            return checkSumPlus((Integer[]) object);
-        } else {
-            failed("Unknow type of array: " + object + " of class " +
-                object.getClass().getName());
-            return -1;
-        }
-    }
-
-    private static int checkSumPlus(int[] a) {
-        int checkSum = 0;
-
-        for (int e : a) {
-            checkSum += e;
-        }
-        return checkSum;
-    }
-
-    private static int checkSumPlus(long[] a) {
-        long checkSum = 0;
-
-        for (long e : a) {
-            checkSum += e;
-        }
-        return (int) checkSum;
-    }
-
-    private static int checkSumPlus(short[] a) {
-        short checkSum = 0;
-
-        for (short e : a) {
-            checkSum += e;
-        }
-        return (int) checkSum;
-    }
-
-    private static int checkSumPlus(byte[] a) {
-        byte checkSum = 0;
-
-        for (byte e : a) {
-            checkSum += e;
-        }
-        return (int) checkSum;
-    }
-
-    private static int checkSumPlus(char[] a) {
-        char checkSum = 0;
-
-        for (char e : a) {
-            checkSum += e;
-        }
-        return (int) checkSum;
-    }
-
-    private static int checkSumPlus(float[] a) {
-        int checkSum = 0;
-
-        for (float e : a) {
-            checkSum += (int) e;
-        }
-        return checkSum;
-    }
-
-    private static int checkSumPlus(double[] a) {
-        int checkSum = 0;
-
-        for (double e : a) {
-            checkSum += (int) e;
-        }
-        return checkSum;
-    }
-
-    private static int checkSumPlus(Integer[] a) {
-        int checkSum = 0;
-
-        for (Integer e : a) {
-            checkSum += e.intValue();
-        }
-        return checkSum;
-    }
-
-    private static void sortByInsertionSort(Object object) {
-        if (object instanceof int[]) {
-            sortByInsertionSort((int[]) object);
-        } else if (object instanceof long[]) {
-            sortByInsertionSort((long[]) object);
-        } else if (object instanceof short[]) {
-            sortByInsertionSort((short[]) object);
-        } else if (object instanceof byte[]) {
-            sortByInsertionSort((byte[]) object);
-        } else if (object instanceof char[]) {
-            sortByInsertionSort((char[]) object);
-        } else if (object instanceof float[]) {
-            sortByInsertionSort((float[]) object);
-        } else if (object instanceof double[]) {
-            sortByInsertionSort((double[]) object);
-        } else if (object instanceof Integer[]) {
-            sortByInsertionSort((Integer[]) object);
-        } else {
-            failed("Unknow type of array: " + object + " of class " +
-                object.getClass().getName());
-        }
-    }
-
-    private static void sortByInsertionSort(int[] a) {
-        for (int j, i = 1; i < a.length; i++) {
-            int ai = a[i];
-            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
-                a[j + 1] = a[j];
-            }
-            a[j + 1] = ai;
-        }
-    }
-
-    private static void sortByInsertionSort(long[] a) {
-        for (int j, i = 1; i < a.length; i++) {
-            long ai = a[i];
-            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
-                a[j + 1] = a[j];
-            }
-            a[j + 1] = ai;
-        }
-    }
-
-    private static void sortByInsertionSort(short[] a) {
-        for (int j, i = 1; i < a.length; i++) {
-            short ai = a[i];
-            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
-                a[j + 1] = a[j];
-            }
-            a[j + 1] = ai;
-        }
-    }
-
-    private static void sortByInsertionSort(byte[] a) {
-        for (int j, i = 1; i < a.length; i++) {
-            byte ai = a[i];
-            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
-                a[j + 1] = a[j];
-            }
-            a[j + 1] = ai;
-        }
-    }
-
-    private static void sortByInsertionSort(char[] a) {
-        for (int j, i = 1; i < a.length; i++) {
-            char ai = a[i];
-            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
-                a[j + 1] = a[j];
-            }
-            a[j + 1] = ai;
-        }
-    }
-
-    private static void sortByInsertionSort(float[] a) {
-        for (int j, i = 1; i < a.length; i++) {
-            float ai = a[i];
-            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
-                a[j + 1] = a[j];
-            }
-            a[j + 1] = ai;
-        }
-    }
-
-    private static void sortByInsertionSort(double[] a) {
-        for (int j, i = 1; i < a.length; i++) {
-            double ai = a[i];
-            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
-                a[j + 1] = a[j];
-            }
-            a[j + 1] = ai;
-        }
-    }
-
-    private static void sortByInsertionSort(Integer[] a) {
-        for (int j, i = 1; i < a.length; i++) {
-            Integer ai = a[i];
-            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
-                a[j + 1] = a[j];
-            }
-            a[j + 1] = ai;
-        }
-    }
-
-    private static void sort(Object object) {
-        if (object instanceof int[]) {
-            Arrays.parallelSort((int[]) object);
-        } else if (object instanceof long[]) {
-            Arrays.parallelSort((long[]) object);
-        } else if (object instanceof short[]) {
-            Arrays.parallelSort((short[]) object);
-        } else if (object instanceof byte[]) {
-            Arrays.parallelSort((byte[]) object);
-        } else if (object instanceof char[]) {
-            Arrays.parallelSort((char[]) object);
-        } else if (object instanceof float[]) {
-            Arrays.parallelSort((float[]) object);
-        } else if (object instanceof double[]) {
-            Arrays.parallelSort((double[]) object);
-        } else if (object instanceof Integer[]) {
-            Arrays.parallelSort((Integer[]) object);
-        } else {
-            failed("Unknow type of array: " + object + " of class " +
-                object.getClass().getName());
-        }
-    }
-
-    private static void sortSubArray(Object object, int fromIndex, int toIndex) {
-        if (object instanceof int[]) {
-            Arrays.parallelSort((int[]) object, fromIndex, toIndex);
-        } else if (object instanceof long[]) {
-            Arrays.parallelSort((long[]) object, fromIndex, toIndex);
-        } else if (object instanceof short[]) {
-            Arrays.parallelSort((short[]) object, fromIndex, toIndex);
-        } else if (object instanceof byte[]) {
-            Arrays.parallelSort((byte[]) object, fromIndex, toIndex);
-        } else if (object instanceof char[]) {
-            Arrays.parallelSort((char[]) object, fromIndex, toIndex);
-        } else if (object instanceof float[]) {
-            Arrays.parallelSort((float[]) object, fromIndex, toIndex);
-        } else if (object instanceof double[]) {
-            Arrays.parallelSort((double[]) object, fromIndex, toIndex);
-        } else if (object instanceof Integer[]) {
-            Arrays.parallelSort((Integer[]) object, fromIndex, toIndex);
-        } else {
-            failed("Unknow type of array: " + object + " of class " +
-                object.getClass().getName());
-        }
-    }
-
-    private static void checkSubArray(Object object, int fromIndex, int toIndex, int m) {
-        if (object instanceof int[]) {
-            checkSubArray((int[]) object, fromIndex, toIndex, m);
-        } else if (object instanceof long[]) {
-            checkSubArray((long[]) object, fromIndex, toIndex, m);
-        } else if (object instanceof short[]) {
-            checkSubArray((short[]) object, fromIndex, toIndex, m);
-        } else if (object instanceof byte[]) {
-            checkSubArray((byte[]) object, fromIndex, toIndex, m);
-        } else if (object instanceof char[]) {
-            checkSubArray((char[]) object, fromIndex, toIndex, m);
-        } else if (object instanceof float[]) {
-            checkSubArray((float[]) object, fromIndex, toIndex, m);
-        } else if (object instanceof double[]) {
-            checkSubArray((double[]) object, fromIndex, toIndex, m);
-        } else if (object instanceof Integer[]) {
-            checkSubArray((Integer[]) object, fromIndex, toIndex, m);
-        } else {
-            failed("Unknow type of array: " + object + " of class " +
-                object.getClass().getName());
-        }
-    }
-
-    private static void checkSubArray(Integer[] a, int fromIndex, int toIndex, int m) {
-        for (int i = 0; i < fromIndex; i++) {
-            if (a[i].intValue() != 0xDEDA) {
-                failed("Range sort changes left element on position " + i +
-                    ": " + a[i] + ", must be " + 0xDEDA);
-            }
-        }
-
-        for (int i = fromIndex; i < toIndex - 1; i++) {
-            if (a[i].intValue() > a[i + 1].intValue()) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
-            }
-        }
-
-        for (int i = toIndex; i < a.length; i++) {
-            if (a[i].intValue() != 0xBABA) {
-                failed("Range sort changes right element on position " + i +
-                    ": " + a[i] + ", must be " + 0xBABA);
-            }
-        }
-    }
-
-    private static void checkSubArray(int[] a, int fromIndex, int toIndex, int m) {
-        for (int i = 0; i < fromIndex; i++) {
-            if (a[i] != 0xDEDA) {
-                failed("Range sort changes left element on position " + i +
-                    ": " + a[i] + ", must be " + 0xDEDA);
-            }
-        }
-
-        for (int i = fromIndex; i < toIndex - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
-            }
-        }
-
-        for (int i = toIndex; i < a.length; i++) {
-            if (a[i] != 0xBABA) {
-                failed("Range sort changes right element on position " + i +
-                    ": " + a[i] + ", must be " + 0xBABA);
-            }
-        }
-    }
-
-    private static void checkSubArray(byte[] a, int fromIndex, int toIndex, int m) {
-        for (int i = 0; i < fromIndex; i++) {
-            if (a[i] != (byte) 0xDEDA) {
-                failed("Range sort changes left element on position " + i +
-                    ": " + a[i] + ", must be " + 0xDEDA);
-            }
-        }
-
-        for (int i = fromIndex; i < toIndex - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
-            }
-        }
-
-        for (int i = toIndex; i < a.length; i++) {
-            if (a[i] != (byte) 0xBABA) {
-                failed("Range sort changes right element on position " + i +
-                    ": " + a[i] + ", must be " + 0xBABA);
-            }
-        }
-    }
-
-    private static void checkSubArray(long[] a, int fromIndex, int toIndex, int m) {
-        for (int i = 0; i < fromIndex; i++) {
-            if (a[i] != (long) 0xDEDA) {
-                failed("Range sort changes left element on position " + i +
-                    ": " + a[i] + ", must be " + 0xDEDA);
-            }
-        }
-
-        for (int i = fromIndex; i < toIndex - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
-            }
-        }
-
-        for (int i = toIndex; i < a.length; i++) {
-            if (a[i] != (long) 0xBABA) {
-                failed("Range sort changes right element on position " + i +
-                    ": " + a[i] + ", must be " + 0xBABA);
-            }
-        }
-    }
-
-    private static void checkSubArray(char[] a, int fromIndex, int toIndex, int m) {
-        for (int i = 0; i < fromIndex; i++) {
-            if (a[i] != (char) 0xDEDA) {
-                failed("Range sort changes left element on position " + i +
-                    ": " + a[i] + ", must be " + 0xDEDA);
-            }
-        }
-
-        for (int i = fromIndex; i < toIndex - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
-            }
-        }
-
-        for (int i = toIndex; i < a.length; i++) {
-            if (a[i] != (char) 0xBABA) {
-                failed("Range sort changes right element on position " + i +
-                    ": " + a[i] + ", must be " + 0xBABA);
-            }
-        }
-    }
-
-    private static void checkSubArray(short[] a, int fromIndex, int toIndex, int m) {
-        for (int i = 0; i < fromIndex; i++) {
-            if (a[i] != (short) 0xDEDA) {
-                failed("Range sort changes left element on position " + i +
-                    ": " + a[i] + ", must be " + 0xDEDA);
-            }
-        }
-
-        for (int i = fromIndex; i < toIndex - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
-            }
-        }
-
-        for (int i = toIndex; i < a.length; i++) {
-            if (a[i] != (short) 0xBABA) {
-                failed("Range sort changes right element on position " + i +
-                    ": " + a[i] + ", must be " + 0xBABA);
-            }
-        }
-    }
-
-    private static void checkSubArray(float[] a, int fromIndex, int toIndex, int m) {
-        for (int i = 0; i < fromIndex; i++) {
-            if (a[i] != (float) 0xDEDA) {
-                failed("Range sort changes left element on position " + i +
-                    ": " + a[i] + ", must be " + 0xDEDA);
-            }
-        }
-
-        for (int i = fromIndex; i < toIndex - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
-            }
-        }
-
-        for (int i = toIndex; i < a.length; i++) {
-            if (a[i] != (float) 0xBABA) {
-                failed("Range sort changes right element on position " + i +
-                    ": " + a[i] + ", must be " + 0xBABA);
-            }
-        }
-    }
-
-    private static void checkSubArray(double[] a, int fromIndex, int toIndex, int m) {
-        for (int i = 0; i < fromIndex; i++) {
-            if (a[i] != (double) 0xDEDA) {
-                failed("Range sort changes left element on position " + i +
-                    ": " + a[i] + ", must be " + 0xDEDA);
-            }
-        }
-
-        for (int i = fromIndex; i < toIndex - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
-            }
-        }
-
-        for (int i = toIndex; i < a.length; i++) {
-            if (a[i] != (double) 0xBABA) {
-                failed("Range sort changes right element on position " + i +
-                    ": " + a[i] + ", must be " + 0xBABA);
-            }
-        }
-    }
-
-    private static void checkRange(Object object, int m) {
-        if (object instanceof int[]) {
-            checkRange((int[]) object, m);
-        } else if (object instanceof long[]) {
-            checkRange((long[]) object, m);
-        } else if (object instanceof short[]) {
-            checkRange((short[]) object, m);
-        } else if (object instanceof byte[]) {
-            checkRange((byte[]) object, m);
-        } else if (object instanceof char[]) {
-            checkRange((char[]) object, m);
-        } else if (object instanceof float[]) {
-            checkRange((float[]) object, m);
-        } else if (object instanceof double[]) {
-            checkRange((double[]) object, m);
-        } else if (object instanceof Integer[]) {
-            checkRange((Integer[]) object, m);
-        } else {
-            failed("Unknow type of array: " + object + " of class " +
-                object.getClass().getName());
-        }
-    }
-
-    private static void checkRange(Integer[] a, int m) {
-        try {
-            Arrays.parallelSort(a, m + 1, m);
-
-            failed("ParallelSort does not throw IllegalArgumentException " +
-                " as expected: fromIndex = " + (m + 1) +
-                " toIndex = " + m);
-        }
-        catch (IllegalArgumentException iae) {
-            try {
-                Arrays.parallelSort(a, -m, a.length);
-
-                failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
-                    " as expected: fromIndex = " + (-m));
-            }
-            catch (ArrayIndexOutOfBoundsException aoe) {
-                try {
-                    Arrays.parallelSort(a, 0, a.length + m);
-
-                    failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
-                        " as expected: toIndex = " + (a.length + m));
-                }
-                catch (ArrayIndexOutOfBoundsException aie) {
-                    return;
-                }
-            }
-        }
-    }
-
-    private static void checkRange(int[] a, int m) {
-        try {
-            Arrays.parallelSort(a, m + 1, m);
-
-            failed("ParallelSort does not throw IllegalArgumentException " +
-                " as expected: fromIndex = " + (m + 1) +
-                " toIndex = " + m);
-        }
-        catch (IllegalArgumentException iae) {
-            try {
-                Arrays.parallelSort(a, -m, a.length);
-
-                failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
-                    " as expected: fromIndex = " + (-m));
-            }
-            catch (ArrayIndexOutOfBoundsException aoe) {
-                try {
-                    Arrays.parallelSort(a, 0, a.length + m);
-
-                    failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
-                        " as expected: toIndex = " + (a.length + m));
-                }
-                catch (ArrayIndexOutOfBoundsException aie) {
-                    return;
-                }
-            }
-        }
-    }
-
-    private static void checkRange(long[] a, int m) {
-        try {
-            Arrays.parallelSort(a, m + 1, m);
-
-            failed("ParallelSort does not throw IllegalArgumentException " +
-                " as expected: fromIndex = " + (m + 1) +
-                " toIndex = " + m);
-        }
-        catch (IllegalArgumentException iae) {
-            try {
-                Arrays.parallelSort(a, -m, a.length);
-
-                failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
-                    " as expected: fromIndex = " + (-m));
-            }
-            catch (ArrayIndexOutOfBoundsException aoe) {
-                try {
-                    Arrays.parallelSort(a, 0, a.length + m);
-
-                    failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
-                        " as expected: toIndex = " + (a.length + m));
-                }
-                catch (ArrayIndexOutOfBoundsException aie) {
-                    return;
-                }
-            }
-        }
-    }
-
-    private static void checkRange(byte[] a, int m) {
-        try {
-            Arrays.parallelSort(a, m + 1, m);
-
-            failed("ParallelSort does not throw IllegalArgumentException " +
-                " as expected: fromIndex = " + (m + 1) +
-                " toIndex = " + m);
-        }
-        catch (IllegalArgumentException iae) {
-            try {
-                Arrays.parallelSort(a, -m, a.length);
-
-                failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
-                    " as expected: fromIndex = " + (-m));
-            }
-            catch (ArrayIndexOutOfBoundsException aoe) {
-                try {
-                    Arrays.parallelSort(a, 0, a.length + m);
-
-                    failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
-                        " as expected: toIndex = " + (a.length + m));
-                }
-                catch (ArrayIndexOutOfBoundsException aie) {
-                    return;
-                }
-            }
-        }
-    }
-
-    private static void checkRange(short[] a, int m) {
-        try {
-            Arrays.parallelSort(a, m + 1, m);
-
-            failed("ParallelSort does not throw IllegalArgumentException " +
-                " as expected: fromIndex = " + (m + 1) +
-                " toIndex = " + m);
-        }
-        catch (IllegalArgumentException iae) {
-            try {
-                Arrays.parallelSort(a, -m, a.length);
-
-                failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
-                    " as expected: fromIndex = " + (-m));
-            }
-            catch (ArrayIndexOutOfBoundsException aoe) {
-                try {
-                    Arrays.parallelSort(a, 0, a.length + m);
-
-                    failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
-                        " as expected: toIndex = " + (a.length + m));
-                }
-                catch (ArrayIndexOutOfBoundsException aie) {
-                    return;
-                }
-            }
-        }
-    }
-
-    private static void checkRange(char[] a, int m) {
-        try {
-            Arrays.parallelSort(a, m + 1, m);
-
-            failed("ParallelSort does not throw IllegalArgumentException " +
-                " as expected: fromIndex = " + (m + 1) +
-                " toIndex = " + m);
-        }
-        catch (IllegalArgumentException iae) {
-            try {
-                Arrays.parallelSort(a, -m, a.length);
-
-                failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
-                    " as expected: fromIndex = " + (-m));
-            }
-            catch (ArrayIndexOutOfBoundsException aoe) {
-                try {
-                    Arrays.parallelSort(a, 0, a.length + m);
-
-                    failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
-                        " as expected: toIndex = " + (a.length + m));
-                }
-                catch (ArrayIndexOutOfBoundsException aie) {
-                    return;
-                }
-            }
-        }
-    }
-
-    private static void checkRange(float[] a, int m) {
-        try {
-            Arrays.parallelSort(a, m + 1, m);
-
-            failed("ParallelSort does not throw IllegalArgumentException " +
-                " as expected: fromIndex = " + (m + 1) +
-                " toIndex = " + m);
-        }
-        catch (IllegalArgumentException iae) {
-            try {
-                Arrays.parallelSort(a, -m, a.length);
-
-                failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
-                    " as expected: fromIndex = " + (-m));
-            }
-            catch (ArrayIndexOutOfBoundsException aoe) {
-                try {
-                    Arrays.parallelSort(a, 0, a.length + m);
-
-                    failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
-                        " as expected: toIndex = " + (a.length + m));
-                }
-                catch (ArrayIndexOutOfBoundsException aie) {
-                    return;
-                }
-            }
-        }
-    }
-
-    private static void checkRange(double[] a, int m) {
-        try {
-            Arrays.parallelSort(a, m + 1, m);
-
-            failed("ParallelSort does not throw IllegalArgumentException " +
-                " as expected: fromIndex = " + (m + 1) +
-                " toIndex = " + m);
-        }
-        catch (IllegalArgumentException iae) {
-            try {
-                Arrays.parallelSort(a, -m, a.length);
-
-                failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
-                    " as expected: fromIndex = " + (-m));
-            }
-            catch (ArrayIndexOutOfBoundsException aoe) {
-                try {
-                    Arrays.parallelSort(a, 0, a.length + m);
-
-                    failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
-                        " as expected: toIndex = " + (a.length + m));
-                }
-                catch (ArrayIndexOutOfBoundsException aie) {
-                    return;
-                }
-            }
-        }
-    }
-
-    private static void outArray(Object[] a) {
-        for (int i = 0; i < a.length; i++) {
-            out.print(a[i] + " ");
-        }
-        out.println();
-    }
-
-    private static void outArray(int[] a) {
-        for (int i = 0; i < a.length; i++) {
-            out.print(a[i] + " ");
-        }
-        out.println();
-    }
-
-    private static void outArray(float[] a) {
-        for (int i = 0; i < a.length; i++) {
-            out.print(a[i] + " ");
-        }
-        out.println();
-    }
-
-    private static void outArray(double[] a) {
-        for (int i = 0; i < a.length; i++) {
-            out.print(a[i] + " ");
-        }
-        out.println();
-    }
-
-    private static class MyRandom extends Random {
-        MyRandom(long seed) {
-            super(seed);
-            mySeed = seed;
-        }
-
-        long getSeed() {
-            return mySeed;
-        }
-
-        private long mySeed;
-    }
-
-    private static String ourDescription;
-}
--- a/test/jdk/java/util/Arrays/Sorting.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/jdk/java/util/Arrays/Sorting.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,277 +23,329 @@
 
 /*
  * @test
- * @bug 6880672 6896573 6899694 6976036 7013585 7018258
- * @summary Exercise Arrays.sort
+ * @compile/module=java.base java/util/SortingHelper.java
+ * @bug 6880672 6896573 6899694 6976036 7013585 7018258 8003981 8226297
  * @build Sorting
  * @run main Sorting -shortrun
+ * @summary Exercise Arrays.sort, Arrays.parallelSort
  *
  * @author Vladimir Yaroslavskiy
  * @author Jon Bentley
  * @author Josh Bloch
  */
 
-import java.util.Arrays;
+import java.io.PrintStream;
+import java.util.Comparator;
 import java.util.Random;
-import java.io.PrintStream;
+import java.util.SortingHelper;
 
 public class Sorting {
+
     private static final PrintStream out = System.out;
     private static final PrintStream err = System.err;
 
     // Array lengths used in a long run (default)
     private static final int[] LONG_RUN_LENGTHS = {
-        1, 2, 3, 5, 8, 13, 21, 34, 55, 100, 1000, 10000, 100000, 1000000 };
+        1, 3, 8, 21, 55, 100, 1_000, 10_000, 100_000 };
 
     // Array lengths used in a short run
     private static final int[] SHORT_RUN_LENGTHS = {
-        1, 2, 3, 21, 55, 1000, 10000 };
+        1, 8, 55, 100, 10_000 };
 
     // Random initial values used in a long run (default)
-    private static final long[] LONG_RUN_RANDOMS = { 666, 0xC0FFEE, 999 };
+    private static final TestRandom[] LONG_RUN_RANDOMS = {
+        TestRandom.BABA, TestRandom.DEDA, TestRandom.C0FFEE };
 
     // Random initial values used in a short run
-    private static final long[] SHORT_RUN_RANDOMS = { 666 };
+    private static final TestRandom[] SHORT_RUN_RANDOMS = {
+        TestRandom.C0FFEE };
+
+    // Constants used in subarray sorting
+    private static final int A380 = 0xA380;
+    private static final int B747 = 0xB747;
+
+    private final SortingHelper sortingHelper;
+    private final TestRandom[] randoms;
+    private final int[] lengths;
+    private Object[] gold;
+    private Object[] test;
 
     public static void main(String[] args) {
+        long start = System.currentTimeMillis();
         boolean shortRun = args.length > 0 && args[0].equals("-shortrun");
-        long start = System.currentTimeMillis();
+
+        int[] lengths = shortRun ? SHORT_RUN_LENGTHS : LONG_RUN_LENGTHS;
+        TestRandom[] randoms = shortRun ? SHORT_RUN_RANDOMS : LONG_RUN_RANDOMS;
 
-        if (shortRun) {
-            testAndCheck(SHORT_RUN_LENGTHS, SHORT_RUN_RANDOMS);
-        } else {
-            testAndCheck(LONG_RUN_LENGTHS, LONG_RUN_RANDOMS);
-        }
+        new Sorting(SortingHelper.DUAL_PIVOT_QUICKSORT, randoms, lengths).testCore();
+        new Sorting(SortingHelper.PARALLEL_SORT, randoms, lengths).testCore();
+        new Sorting(SortingHelper.HEAP_SORT, randoms, lengths).testBasic();
+        new Sorting(SortingHelper.ARRAYS_SORT, randoms, lengths).testAll();
+        new Sorting(SortingHelper.ARRAYS_PARALLEL_SORT, randoms, lengths).testAll();
+
         long end = System.currentTimeMillis();
-
-        out.format("PASSED in %d sec.\n", Math.round((end - start) / 1E3));
+        out.format("PASSED in %d sec.\n", (end - start) / 1000);
     }
 
-    private static void testAndCheck(int[] lengths, long[] randoms) {
-        testEmptyAndNullIntArray();
-        testEmptyAndNullLongArray();
-        testEmptyAndNullShortArray();
-        testEmptyAndNullCharArray();
-        testEmptyAndNullByteArray();
-        testEmptyAndNullFloatArray();
-        testEmptyAndNullDoubleArray();
+    private Sorting(SortingHelper sortingHelper, TestRandom[] randoms, int[] lengths) {
+        this.sortingHelper = sortingHelper;
+        this.randoms = randoms;
+        this.lengths = lengths;
+    }
+
+    private void testBasic() {
+        testEmptyArray();
 
         for (int length : lengths) {
-            testMergeSort(length);
-            testAndCheckRange(length);
-            testAndCheckSubArray(length);
+            createData(length);
+            testBasic(length);
         }
-        for (long seed : randoms) {
-            for (int length : lengths) {
-                testAndCheckWithInsertionSort(length, new MyRandom(seed));
-                testAndCheckWithCheckSum(length, new MyRandom(seed));
-                testAndCheckWithScrambling(length, new MyRandom(seed));
-                testAndCheckFloat(length, new MyRandom(seed));
-                testAndCheckDouble(length, new MyRandom(seed));
-                testStable(length, new MyRandom(seed));
-            }
+    }
+
+    private void testBasic(int length) {
+        for (TestRandom random : randoms) {
+            testWithInsertionSort(length, random);
+            testWithCheckSum(length, random);
+            testWithScrambling(length, random);
         }
     }
 
-    private static void testEmptyAndNullIntArray() {
-        ourDescription = "Check empty and null array";
-        Arrays.sort(new int[] {});
-        Arrays.sort(new int[] {}, 0, 0);
+    private void testCore() {
+        for (int length : lengths) {
+            createData(length);
+            testCore(length);
+        }
+    }
+
+    private void testCore(int length) {
+        testBasic(length);
 
-        try {
-            Arrays.sort((int[]) null);
-        } catch (NullPointerException expected) {
-            try {
-                Arrays.sort((int[]) null, 0, 0);
-            } catch (NullPointerException expected2) {
-                return;
-            }
-            failed("Arrays.sort(int[],fromIndex,toIndex) shouldn't " +
-                "catch null array");
+        for (TestRandom random : randoms) {
+            testMergingSort(length, random);
+            testSubArray(length, random);
+            testNegativeZero(length, random);
+            testFloatingPointSorting(length, random);
         }
-        failed("Arrays.sort(int[]) shouldn't catch null array");
+    }
+
+    private void testAll() {
+        for (int length : lengths) {
+            createData(length);
+            testAll(length);
+        }
+    }
+
+    private void testAll(int length) {
+        testCore(length);
+
+        for (TestRandom random : randoms) {
+            testRange(length, random);
+            testStability(length, random);
+        }
     }
 
-    private static void testEmptyAndNullLongArray() {
-        ourDescription = "Check empty and null array";
-        Arrays.sort(new long[] {});
-        Arrays.sort(new long[] {}, 0, 0);
+    private void testEmptyArray() {
+        testEmptyAndNullIntArray();
+        testEmptyAndNullLongArray();
+        testEmptyAndNullByteArray();
+        testEmptyAndNullCharArray();
+        testEmptyAndNullShortArray();
+        testEmptyAndNullFloatArray();
+        testEmptyAndNullDoubleArray();
+    }
+
+    private void testStability(int length, TestRandom random) {
+        printTestName("Test stability", random, length);
+
+        Pair[] a = build(length, random);
+        sortingHelper.sort(a);
+        checkSorted(a);
+        checkStable(a);
+
+        a = build(length, random);
+        sortingHelper.sort(a, pairComparator);
+        checkSorted(a);
+        checkStable(a);
+
+        out.println();
+    }
+
+    private void testEmptyAndNullIntArray() {
+        sortingHelper.sort(new int[] {});
+        sortingHelper.sort(new int[] {}, 0, 0);
 
         try {
-            Arrays.sort((long[]) null);
+            sortingHelper.sort(null);
         } catch (NullPointerException expected) {
             try {
-                Arrays.sort((long[]) null, 0, 0);
-            } catch (NullPointerException expected2) {
-                return;
-            }
-            failed("Arrays.sort(long[],fromIndex,toIndex) shouldn't " +
-                "catch null array");
-        }
-        failed("Arrays.sort(long[]) shouldn't catch null array");
-    }
-
-    private static void testEmptyAndNullShortArray() {
-        ourDescription = "Check empty and null array";
-        Arrays.sort(new short[] {});
-        Arrays.sort(new short[] {}, 0, 0);
-
-        try {
-            Arrays.sort((short[]) null);
-        } catch (NullPointerException expected) {
-            try {
-                Arrays.sort((short[]) null, 0, 0);
+                sortingHelper.sort(null, 0, 0);
             } catch (NullPointerException expected2) {
                 return;
             }
-            failed("Arrays.sort(short[],fromIndex,toIndex) shouldn't " +
+            fail(sortingHelper + "(int[],fromIndex,toIndex) shouldn't " +
                 "catch null array");
         }
-        failed("Arrays.sort(short[]) shouldn't catch null array");
+        fail(sortingHelper + "(int[]) shouldn't catch null array");
     }
 
-    private static void testEmptyAndNullCharArray() {
-        ourDescription = "Check empty and null array";
-        Arrays.sort(new char[] {});
-        Arrays.sort(new char[] {}, 0, 0);
+    private void testEmptyAndNullLongArray() {
+        sortingHelper.sort(new long[] {});
+        sortingHelper.sort(new long[] {}, 0, 0);
 
         try {
-            Arrays.sort((char[]) null);
+            sortingHelper.sort(null);
         } catch (NullPointerException expected) {
             try {
-                Arrays.sort((char[]) null, 0, 0);
+                sortingHelper.sort(null, 0, 0);
             } catch (NullPointerException expected2) {
                 return;
             }
-            failed("Arrays.sort(char[],fromIndex,toIndex) shouldn't " +
+            fail(sortingHelper + "(long[],fromIndex,toIndex) shouldn't " +
                 "catch null array");
         }
-        failed("Arrays.sort(char[]) shouldn't catch null array");
+        fail(sortingHelper + "(long[]) shouldn't catch null array");
     }
 
-    private static void testEmptyAndNullByteArray() {
-        ourDescription = "Check empty and null array";
-        Arrays.sort(new byte[] {});
-        Arrays.sort(new byte[] {}, 0, 0);
+    private void testEmptyAndNullByteArray() {
+        sortingHelper.sort(new byte[] {});
+        sortingHelper.sort(new byte[] {}, 0, 0);
 
         try {
-            Arrays.sort((byte[]) null);
+            sortingHelper.sort(null);
         } catch (NullPointerException expected) {
             try {
-                Arrays.sort((byte[]) null, 0, 0);
+                sortingHelper.sort(null, 0, 0);
             } catch (NullPointerException expected2) {
                 return;
             }
-            failed("Arrays.sort(byte[],fromIndex,toIndex) shouldn't " +
+            fail(sortingHelper + "(byte[],fromIndex,toIndex) shouldn't " +
                 "catch null array");
         }
-        failed("Arrays.sort(byte[]) shouldn't catch null array");
+        fail(sortingHelper + "(byte[]) shouldn't catch null array");
     }
 
-    private static void testEmptyAndNullFloatArray() {
-        ourDescription = "Check empty and null array";
-        Arrays.sort(new float[] {});
-        Arrays.sort(new float[] {}, 0, 0);
+    private void testEmptyAndNullCharArray() {
+        sortingHelper.sort(new char[] {});
+        sortingHelper.sort(new char[] {}, 0, 0);
 
         try {
-            Arrays.sort((float[]) null);
+            sortingHelper.sort(null);
         } catch (NullPointerException expected) {
             try {
-                Arrays.sort((float[]) null, 0, 0);
+                sortingHelper.sort(null, 0, 0);
             } catch (NullPointerException expected2) {
                 return;
             }
-            failed("Arrays.sort(float[],fromIndex,toIndex) shouldn't " +
+            fail(sortingHelper + "(char[],fromIndex,toIndex) shouldn't " +
                 "catch null array");
         }
-        failed("Arrays.sort(float[]) shouldn't catch null array");
+        fail(sortingHelper + "(char[]) shouldn't catch null array");
     }
 
-    private static void testEmptyAndNullDoubleArray() {
-        ourDescription = "Check empty and null array";
-        Arrays.sort(new double[] {});
-        Arrays.sort(new double[] {}, 0, 0);
+    private void testEmptyAndNullShortArray() {
+        sortingHelper.sort(new short[] {});
+        sortingHelper.sort(new short[] {}, 0, 0);
 
         try {
-            Arrays.sort((double[]) null);
+            sortingHelper.sort(null);
         } catch (NullPointerException expected) {
             try {
-                Arrays.sort((double[]) null, 0, 0);
+                sortingHelper.sort(null, 0, 0);
+            } catch (NullPointerException expected2) {
+                return;
+            }
+            fail(sortingHelper + "(short[],fromIndex,toIndex) shouldn't " +
+                "catch null array");
+        }
+        fail(sortingHelper + "(short[]) shouldn't catch null array");
+    }
+
+    private void testEmptyAndNullFloatArray() {
+        sortingHelper.sort(new float[] {});
+        sortingHelper.sort(new float[] {}, 0, 0);
+
+        try {
+            sortingHelper.sort(null);
+        } catch (NullPointerException expected) {
+            try {
+                sortingHelper.sort(null, 0, 0);
             } catch (NullPointerException expected2) {
                 return;
             }
-            failed("Arrays.sort(double[],fromIndex,toIndex) shouldn't " +
+            fail(sortingHelper + "(float[],fromIndex,toIndex) shouldn't " +
                 "catch null array");
         }
-        failed("Arrays.sort(double[]) shouldn't catch null array");
+        fail(sortingHelper + "(float[]) shouldn't catch null array");
     }
 
-    private static void testAndCheckSubArray(int length) {
-        ourDescription = "Check sorting of subarray";
-        int[] golden = new int[length];
-        boolean newLine = false;
+    private void testEmptyAndNullDoubleArray() {
+        sortingHelper.sort(new double[] {});
+        sortingHelper.sort(new double[] {}, 0, 0);
 
-        for (int m = 1; m < length / 2; m *= 2) {
-            newLine = true;
+        try {
+            sortingHelper.sort(null);
+        } catch (NullPointerException expected) {
+            try {
+                sortingHelper.sort(null, 0, 0);
+            } catch (NullPointerException expected2) {
+                return;
+            }
+            fail(sortingHelper + "(double[],fromIndex,toIndex) shouldn't " +
+                "catch null array");
+        }
+        fail(sortingHelper + "(double[]) shouldn't catch null array");
+    }
+
+    private void testSubArray(int length, TestRandom random) {
+        if (length < 4) {
+            return;
+        }
+        for (int m = 1; m < length / 2; m <<= 1) {
             int fromIndex = m;
             int toIndex = length - m;
 
-            prepareSubArray(golden, fromIndex, toIndex, m);
-            int[] test = golden.clone();
+            prepareSubArray((int[]) gold[0], fromIndex, toIndex);
+            convertData(length);
 
-            for (TypeConverter converter : TypeConverter.values()) {
-                out.println("Test 'subarray': " + converter +
-                   " length = " + length + ", m = " + m);
-                Object convertedGolden = converter.convert(golden);
-                Object convertedTest = converter.convert(test);
-                sortSubArray(convertedTest, fromIndex, toIndex);
-                checkSubArray(convertedTest, fromIndex, toIndex, m);
-            }
-        }
-        if (newLine) {
-            out.println();
-        }
-    }
-
-    private static void testAndCheckRange(int length) {
-        ourDescription = "Check range check";
-        int[] golden = new int[length];
-
-        for (int m = 1; m < 2 * length; m *= 2) {
-            for (int i = 1; i <= length; i++) {
-                golden[i - 1] = i % m + m % i;
-            }
-            for (TypeConverter converter : TypeConverter.values()) {
-                out.println("Test 'range': " + converter +
-                   ", length = " + length + ", m = " + m);
-                Object convertedGolden = converter.convert(golden);
-                checkRange(convertedGolden, m);
+            for (int i = 0; i < test.length; i++) {
+                printTestName("Test subarray", random, length,
+                    ", m = " + m + ", " + getType(i));
+                sortingHelper.sort(test[i], fromIndex, toIndex);
+                checkSubArray(test[i], fromIndex, toIndex);
             }
         }
         out.println();
     }
 
-    private static void testStable(int length, MyRandom random) {
-        ourDescription = "Check if sorting is stable";
-        Pair[] a = build(length, random);
+    private void testRange(int length, TestRandom random) {
+        if (length < 2) {
+            return;
+        }
+        for (int m = 1; m < length; m <<= 1) {
+            for (int i = 1; i <= length; i++) {
+                ((int[]) gold[0]) [i - 1] = i % m + m % i;
+            }
+            convertData(length);
 
-        out.println("Test 'stable': " + "random = " + random.getSeed() +
-            ", length = " + length);
-        Arrays.sort(a);
-        checkSorted(a);
-        checkStable(a);
+            for (int i = 0; i < test.length; i++) {
+                printTestName("Test range check", random, length,
+                    ", m = " + m + ", " + getType(i));
+                checkRange(test[i], m);
+            }
+        }
         out.println();
     }
 
-    private static void checkSorted(Pair[] a) {
+    private void checkSorted(Pair[] a) {
         for (int i = 0; i < a.length - 1; i++) {
             if (a[i].getKey() > a[i + 1].getKey()) {
-                failedSort(i, "" + a[i].getKey(), "" + a[i + 1].getKey());
+                fail("Array is not sorted at " + i + "-th position: " +
+                    a[i].getKey() + " and " + a[i + 1].getKey());
             }
         }
     }
 
-    private static void checkStable(Pair[] a) {
+    private void checkStable(Pair[] a) {
         for (int i = 0; i < a.length / 4; ) {
             int key1 = a[i].getKey();
             int value1 = a[i++].getValue();
@@ -305,18 +357,18 @@
             int value4 = a[i++].getValue();
 
             if (!(key1 == key2 && key2 == key3 && key3 == key4)) {
-                failed("On position " + i + " keys are different " +
-                    key1 + ", " + key2 + ", " + key3 + ", " + key4);
+                fail("Keys are different " + key1 + ", " + key2 + ", " +
+                    key3 + ", " + key4 + " at position " + i);
             }
             if (!(value1 < value2 && value2 < value3 && value3 < value4)) {
-                failed("Sorting is not stable at position " + i +
-                    ". Second values have been changed: " +  value1 + ", " +
+                fail("Sorting is not stable at position " + i +
+                    ". Second values have been changed: " + value1 + ", " +
                     value2 + ", " + value3 + ", " + value4);
             }
         }
     }
 
-    private static Pair[] build(int length, Random random) {
+    private Pair[] build(int length, Random random) {
         Pair[] a = new Pair[length * 4];
 
         for (int i = 0; i < a.length; ) {
@@ -329,222 +381,151 @@
         return a;
     }
 
-    private static final class Pair implements Comparable<Pair> {
-        Pair(int key, int value) {
-            myKey = key;
-            myValue = value;
-        }
-
-        int getKey() {
-            return myKey;
-        }
-
-        int getValue() {
-            return myValue;
-        }
-
-        public int compareTo(Pair pair) {
-            if (myKey < pair.myKey) {
-                return -1;
-            }
-            if (myKey > pair.myKey) {
-                return 1;
-            }
-            return 0;
-        }
-
-        @Override
-        public String toString() {
-            return "(" + myKey + ", " + myValue + ")";
-        }
-
-        private int myKey;
-        private int myValue;
-    }
-
-
-    private static void testAndCheckWithInsertionSort(int length, MyRandom random) {
+    private void testWithInsertionSort(int length, TestRandom random) {
         if (length > 1000) {
             return;
         }
-        ourDescription = "Check sorting with insertion sort";
-        int[] golden = new int[length];
-
-        for (int m = 1; m < 2 * length; m *= 2) {
+        for (int m = 1; m <= length; m <<= 1) {
             for (UnsortedBuilder builder : UnsortedBuilder.values()) {
-                builder.build(golden, m, random);
-                int[] test = golden.clone();
+                builder.build((int[]) gold[0], m, random);
+                convertData(length);
 
-                for (TypeConverter converter : TypeConverter.values()) {
-                    out.println("Test 'insertion sort': " + converter +
-                        " " + builder + "random = " + random.getSeed() +
-                        ", length = " + length + ", m = " + m);
-                    Object convertedGolden = converter.convert(golden);
-                    Object convertedTest1 = converter.convert(test);
-                    Object convertedTest2 = converter.convert(test);
-                    sort(convertedTest1);
-                    sortByInsertionSort(convertedTest2);
-                    compare(convertedTest1, convertedTest2);
+                for (int i = 0; i < test.length; i++) {
+                    printTestName("Test with insertion sort", random, length,
+                        ", m = " + m + ", " + getType(i) + " " + builder);
+                    sortingHelper.sort(test[i]);
+                    sortByInsertionSort(gold[i]);
+                    compare(test[i], gold[i]);
                 }
             }
         }
         out.println();
     }
 
-    private static void testMergeSort(int length) {
-        if (length < 1000) {
+    private void testMergingSort(int length, TestRandom random) {
+        if (length < (4 << 10)) { // DualPivotQuicksort.MIN_TRY_MERGE_SIZE
             return;
         }
-        ourDescription = "Check merge sorting";
-        int[] golden = new int[length];
-        int period = 67; // java.util.DualPivotQuicksort.MAX_RUN_COUNT
+        final int PERIOD = 50;
+
+        for (int m = PERIOD - 2; m <= PERIOD + 2; m++) {
+            for (MergingBuilder builder : MergingBuilder.values()) {
+                builder.build((int[]) gold[0], m);
+                convertData(length);
 
-        for (int m = period - 2; m <= period + 2; m++) {
-            for (MergeBuilder builder : MergeBuilder.values()) {
-                builder.build(golden, m);
-                int[] test = golden.clone();
+                for (int i = 0; i < test.length; i++) {
+                    printTestName("Test merging sort", random, length,
+                        ", m = " + m + ", " +  getType(i) + " " + builder);
+                    sortingHelper.sort(test[i]);
+                    checkSorted(test[i]);
+                }
+            }
+        }
+        out.println();
+    }
 
-                for (TypeConverter converter : TypeConverter.values()) {
-                    out.println("Test 'merge sort': " + converter + " " +
-                        builder + "length = " + length + ", m = " + m);
-                    Object convertedGolden = converter.convert(golden);
-                    sort(convertedGolden);
-                    checkSorted(convertedGolden);
+    private void testWithCheckSum(int length, TestRandom random) {
+        for (int m = 1; m <= length; m <<= 1) {
+            for (UnsortedBuilder builder : UnsortedBuilder.values()) {
+                builder.build((int[]) gold[0], m, random);
+                convertData(length);
+
+                for (int i = 0; i < test.length; i++) {
+                    printTestName("Test with check sum", random, length,
+                        ", m = " + m + ", " + getType(i) + " " + builder);
+                    sortingHelper.sort(test[i]);
+                    checkWithCheckSum(test[i], gold[i]);
                 }
             }
         }
         out.println();
     }
 
-    private static void testAndCheckWithCheckSum(int length, MyRandom random) {
-        ourDescription = "Check sorting with check sum";
-        int[] golden = new int[length];
-
-        for (int m = 1; m < 2 * length; m *= 2) {
-            for (UnsortedBuilder builder : UnsortedBuilder.values()) {
-                builder.build(golden, m, random);
-                int[] test = golden.clone();
+    private void testWithScrambling(int length, TestRandom random) {
+        for (int m = 1; m <= length; m <<= 1) {
+            for (SortedBuilder builder : SortedBuilder.values()) {
+                builder.build((int[]) gold[0], m);
+                convertData(length);
 
-                for (TypeConverter converter : TypeConverter.values()) {
-                    out.println("Test 'check sum': " + converter +
-                        " " + builder + "random = " + random.getSeed() +
-                        ", length = " + length + ", m = " + m);
-                    Object convertedGolden = converter.convert(golden);
-                    Object convertedTest = converter.convert(test);
-                    sort(convertedTest);
-                    checkWithCheckSum(convertedTest, convertedGolden);
-                }
-            }
-        }
-        out.println();
-    }
-
-    private static void testAndCheckWithScrambling(int length, MyRandom random) {
-        ourDescription = "Check sorting with scrambling";
-        int[] golden = new int[length];
-
-        for (int m = 1; m <= 7; m++) {
-            if (m > length) {
-                break;
-            }
-            for (SortedBuilder builder : SortedBuilder.values()) {
-                builder.build(golden, m);
-                int[] test = golden.clone();
-                scramble(test, random);
-
-                for (TypeConverter converter : TypeConverter.values()) {
-                    out.println("Test 'scrambling': " + converter +
-                       " " + builder + "random = " + random.getSeed() +
-                       ", length = " + length + ", m = " + m);
-                    Object convertedGolden = converter.convert(golden);
-                    Object convertedTest = converter.convert(test);
-                    sort(convertedTest);
-                    compare(convertedTest, convertedGolden);
+                for (int i = 0; i < test.length; i++) {
+                    printTestName("Test with scrambling", random, length,
+                        ", m = " + m + ", " + getType(i) + " " + builder);
+                    scramble(test[i], random);
+                    sortingHelper.sort(test[i]);
+                    compare(test[i], gold[i]);
                 }
             }
         }
         out.println();
     }
 
-    private static void testAndCheckFloat(int length, MyRandom random) {
-        ourDescription = "Check float sorting";
-        float[] golden = new float[length];
-        final int MAX = 10;
-        boolean newLine = false;
+    private void testNegativeZero(int length, TestRandom random) {
+        for (int i = 5; i < test.length; i++) {
+            printTestName("Test negative zero -0.0", random, length, " " + getType(i));
+
+            NegativeZeroBuilder builder = NegativeZeroBuilder.values() [i - 5];
+            builder.build(test[i], random);
+
+            sortingHelper.sort(test[i]);
+            checkNegativeZero(test[i]);
+        }
+        out.println();
+    }
 
-        for (int a = 0; a <= MAX; a++) {
-            for (int g = 0; g <= MAX; g++) {
-                for (int z = 0; z <= MAX; z++) {
-                    for (int n = 0; n <= MAX; n++) {
-                        for (int p = 0; p <= MAX; p++) {
-                            if (a + g + z + n + p > length) {
+    private void testFloatingPointSorting(int length, TestRandom random) {
+        if (length < 2) {
+            return;
+        }
+        final int MAX = 13;
+
+        for (int a = 0; a < MAX; a++) {
+            for (int g = 0; g < MAX; g++) {
+                for (int z = 0; z < MAX; z++) {
+                    for (int n = 0; n < MAX; n++) {
+                        for (int p = 0; p < MAX; p++) {
+                            if (a + g + z + n + p != length) {
                                 continue;
                             }
-                            if (a + g + z + n + p < length) {
-                                continue;
+                            for (int i = 5; i < test.length; i++) {
+                                printTestName("Test float-pointing sorting", random, length,
+                                    ", a = " + a + ", g = " + g + ", z = " + z +
+                                    ", n = " + n + ", p = " + p + ", " + getType(i));
+                                FloatingPointBuilder builder = FloatingPointBuilder.values()[i - 5];
+                                builder.build(gold[i], a, g, z, n, p, random);
+                                copy(test[i], gold[i]);
+                                scramble(test[i], random);
+                                sortingHelper.sort(test[i]);
+                                compare(test[i], gold[i], a, n, g);
                             }
-                            for (FloatBuilder builder : FloatBuilder.values()) {
-                                out.println("Test 'float': random = " + random.getSeed() +
-                                   ", length = " + length + ", a = " + a + ", g = " +
-                                   g + ", z = " + z + ", n = " + n + ", p = " + p);
-                                builder.build(golden, a, g, z, n, p, random);
-                                float[] test = golden.clone();
-                                scramble(test, random);
-                                sort(test);
-                                compare(test, golden, a, n, g);
-                            }
-                            newLine = true;
                         }
                     }
                 }
             }
         }
-        if (newLine) {
-            out.println();
+
+        for (int m = 13; m > 4; m--) {
+            int t = length / m;
+            int g = t, z = t, n = t, p = t;
+            int a = length - g - z - n - p;
+
+            for (int i = 5; i < test.length; i++) {
+                printTestName("Test float-pointing sorting", random, length,
+                    ", a = " + a + ", g = " + g + ", z = " + z +
+                    ", n = " + n + ", p = " + p + ", " + getType(i));
+                FloatingPointBuilder builder = FloatingPointBuilder.values() [i - 5];
+                builder.build(gold[i], a, g, z, n, p, random);
+                copy(test[i], gold[i]);
+                scramble(test[i], random);
+                sortingHelper.sort(test[i]);
+                compare(test[i], gold[i], a, n, g);
+            }
         }
+        out.println();
     }
 
-    private static void testAndCheckDouble(int length, MyRandom random) {
-        ourDescription = "Check double sorting";
-        double[] golden = new double[length];
-        final int MAX = 10;
-        boolean newLine = false;
-
-        for (int a = 0; a <= MAX; a++) {
-            for (int g = 0; g <= MAX; g++) {
-                for (int z = 0; z <= MAX; z++) {
-                    for (int n = 0; n <= MAX; n++) {
-                        for (int p = 0; p <= MAX; p++) {
-                            if (a + g + z + n + p > length) {
-                                continue;
-                            }
-                            if (a + g + z + n + p < length) {
-                                continue;
-                            }
-                            for (DoubleBuilder builder : DoubleBuilder.values()) {
-                                out.println("Test 'double': random = " + random.getSeed() +
-                                   ", length = " + length + ", a = " + a + ", g = " +
-                                   g + ", z = " + z + ", n = " + n + ", p = " + p);
-                                builder.build(golden, a, g, z, n, p, random);
-                                double[] test = golden.clone();
-                                scramble(test, random);
-                                sort(test);
-                                compare(test, golden, a, n, g);
-                            }
-                            newLine = true;
-                        }
-                    }
-                }
-            }
-        }
-        if (newLine) {
-            out.println();
-        }
-    }
-
-    private static void prepareSubArray(int[] a, int fromIndex, int toIndex, int m) {
+    private void prepareSubArray(int[] a, int fromIndex, int toIndex) {
         for (int i = 0; i < fromIndex; i++) {
-            a[i] = 0xDEDA;
+            a[i] = A380;
         }
         int middle = (fromIndex + toIndex) >>> 1;
         int k = 0;
@@ -552,338 +533,1112 @@
         for (int i = fromIndex; i < middle; i++) {
             a[i] = k++;
         }
+
         for (int i = middle; i < toIndex; i++) {
             a[i] = k--;
         }
+
         for (int i = toIndex; i < a.length; i++) {
-            a[i] = 0xBABA;
+            a[i] = B747;
         }
     }
 
-    private static void scramble(int[] a, Random random) {
+    private void scramble(Object a, Random random) {
+        if (a instanceof int[]) {
+            scramble((int[]) a, random);
+        } else if (a instanceof long[]) {
+            scramble((long[]) a, random);
+        } else if (a instanceof byte[]) {
+            scramble((byte[]) a, random);
+        } else if (a instanceof char[]) {
+            scramble((char[]) a, random);
+        } else if (a instanceof short[]) {
+            scramble((short[]) a, random);
+        } else if (a instanceof float[]) {
+            scramble((float[]) a, random);
+        } else if (a instanceof double[]) {
+            scramble((double[]) a, random);
+        } else {
+            fail("Unknown type of array: " + a.getClass().getName());
+        }
+    }
+
+    private void scramble(int[] a, Random random) {
         for (int i = 0; i < a.length * 7; i++) {
             swap(a, random.nextInt(a.length), random.nextInt(a.length));
         }
     }
 
-    private static void scramble(float[] a, Random random) {
+    private void scramble(long[] a, Random random) {
+        for (int i = 0; i < a.length * 7; i++) {
+            swap(a, random.nextInt(a.length), random.nextInt(a.length));
+        }
+    }
+
+    private void scramble(byte[] a, Random random) {
         for (int i = 0; i < a.length * 7; i++) {
             swap(a, random.nextInt(a.length), random.nextInt(a.length));
         }
     }
 
-    private static void scramble(double[] a, Random random) {
+    private void scramble(char[] a, Random random) {
+        for (int i = 0; i < a.length * 7; i++) {
+            swap(a, random.nextInt(a.length), random.nextInt(a.length));
+        }
+    }
+
+    private void scramble(short[] a, Random random) {
+        for (int i = 0; i < a.length * 7; i++) {
+            swap(a, random.nextInt(a.length), random.nextInt(a.length));
+        }
+    }
+
+    private void scramble(float[] a, Random random) {
+        for (int i = 0; i < a.length * 7; i++) {
+            swap(a, random.nextInt(a.length), random.nextInt(a.length));
+        }
+    }
+
+    private void scramble(double[] a, Random random) {
         for (int i = 0; i < a.length * 7; i++) {
             swap(a, random.nextInt(a.length), random.nextInt(a.length));
         }
     }
 
-    private static void swap(int[] a, int i, int j) {
-        int t = a[i];
-        a[i] = a[j];
-        a[j] = t;
+    private void swap(int[] a, int i, int j) {
+        int t = a[i]; a[i] = a[j]; a[j] = t;
+    }
+
+    private void swap(long[] a, int i, int j) {
+        long t = a[i]; a[i] = a[j]; a[j] = t;
     }
 
-    private static void swap(float[] a, int i, int j) {
-        float t = a[i];
-        a[i] = a[j];
-        a[j] = t;
+    private void swap(byte[] a, int i, int j) {
+        byte t = a[i]; a[i] = a[j]; a[j] = t;
     }
 
-    private static void swap(double[] a, int i, int j) {
-        double t = a[i];
-        a[i] = a[j];
-        a[j] = t;
+    private void swap(char[] a, int i, int j) {
+        char t = a[i]; a[i] = a[j]; a[j] = t;
+    }
+
+    private void swap(short[] a, int i, int j) {
+        short t = a[i]; a[i] = a[j]; a[j] = t;
     }
 
-    private static enum TypeConverter {
-        INT {
-            Object convert(int[] a) {
-                return a.clone();
-            }
-        },
-        LONG {
-            Object convert(int[] a) {
-                long[] b = new long[a.length];
-
-                for (int i = 0; i < a.length; i++) {
-                    b[i] = (long) a[i];
-                }
-                return b;
-            }
-        },
-        BYTE {
-            Object convert(int[] a) {
-                byte[] b = new byte[a.length];
+    private void swap(float[] a, int i, int j) {
+        float t = a[i]; a[i] = a[j]; a[j] = t;
+    }
 
-                for (int i = 0; i < a.length; i++) {
-                    b[i] = (byte) a[i];
-                }
-                return b;
-            }
-        },
-        SHORT {
-            Object convert(int[] a) {
-                short[] b = new short[a.length];
+    private void swap(double[] a, int i, int j) {
+        double t = a[i]; a[i] = a[j]; a[j] = t;
+    }
 
-                for (int i = 0; i < a.length; i++) {
-                    b[i] = (short) a[i];
-                }
-                return b;
-            }
-        },
-        CHAR {
-            Object convert(int[] a) {
-                char[] b = new char[a.length];
+    private void checkWithCheckSum(Object test, Object gold) {
+        checkSorted(test);
+        checkCheckSum(test, gold);
+    }
 
-                for (int i = 0; i < a.length; i++) {
-                    b[i] = (char) a[i];
-                }
-                return b;
-            }
-        },
-        FLOAT {
-            Object convert(int[] a) {
-                float[] b = new float[a.length];
-
-                for (int i = 0; i < a.length; i++) {
-                    b[i] = (float) a[i];
-                }
-                return b;
-            }
-        },
-        DOUBLE {
-            Object convert(int[] a) {
-                double[] b = new double[a.length];
+    private void fail(String message) {
+        err.format("\n*** TEST FAILED ***\n\n%s\n\n", message);
+        throw new RuntimeException("Test failed");
+    }
 
-                for (int i = 0; i < a.length; i++) {
-                    b[i] = (double) a[i];
-                }
-                return b;
-            }
-        },
-        INTEGER {
-            Object convert(int[] a) {
-                Integer[] b = new Integer[a.length];
-
-                for (int i = 0; i < a.length; i++) {
-                    b[i] = new Integer(a[i]);
-                }
-                return b;
-            }
-        };
-
-        abstract Object convert(int[] a);
-
-        @Override public String toString() {
-            String name = name();
-
-            for (int i = name.length(); i < 9; i++) {
-                name += " ";
-            }
-            return name;
+    private void checkNegativeZero(Object a) {
+        if (a instanceof float[]) {
+            checkNegativeZero((float[]) a);
+        } else if (a instanceof double[]) {
+            checkNegativeZero((double[]) a);
+        } else {
+            fail("Unknown type of array: " + a.getClass().getName());
         }
     }
 
-    private static enum FloatBuilder {
-        SIMPLE {
-            void build(float[] x, int a, int g, int z, int n, int p, Random random) {
-                int fromIndex = 0;
-                float negativeValue = -random.nextFloat();
-                float positiveValue =  random.nextFloat();
-
-                writeValue(x, negativeValue, fromIndex, n);
-                fromIndex += n;
-
-                writeValue(x, -0.0f, fromIndex, g);
-                fromIndex += g;
-
-                writeValue(x, 0.0f, fromIndex, z);
-                fromIndex += z;
-
-                writeValue(x, positiveValue, fromIndex, p);
-                fromIndex += p;
-
-                writeValue(x, Float.NaN, fromIndex, a);
+    private void checkNegativeZero(float[] a) {
+        for (int i = 0; i < a.length - 1; i++) {
+            if (Float.floatToRawIntBits(a[i]) == 0 && Float.floatToRawIntBits(a[i + 1]) < 0) {
+                fail(a[i] + " before " + a[i + 1] + " at position " + i);
             }
-        };
-
-        abstract void build(float[] x, int a, int g, int z, int n, int p, Random random);
-    }
-
-    private static enum DoubleBuilder {
-        SIMPLE {
-            void build(double[] x, int a, int g, int z, int n, int p, Random random) {
-                int fromIndex = 0;
-                double negativeValue = -random.nextFloat();
-                double positiveValue =  random.nextFloat();
-
-                writeValue(x, negativeValue, fromIndex, n);
-                fromIndex += n;
-
-                writeValue(x, -0.0d, fromIndex, g);
-                fromIndex += g;
-
-                writeValue(x, 0.0d, fromIndex, z);
-                fromIndex += z;
-
-                writeValue(x, positiveValue, fromIndex, p);
-                fromIndex += p;
-
-                writeValue(x, Double.NaN, fromIndex, a);
-            }
-        };
-
-        abstract void build(double[] x, int a, int g, int z, int n, int p, Random random);
-    }
-
-    private static void writeValue(float[] a, float value, int fromIndex, int count) {
-        for (int i = fromIndex; i < fromIndex + count; i++) {
-            a[i] = value;
         }
     }
 
-    private static void compare(float[] a, float[] b, int numNaN, int numNeg, int numNegZero) {
+    private void checkNegativeZero(double[] a) {
+        for (int i = 0; i < a.length - 1; i++) {
+            if (Double.doubleToRawLongBits(a[i]) == 0 && Double.doubleToRawLongBits(a[i + 1]) < 0) {
+                fail(a[i] + " before " + a[i + 1] + " at position " + i);
+            }
+        }
+    }
+
+    private void compare(Object a, Object b, int numNaN, int numNeg, int numNegZero) {
+        if (a instanceof float[]) {
+            compare((float[]) a, (float[]) b, numNaN, numNeg, numNegZero);
+        } else if (a instanceof double[]) {
+            compare((double[]) a, (double[]) b, numNaN, numNeg, numNegZero);
+        } else {
+            fail("Unknown type of array: " + a.getClass().getName());
+        }
+    }
+
+    private void compare(float[] a, float[] b, int numNaN, int numNeg, int numNegZero) {
         for (int i = a.length - numNaN; i < a.length; i++) {
             if (a[i] == a[i]) {
-                failed("On position " + i + " must be NaN instead of " + a[i]);
+                fail("There must be NaN instead of " + a[i] + " at position " + i);
             }
         }
         final int NEGATIVE_ZERO = Float.floatToIntBits(-0.0f);
 
         for (int i = numNeg; i < numNeg + numNegZero; i++) {
             if (NEGATIVE_ZERO != Float.floatToIntBits(a[i])) {
-                failed("On position " + i + " must be -0.0 instead of " + a[i]);
+                fail("There must be -0.0 instead of " + a[i] + " at position " + i);
             }
         }
+
         for (int i = 0; i < a.length - numNaN; i++) {
             if (a[i] != b[i]) {
-                failedCompare(i, "" + a[i], "" + b[i]);
+                fail("There must be " + b[i] + " instead of " + a[i] + " at position " + i);
             }
         }
     }
 
-    private static void writeValue(double[] a, double value, int fromIndex, int count) {
-        for (int i = fromIndex; i < fromIndex + count; i++) {
-            a[i] = value;
-        }
-    }
-
-    private static void compare(double[] a, double[] b, int numNaN, int numNeg, int numNegZero) {
+    private void compare(double[] a, double[] b, int numNaN, int numNeg, int numNegZero) {
         for (int i = a.length - numNaN; i < a.length; i++) {
             if (a[i] == a[i]) {
-                failed("On position " + i + " must be NaN instead of " + a[i]);
+                fail("There must be NaN instead of " + a[i] + " at position " + i);
             }
         }
         final long NEGATIVE_ZERO = Double.doubleToLongBits(-0.0d);
 
         for (int i = numNeg; i < numNeg + numNegZero; i++) {
             if (NEGATIVE_ZERO != Double.doubleToLongBits(a[i])) {
-                failed("On position " + i + " must be -0.0 instead of " + a[i]);
+                fail("There must be -0.0 instead of " + a[i] + " at position " + i);
+            }
+        }
+
+        for (int i = 0; i < a.length - numNaN; i++) {
+            if (a[i] != b[i]) {
+                fail("There must be " + b[i] + " instead of " + a[i] + " at position " + i);
+            }
+        }
+    }
+
+    private void compare(Object a, Object b) {
+        if (a instanceof int[]) {
+            compare((int[]) a, (int[]) b);
+        } else if (a instanceof long[]) {
+            compare((long[]) a, (long[]) b);
+        } else if (a instanceof byte[]) {
+            compare((byte[]) a, (byte[]) b);
+        } else if (a instanceof char[]) {
+            compare((char[]) a, (char[]) b);
+        } else if (a instanceof short[]) {
+            compare((short[]) a, (short[]) b);
+        } else if (a instanceof float[]) {
+            compare((float[]) a, (float[]) b);
+        } else if (a instanceof double[]) {
+            compare((double[]) a, (double[]) b);
+        } else {
+            fail("Unknown type of array: " + a.getClass().getName());
+        }
+    }
+
+    private void compare(int[] a, int[] b) {
+        for (int i = 0; i < a.length; i++) {
+            if (a[i] != b[i]) {
+                fail("There must be " + b[i] + " instead of " + a[i] + " at position " + i);
+            }
+        }
+    }
+
+    private void compare(long[] a, long[] b) {
+        for (int i = 0; i < a.length; i++) {
+            if (a[i] != b[i]) {
+                fail("There must be " + b[i] + " instead of " + a[i] + " at position " + i);
+            }
+        }
+    }
+
+    private void compare(byte[] a, byte[] b) {
+        for (int i = 0; i < a.length; i++) {
+            if (a[i] != b[i]) {
+                fail("There must be " + b[i] + " instead of " + a[i] + " at position " + i);
+            }
+        }
+    }
+
+    private void compare(char[] a, char[] b) {
+        for (int i = 0; i < a.length; i++) {
+            if (a[i] != b[i]) {
+                fail("There must be " + b[i] + " instead of " + a[i] + " at position " + i);
+            }
+        }
+    }
+
+    private void compare(short[] a, short[] b) {
+        for (int i = 0; i < a.length; i++) {
+            if (a[i] != b[i]) {
+                fail("There must be " + b[i] + " instead of " + a[i] + " at position " + i);
+            }
+        }
+    }
+
+    private void compare(float[] a, float[] b) {
+        for (int i = 0; i < a.length; i++) {
+            if (a[i] != b[i]) {
+                fail("There must be " + b[i] + " instead of " + a[i] + " at position " + i);
+            }
+        }
+    }
+
+    private void compare(double[] a, double[] b) {
+        for (int i = 0; i < a.length; i++) {
+            if (a[i] != b[i]) {
+                fail("There must be " + b[i] + " instead of " + a[i] + " at position " + i);
             }
         }
-        for (int i = 0; i < a.length - numNaN; i++) {
-            if (a[i] != b[i]) {
-                failedCompare(i, "" + a[i], "" + b[i]);
+    }
+
+    private String getType(int i) {
+        Object a = test[i];
+
+        if (a instanceof int[]) {
+            return "INT   ";
+        }
+        if (a instanceof long[]) {
+            return "LONG  ";
+        }
+        if (a instanceof byte[]) {
+            return "BYTE  ";
+        }
+        if (a instanceof char[]) {
+            return "CHAR  ";
+        }
+        if (a instanceof short[]) {
+            return "SHORT ";
+        }
+        if (a instanceof float[]) {
+            return "FLOAT ";
+        }
+        if (a instanceof double[]) {
+            return "DOUBLE";
+        }
+        fail("Unknown type of array: " + a.getClass().getName());
+        return null;
+    }
+
+    private void checkSorted(Object a) {
+        if (a instanceof int[]) {
+            checkSorted((int[]) a);
+        } else if (a instanceof long[]) {
+            checkSorted((long[]) a);
+        } else if (a instanceof byte[]) {
+            checkSorted((byte[]) a);
+        } else if (a instanceof char[]) {
+            checkSorted((char[]) a);
+        } else if (a instanceof short[]) {
+            checkSorted((short[]) a);
+        } else if (a instanceof float[]) {
+            checkSorted((float[]) a);
+        } else if (a instanceof double[]) {
+            checkSorted((double[]) a);
+        } else {
+            fail("Unknown type of array: " + a.getClass().getName());
+        }
+    }
+
+    private void checkSorted(int[] a) {
+        for (int i = 0; i < a.length - 1; i++) {
+            if (a[i] > a[i + 1]) {
+                fail("Array is not sorted at " + i + "-th position: " + a[i] + " and " + a[i + 1]);
+            }
+        }
+    }
+
+    private void checkSorted(long[] a) {
+        for (int i = 0; i < a.length - 1; i++) {
+            if (a[i] > a[i + 1]) {
+                fail("Array is not sorted at " + i + "-th position: " + a[i] + " and " + a[i + 1]);
+            }
+        }
+    }
+
+    private void checkSorted(byte[] a) {
+        for (int i = 0; i < a.length - 1; i++) {
+            if (a[i] > a[i + 1]) {
+                fail("Array is not sorted at " + i + "-th position: " + a[i] + " and " + a[i + 1]);
+            }
+        }
+    }
+
+    private void checkSorted(char[] a) {
+        for (int i = 0; i < a.length - 1; i++) {
+            if (a[i] > a[i + 1]) {
+                fail("Array is not sorted at " + i + "-th position: " + a[i] + " and " + a[i + 1]);
+            }
+        }
+    }
+
+    private void checkSorted(short[] a) {
+        for (int i = 0; i < a.length - 1; i++) {
+            if (a[i] > a[i + 1]) {
+                fail("Array is not sorted at " + i + "-th position: " + a[i] + " and " + a[i + 1]);
+            }
+        }
+    }
+
+    private void checkSorted(float[] a) {
+        for (int i = 0; i < a.length - 1; i++) {
+            if (a[i] > a[i + 1]) {
+                fail("Array is not sorted at " + i + "-th position: " + a[i] + " and " + a[i + 1]);
+            }
+        }
+    }
+
+    private void checkSorted(double[] a) {
+        for (int i = 0; i < a.length - 1; i++) {
+            if (a[i] > a[i + 1]) {
+                fail("Array is not sorted at " + i + "-th position: " + a[i] + " and " + a[i + 1]);
             }
         }
     }
 
-    private static enum SortedBuilder {
-        REPEATED {
-            void build(int[] a, int m) {
-                int period = a.length / m;
-                int i = 0;
-                int k = 0;
+    private void checkCheckSum(Object test, Object gold) {
+        if (checkSumXor(test) != checkSumXor(gold)) {
+            fail("Original and sorted arrays are not identical [^]");
+        }
+        if (checkSumPlus(test) != checkSumPlus(gold)) {
+            fail("Original and sorted arrays are not identical [+]");
+        }
+    }
+
+    private int checkSumXor(Object a) {
+        if (a instanceof int[]) {
+            return checkSumXor((int[]) a);
+        }
+        if (a instanceof long[]) {
+            return checkSumXor((long[]) a);
+        }
+        if (a instanceof byte[]) {
+            return checkSumXor((byte[]) a);
+        }
+        if (a instanceof char[]) {
+            return checkSumXor((char[]) a);
+        }
+        if (a instanceof short[]) {
+            return checkSumXor((short[]) a);
+        }
+        if (a instanceof float[]) {
+            return checkSumXor((float[]) a);
+        }
+        if (a instanceof double[]) {
+            return checkSumXor((double[]) a);
+        }
+        fail("Unknown type of array: " + a.getClass().getName());
+        return -1;
+    }
+
+    private int checkSumXor(int[] a) {
+        int checkSum = 0;
+
+        for (int e : a) {
+            checkSum ^= e;
+        }
+        return checkSum;
+    }
+
+    private int checkSumXor(long[] a) {
+        long checkSum = 0;
+
+        for (long e : a) {
+            checkSum ^= e;
+        }
+        return (int) checkSum;
+    }
+
+    private int checkSumXor(byte[] a) {
+        byte checkSum = 0;
+
+        for (byte e : a) {
+            checkSum ^= e;
+        }
+        return (int) checkSum;
+    }
+
+    private int checkSumXor(char[] a) {
+        char checkSum = 0;
+
+        for (char e : a) {
+            checkSum ^= e;
+        }
+        return (int) checkSum;
+    }
+
+    private int checkSumXor(short[] a) {
+        short checkSum = 0;
+
+        for (short e : a) {
+            checkSum ^= e;
+        }
+        return (int) checkSum;
+    }
+
+    private int checkSumXor(float[] a) {
+        int checkSum = 0;
+
+        for (float e : a) {
+            checkSum ^= (int) e;
+        }
+        return checkSum;
+    }
+
+    private int checkSumXor(double[] a) {
+        int checkSum = 0;
+
+        for (double e : a) {
+            checkSum ^= (int) e;
+        }
+        return checkSum;
+    }
+
+    private int checkSumPlus(Object a) {
+        if (a instanceof int[]) {
+            return checkSumPlus((int[]) a);
+        }
+        if (a instanceof long[]) {
+            return checkSumPlus((long[]) a);
+        }
+        if (a instanceof byte[]) {
+            return checkSumPlus((byte[]) a);
+        }
+        if (a instanceof char[]) {
+            return checkSumPlus((char[]) a);
+        }
+        if (a instanceof short[]) {
+            return checkSumPlus((short[]) a);
+        }
+        if (a instanceof float[]) {
+            return checkSumPlus((float[]) a);
+        }
+        if (a instanceof double[]) {
+            return checkSumPlus((double[]) a);
+        }
+        fail("Unknown type of array: " + a.getClass().getName());
+        return -1;
+    }
+
+    private int checkSumPlus(int[] a) {
+        int checkSum = 0;
+
+        for (int e : a) {
+            checkSum += e;
+        }
+        return checkSum;
+    }
+
+    private int checkSumPlus(long[] a) {
+        long checkSum = 0;
+
+        for (long e : a) {
+            checkSum += e;
+        }
+        return (int) checkSum;
+    }
+
+    private int checkSumPlus(byte[] a) {
+        byte checkSum = 0;
+
+        for (byte e : a) {
+            checkSum += e;
+        }
+        return (int) checkSum;
+    }
+
+    private int checkSumPlus(char[] a) {
+        char checkSum = 0;
+
+        for (char e : a) {
+            checkSum += e;
+        }
+        return (int) checkSum;
+    }
+
+    private int checkSumPlus(short[] a) {
+        short checkSum = 0;
+
+        for (short e : a) {
+            checkSum += e;
+        }
+        return (int) checkSum;
+    }
+
+    private int checkSumPlus(float[] a) {
+        int checkSum = 0;
+
+        for (float e : a) {
+            checkSum += (int) e;
+        }
+        return checkSum;
+    }
+
+    private int checkSumPlus(double[] a) {
+        int checkSum = 0;
+
+        for (double e : a) {
+            checkSum += (int) e;
+        }
+        return checkSum;
+    }
+
+    private void sortByInsertionSort(Object a) {
+        if (a instanceof int[]) {
+            sortByInsertionSort((int[]) a);
+        } else if (a instanceof long[]) {
+            sortByInsertionSort((long[]) a);
+        } else if (a instanceof byte[]) {
+            sortByInsertionSort((byte[]) a);
+        } else if (a instanceof char[]) {
+            sortByInsertionSort((char[]) a);
+        } else if (a instanceof short[]) {
+            sortByInsertionSort((short[]) a);
+        } else if (a instanceof float[]) {
+            sortByInsertionSort((float[]) a);
+        } else if (a instanceof double[]) {
+            sortByInsertionSort((double[]) a);
+        } else {
+            fail("Unknown type of array: " + a.getClass().getName());
+        }
+    }
+
+    private void sortByInsertionSort(int[] a) {
+        for (int j, i = 1; i < a.length; i++) {
+            int ai = a[i];
+
+            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
+                a[j + 1] = a[j];
+            }
+            a[j + 1] = ai;
+        }
+    }
+
+    private void sortByInsertionSort(long[] a) {
+        for (int j, i = 1; i < a.length; i++) {
+            long ai = a[i];
+
+            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
+                a[j + 1] = a[j];
+            }
+            a[j + 1] = ai;
+        }
+    }
+
+    private void sortByInsertionSort(byte[] a) {
+        for (int j, i = 1; i < a.length; i++) {
+            byte ai = a[i];
+
+            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
+                a[j + 1] = a[j];
+            }
+            a[j + 1] = ai;
+        }
+    }
+
+    private void sortByInsertionSort(char[] a) {
+        for (int j, i = 1; i < a.length; i++) {
+            char ai = a[i];
+
+            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
+                a[j + 1] = a[j];
+            }
+            a[j + 1] = ai;
+        }
+    }
+
+    private void sortByInsertionSort(short[] a) {
+        for (int j, i = 1; i < a.length; i++) {
+            short ai = a[i];
+
+            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
+                a[j + 1] = a[j];
+            }
+            a[j + 1] = ai;
+        }
+    }
+
+    private void sortByInsertionSort(float[] a) {
+        for (int j, i = 1; i < a.length; i++) {
+            float ai = a[i];
+
+            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
+                a[j + 1] = a[j];
+            }
+            a[j + 1] = ai;
+        }
+    }
+
+    private void sortByInsertionSort(double[] a) {
+        for (int j, i = 1; i < a.length; i++) {
+            double ai = a[i];
+
+            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
+                a[j + 1] = a[j];
+            }
+            a[j + 1] = ai;
+        }
+    }
+
+    private void checkSubArray(Object a, int fromIndex, int toIndex) {
+        if (a instanceof int[]) {
+            checkSubArray((int[]) a, fromIndex, toIndex);
+        } else if (a instanceof long[]) {
+            checkSubArray((long[]) a, fromIndex, toIndex);
+        } else if (a instanceof byte[]) {
+            checkSubArray((byte[]) a, fromIndex, toIndex);
+        } else if (a instanceof char[]) {
+            checkSubArray((char[]) a, fromIndex, toIndex);
+        } else if (a instanceof short[]) {
+            checkSubArray((short[]) a, fromIndex, toIndex);
+        } else if (a instanceof float[]) {
+            checkSubArray((float[]) a, fromIndex, toIndex);
+        } else if (a instanceof double[]) {
+            checkSubArray((double[]) a, fromIndex, toIndex);
+        } else {
+            fail("Unknown type of array: " + a.getClass().getName());
+        }
+    }
+
+    private void checkSubArray(int[] a, int fromIndex, int toIndex) {
+        for (int i = 0; i < fromIndex; i++) {
+            if (a[i] != A380) {
+                fail("Range sort changes left element at position " + i + hex(a[i], A380));
+            }
+        }
+
+        for (int i = fromIndex; i < toIndex - 1; i++) {
+            if (a[i] > a[i + 1]) {
+                fail("Array is not sorted at " + i + "-th position: " + a[i] + " and " + a[i + 1]);
+            }
+        }
+
+        for (int i = toIndex; i < a.length; i++) {
+            if (a[i] != B747) {
+                fail("Range sort changes right element at position " + i + hex(a[i], B747));
+            }
+        }
+    }
+
+    private void checkSubArray(long[] a, int fromIndex, int toIndex) {
+        for (int i = 0; i < fromIndex; i++) {
+            if (a[i] != (long) A380) {
+                fail("Range sort changes left element at position " + i + hex(a[i], A380));
+            }
+        }
 
-                while (true) {
-                    for (int t = 1; t <= period; t++) {
-                        if (i >= a.length) {
-                            return;
-                        }
-                        a[i++] = k;
-                    }
-                    if (i >= a.length) {
-                        return;
-                    }
-                    k++;
+        for (int i = fromIndex; i < toIndex - 1; i++) {
+            if (a[i] > a[i + 1]) {
+                fail("Array is not sorted at " + i + "-th position: " + a[i] + " and " + a[i + 1]);
+            }
+        }
+
+        for (int i = toIndex; i < a.length; i++) {
+            if (a[i] != (long) B747) {
+                fail("Range sort changes right element at position " + i + hex(a[i], B747));
+            }
+        }
+    }
+
+    private void checkSubArray(byte[] a, int fromIndex, int toIndex) {
+        for (int i = 0; i < fromIndex; i++) {
+            if (a[i] != (byte) A380) {
+                fail("Range sort changes left element at position " + i + hex(a[i], A380));
+            }
+        }
+
+        for (int i = fromIndex; i < toIndex - 1; i++) {
+            if (a[i] > a[i + 1]) {
+                fail("Array is not sorted at " + i + "-th position: " + a[i] + " and " + a[i + 1]);
+            }
+        }
+
+        for (int i = toIndex; i < a.length; i++) {
+            if (a[i] != (byte) B747) {
+                fail("Range sort changes right element at position " + i + hex(a[i], B747));
+            }
+        }
+    }
+
+    private void checkSubArray(char[] a, int fromIndex, int toIndex) {
+        for (int i = 0; i < fromIndex; i++) {
+            if (a[i] != (char) A380) {
+                fail("Range sort changes left element at position " + i + hex(a[i], A380));
+            }
+        }
+
+        for (int i = fromIndex; i < toIndex - 1; i++) {
+            if (a[i] > a[i + 1]) {
+                fail("Array is not sorted at " + i + "-th position: " + a[i] + " and " + a[i + 1]);
+            }
+        }
+
+        for (int i = toIndex; i < a.length; i++) {
+            if (a[i] != (char) B747) {
+                fail("Range sort changes right element at position " + i + hex(a[i], B747));
+            }
+        }
+    }
+
+    private void checkSubArray(short[] a, int fromIndex, int toIndex) {
+        for (int i = 0; i < fromIndex; i++) {
+            if (a[i] != (short) A380) {
+                fail("Range sort changes left element at position " + i + hex(a[i], A380));
+            }
+        }
+
+        for (int i = fromIndex; i < toIndex - 1; i++) {
+            if (a[i] > a[i + 1]) {
+                fail("Array is not sorted at " + i + "-th position: " + a[i] + " and " + a[i + 1]);
+            }
+        }
+
+        for (int i = toIndex; i < a.length; i++) {
+            if (a[i] != (short) B747) {
+                fail("Range sort changes right element at position " + i + hex(a[i], B747));
+            }
+        }
+    }
+
+    private void checkSubArray(float[] a, int fromIndex, int toIndex) {
+        for (int i = 0; i < fromIndex; i++) {
+            if (a[i] != (float) A380) {
+                fail("Range sort changes left element at position " + i + hex((long) a[i], A380));
+            }
+        }
+
+        for (int i = fromIndex; i < toIndex - 1; i++) {
+            if (a[i] > a[i + 1]) {
+                fail("Array is not sorted at " + i + "-th position: " + a[i] + " and " + a[i + 1]);
+            }
+        }
+
+        for (int i = toIndex; i < a.length; i++) {
+            if (a[i] != (float) B747) {
+                fail("Range sort changes right element at position " + i + hex((long) a[i], B747));
+            }
+        }
+    }
+
+    private void checkSubArray(double[] a, int fromIndex, int toIndex) {
+        for (int i = 0; i < fromIndex; i++) {
+            if (a[i] != (double) A380) {
+                fail("Range sort changes left element at position " + i + hex((long) a[i], A380));
+            }
+        }
+
+        for (int i = fromIndex; i < toIndex - 1; i++) {
+            if (a[i] > a[i + 1]) {
+                fail("Array is not sorted at " + i + "-th position: " + a[i] + " and " + a[i + 1]);
+            }
+        }
+
+        for (int i = toIndex; i < a.length; i++) {
+            if (a[i] != (double) B747) {
+                fail("Range sort changes right element at position " + i + hex((long) a[i], B747));
+            }
+        }
+    }
+
+    private void checkRange(Object a, int m) {
+        if (a instanceof int[]) {
+            checkRange((int[]) a, m);
+        } else if (a instanceof long[]) {
+            checkRange((long[]) a, m);
+        } else if (a instanceof byte[]) {
+            checkRange((byte[]) a, m);
+        } else if (a instanceof char[]) {
+            checkRange((char[]) a, m);
+        } else if (a instanceof short[]) {
+            checkRange((short[]) a, m);
+        } else if (a instanceof float[]) {
+            checkRange((float[]) a, m);
+        } else if (a instanceof double[]) {
+            checkRange((double[]) a, m);
+        } else {
+            fail("Unknown type of array: " + a.getClass().getName());
+        }
+    }
+
+    private void checkRange(int[] a, int m) {
+        try {
+            sortingHelper.sort(a, m + 1, m);
+            fail(sortingHelper + " does not throw IllegalArgumentException " +
+                "as expected: fromIndex = " + (m + 1) + " toIndex = " + m);
+        } catch (IllegalArgumentException iae) {
+            try {
+                sortingHelper.sort(a, -m, a.length);
+                fail(sortingHelper + " does not throw ArrayIndexOutOfBoundsException " +
+                    "as expected: fromIndex = " + (-m));
+            } catch (ArrayIndexOutOfBoundsException aoe) {
+                try {
+                    sortingHelper.sort(a, 0, a.length + m);
+                    fail(sortingHelper + " does not throw ArrayIndexOutOfBoundsException " +
+                        "as expected: toIndex = " + (a.length + m));
+                } catch (ArrayIndexOutOfBoundsException expected) {}
+            }
+        }
+    }
+
+    private void checkRange(long[] a, int m) {
+        try {
+            sortingHelper.sort(a, m + 1, m);
+            fail(sortingHelper + " does not throw IllegalArgumentException " +
+                "as expected: fromIndex = " + (m + 1) + " toIndex = " + m);
+        } catch (IllegalArgumentException iae) {
+            try {
+                sortingHelper.sort(a, -m, a.length);
+                fail(sortingHelper + " does not throw ArrayIndexOutOfBoundsException " +
+                    "as expected: fromIndex = " + (-m));
+            } catch (ArrayIndexOutOfBoundsException aoe) {
+                try {
+                    sortingHelper.sort(a, 0, a.length + m);
+                    fail(sortingHelper + " does not throw ArrayIndexOutOfBoundsException " +
+                        "as expected: toIndex = " + (a.length + m));
+                } catch (ArrayIndexOutOfBoundsException expected) {}
+            }
+        }
+    }
+
+    private void checkRange(byte[] a, int m) {
+        try {
+            sortingHelper.sort(a, m + 1, m);
+            fail(sortingHelper + " does not throw IllegalArgumentException " +
+                "as expected: fromIndex = " + (m + 1) + " toIndex = " + m);
+        } catch (IllegalArgumentException iae) {
+            try {
+                sortingHelper.sort(a, -m, a.length);
+                fail(sortingHelper + " does not throw ArrayIndexOutOfBoundsException " +
+                    "as expected: fromIndex = " + (-m));
+            } catch (ArrayIndexOutOfBoundsException aoe) {
+                try {
+                    sortingHelper.sort(a, 0, a.length + m);
+                    fail(sortingHelper + " does not throw ArrayIndexOutOfBoundsException " +
+                        "as expected: toIndex = " + (a.length + m));
+                } catch (ArrayIndexOutOfBoundsException expected) {}
+            }
+        }
+    }
+
+    private void checkRange(char[] a, int m) {
+        try {
+            sortingHelper.sort(a, m + 1, m);
+            fail(sortingHelper + " does not throw IllegalArgumentException " +
+                "as expected: fromIndex = " + (m + 1) + " toIndex = " + m);
+        } catch (IllegalArgumentException iae) {
+            try {
+                sortingHelper.sort(a, -m, a.length);
+                fail(sortingHelper + " does not throw ArrayIndexOutOfBoundsException " +
+                    "as expected: fromIndex = " + (-m));
+            } catch (ArrayIndexOutOfBoundsException aoe) {
+                try {
+                    sortingHelper.sort(a, 0, a.length + m);
+                    fail(sortingHelper + " does not throw ArrayIndexOutOfBoundsException " +
+                        "as expected: toIndex = " + (a.length + m));
+                } catch (ArrayIndexOutOfBoundsException expected) {}
+            }
+        }
+    }
+
+    private void checkRange(short[] a, int m) {
+        try {
+            sortingHelper.sort(a, m + 1, m);
+            fail(sortingHelper + " does not throw IllegalArgumentException " +
+                "as expected: fromIndex = " + (m + 1) + " toIndex = " + m);
+        } catch (IllegalArgumentException iae) {
+            try {
+                sortingHelper.sort(a, -m, a.length);
+                fail(sortingHelper + " does not throw ArrayIndexOutOfBoundsException " +
+                    "as expected: fromIndex = " + (-m));
+            } catch (ArrayIndexOutOfBoundsException aoe) {
+                try {
+                    sortingHelper.sort(a, 0, a.length + m);
+                    fail(sortingHelper + " does not throw ArrayIndexOutOfBoundsException " +
+                        "as expected: toIndex = " + (a.length + m));
+                } catch (ArrayIndexOutOfBoundsException expected) {}
+            }
+        }
+    }
+
+    private void checkRange(float[] a, int m) {
+        try {
+            sortingHelper.sort(a, m + 1, m);
+            fail(sortingHelper + " does not throw IllegalArgumentException " +
+                "as expected: fromIndex = " + (m + 1) + " toIndex = " + m);
+        } catch (IllegalArgumentException iae) {
+            try {
+                sortingHelper.sort(a, -m, a.length);
+                fail(sortingHelper + " does not throw ArrayIndexOutOfBoundsException " +
+                    "as expected: fromIndex = " + (-m));
+            } catch (ArrayIndexOutOfBoundsException aoe) {
+                try {
+                    sortingHelper.sort(a, 0, a.length + m);
+                    fail(sortingHelper + " does not throw ArrayIndexOutOfBoundsException " +
+                        "as expected: toIndex = " + (a.length + m));
+                } catch (ArrayIndexOutOfBoundsException expected) {}
+            }
+        }
+    }
+
+    private void checkRange(double[] a, int m) {
+        try {
+            sortingHelper.sort(a, m + 1, m);
+            fail(sortingHelper + " does not throw IllegalArgumentException " +
+                "as expected: fromIndex = " + (m + 1) + " toIndex = " + m);
+        } catch (IllegalArgumentException iae) {
+            try {
+                sortingHelper.sort(a, -m, a.length);
+                fail(sortingHelper + " does not throw ArrayIndexOutOfBoundsException " +
+                    "as expected: fromIndex = " + (-m));
+            } catch (ArrayIndexOutOfBoundsException aoe) {
+                try {
+                    sortingHelper.sort(a, 0, a.length + m);
+                    fail(sortingHelper + " does not throw ArrayIndexOutOfBoundsException " +
+                        "as expected: toIndex = " + (a.length + m));
+                } catch (ArrayIndexOutOfBoundsException expected) {}
+            }
+        }
+    }
+
+    private void copy(Object dst, Object src) {
+        if (src instanceof float[]) {
+            copy((float[]) dst, (float[]) src);
+        } else if (src instanceof double[]) {
+            copy((double[]) dst, (double[]) src);
+        } else {
+            fail("Unknown type of array: " + src.getClass().getName());
+        }
+    }
+
+    private void copy(float[] dst, float[] src) {
+        System.arraycopy(src, 0, dst, 0, src.length);
+    }
+
+    private void copy(double[] dst, double[] src) {
+        System.arraycopy(src, 0, dst, 0, src.length);
+    }
+
+    private void printTestName(String test, TestRandom random, int length) {
+        printTestName(test, random, length, "");
+    }
+
+    private void createData(int length) {
+        gold = new Object[] {
+            new int[length], new long[length],
+            new byte[length], new char[length], new short[length],
+            new float[length], new double[length]
+        };
+
+        test = new Object[] {
+            new int[length], new long[length],
+            new byte[length], new char[length], new short[length],
+            new float[length], new double[length]
+        };
+    }
+
+    private void convertData(int length) {
+        for (int i = 1; i < gold.length; i++) {
+            TypeConverter converter = TypeConverter.values()[i - 1];
+            converter.convert((int[])gold[0], gold[i]);
+        }
+
+        for (int i = 0; i < gold.length; i++) {
+            System.arraycopy(gold[i], 0, test[i], 0, length);
+        }
+    }
+
+    private String hex(long a, int b) {
+        return ": " + Long.toHexString(a) + ", must be " + Integer.toHexString(b);
+    }
+
+    private void printTestName(String test, TestRandom random, int length, String message) {
+        out.println( "[" + sortingHelper + "] '" + test +
+            "' length = " + length + ", random = " + random + message);
+    }
+
+    private static enum TypeConverter {
+        LONG {
+            void convert(int[] src, Object dst) {
+                long[] b = (long[]) dst;
+
+                for (int i = 0; i < src.length; i++) {
+                    b[i] = (long) src[i];
                 }
             }
         },
-        ORGAN_PIPES {
-            void build(int[] a, int m) {
-                int i = 0;
-                int k = m;
+
+        BYTE {
+            void convert(int[] src, Object dst) {
+                byte[] b = (byte[]) dst;
+
+                for (int i = 0; i < src.length; i++) {
+                    b[i] = (byte) src[i];
+                }
+            }
+        },
+
+        CHAR {
+            void convert(int[] src, Object dst) {
+                char[] b = (char[]) dst;
+
+                for (int i = 0; i < src.length; i++) {
+                    b[i] = (char) src[i];
+                }
+            }
+        },
+
+        SHORT {
+            void convert(int[] src, Object dst) {
+                short[] b = (short[]) dst;
+
+                for (int i = 0; i < src.length; i++) {
+                    b[i] = (short) src[i];
+                }
+            }
+        },
 
-                while (true) {
-                    for (int t = 1; t <= m; t++) {
-                        if (i >= a.length) {
-                            return;
-                        }
-                        a[i++] = k;
-                    }
+        FLOAT {
+            void convert(int[] src, Object dst) {
+                float[] b = (float[]) dst;
+
+                for (int i = 0; i < src.length; i++) {
+                    b[i] = (float) src[i];
+                }
+            }
+        },
+
+        DOUBLE {
+            void convert(int[] src, Object dst) {
+                double[] b = (double[]) dst;
+
+                for (int i = 0; i < src.length; i++) {
+                    b[i] = (double) src[i];
+                }
+            }
+        };
+
+        abstract void convert(int[] src, Object dst);
+    }
+
+    private static enum SortedBuilder {
+        STEPS {
+            void build(int[] a, int m) {
+                for (int i = 0; i < m; i++) {
+                    a[i] = 0;
+                }
+
+                for (int i = m; i < a.length; i++) {
+                    a[i] = 1;
                 }
             }
         };
 
         abstract void build(int[] a, int m);
-
-        @Override public String toString() {
-            String name = name();
-
-            for (int i = name.length(); i < 12; i++) {
-                name += " ";
-            }
-            return name;
-        }
-    }
-
-    private static enum MergeBuilder {
-        ASCENDING {
-            void build(int[] a, int m) {
-                int period = a.length / m;
-                int v = 1, i = 0;
-
-                for (int k = 0; k < m; k++) {
-                    v = 1;
-                    for (int p = 0; p < period; p++) {
-                        a[i++] = v++;
-                    }
-                }
-                for (int j = i; j < a.length - 1; j++) {
-                    a[j] = v++;
-                }
-                a[a.length - 1] = 0;
-            }
-        },
-        DESCENDING {
-            void build(int[] a, int m) {
-                int period = a.length / m;
-                int v = -1, i = 0;
-
-                for (int k = 0; k < m; k++) {
-                    v = -1;
-                    for (int p = 0; p < period; p++) {
-                        a[i++] = v--;
-                    }
-                }
-                for (int j = i; j < a.length - 1; j++) {
-                    a[j] = v--;
-                }
-                a[a.length - 1] = 0;
-            }
-        };
-
-        abstract void build(int[] a, int m);
-
-        @Override public String toString() {
-            String name = name();
-
-            for (int i = name.length(); i < 12; i++) {
-                name += " ";
-            }
-            return name;
-        }
     }
 
     private static enum UnsortedBuilder {
@@ -894,6 +1649,7 @@
                 }
             }
         },
+
         ASCENDING {
             void build(int[] a, int m, Random random) {
                 for (int i = 0; i < a.length; i++) {
@@ -901,6 +1657,7 @@
                 }
             }
         },
+
         DESCENDING {
             void build(int[] a, int m, Random random) {
                 for (int i = 0; i < a.length; i++) {
@@ -908,13 +1665,15 @@
                 }
             }
         },
-        ALL_EQUAL {
+
+        EQUAL {
             void build(int[] a, int m, Random random) {
                 for (int i = 0; i < a.length; i++) {
                     a[i] = m;
                 }
             }
         },
+
         SAW {
             void build(int[] a, int m, Random random) {
                 int incCount = 1;
@@ -941,6 +1700,7 @@
                 }
             }
         },
+
         REPEATED {
             void build(int[] a, int m, Random random) {
                 for (int i = 0; i < a.length; i++) {
@@ -948,6 +1708,7 @@
                 }
             }
         },
+
         DUPLICATED {
             void build(int[] a, int m, Random random) {
                 for (int i = 0; i < a.length; i++) {
@@ -955,6 +1716,7 @@
                 }
             }
         },
+
         ORGAN_PIPES {
             void build(int[] a, int m, Random random) {
                 int middle = a.length / (m + 1);
@@ -962,11 +1724,13 @@
                 for (int i = 0; i < middle; i++) {
                     a[i] = i;
                 }
+
                 for (int i = middle; i < a.length; i++) {
                     a[i] = a.length - i - 1;
                 }
             }
         },
+
         STAGGER {
             void build(int[] a, int m, Random random) {
                 for (int i = 0; i < a.length; i++) {
@@ -974,6 +1738,7 @@
                 }
             }
         },
+
         PLATEAU {
             void build(int[] a, int m, Random random) {
                 for (int i = 0; i < a.length; i++) {
@@ -981,1064 +1746,271 @@
                 }
             }
         },
+
         SHUFFLE {
             void build(int[] a, int m, Random random) {
                 int x = 0, y = 0;
+
                 for (int i = 0; i < a.length; i++) {
                     a[i] = random.nextBoolean() ? (x += 2) : (y += 2);
                 }
             }
+        },
+
+        LATCH {
+            void build(int[] a, int m, Random random) {
+                int max = a.length / m;
+                max = max < 2 ? 2 : max;
+
+                for (int i = 0; i < a.length; i++) {
+                    a[i] = i % max;
+                }
+            }
         };
 
         abstract void build(int[] a, int m, Random random);
-
-        @Override public String toString() {
-            String name = name();
-
-            for (int i = name.length(); i < 12; i++) {
-                name += " ";
-            }
-            return name;
-        }
-    }
-
-    private static void checkWithCheckSum(Object test, Object golden) {
-        checkSorted(test);
-        checkCheckSum(test, golden);
-    }
-
-    private static void failed(String message) {
-        err.format("\n*** TEST FAILED - %s.\n\n%s.\n\n", ourDescription, message);
-        throw new RuntimeException("Test failed - see log file for details");
-    }
-
-    private static void failedSort(int index, String value1, String value2) {
-        failed("Array is not sorted at " + index + "-th position: " +
-            value1 + " and " + value2);
-    }
-
-    private static void failedCompare(int index, String value1, String value2) {
-        failed("On position " + index + " must be " + value2 + " instead of " + value1);
-    }
-
-    private static void compare(Object test, Object golden) {
-        if (test instanceof int[]) {
-            compare((int[]) test, (int[]) golden);
-        } else if (test instanceof long[]) {
-            compare((long[]) test, (long[]) golden);
-        } else if (test instanceof short[]) {
-            compare((short[]) test, (short[]) golden);
-        } else if (test instanceof byte[]) {
-            compare((byte[]) test, (byte[]) golden);
-        } else if (test instanceof char[]) {
-            compare((char[]) test, (char[]) golden);
-        } else if (test instanceof float[]) {
-            compare((float[]) test, (float[]) golden);
-        } else if (test instanceof double[]) {
-            compare((double[]) test, (double[]) golden);
-        } else if (test instanceof Integer[]) {
-            compare((Integer[]) test, (Integer[]) golden);
-        } else {
-            failed("Unknow type of array: " + test + " of class " +
-                test.getClass().getName());
-        }
-    }
-
-    private static void compare(int[] a, int[] b) {
-        for (int i = 0; i < a.length; i++) {
-            if (a[i] != b[i]) {
-                failedCompare(i, "" + a[i], "" + b[i]);
-            }
-        }
-    }
-
-    private static void compare(long[] a, long[] b) {
-        for (int i = 0; i < a.length; i++) {
-            if (a[i] != b[i]) {
-                failedCompare(i, "" + a[i], "" + b[i]);
-            }
-        }
-    }
-
-    private static void compare(short[] a, short[] b) {
-        for (int i = 0; i < a.length; i++) {
-            if (a[i] != b[i]) {
-                failedCompare(i, "" + a[i], "" + b[i]);
-            }
-        }
-    }
-
-    private static void compare(byte[] a, byte[] b) {
-        for (int i = 0; i < a.length; i++) {
-            if (a[i] != b[i]) {
-                failedCompare(i, "" + a[i], "" + b[i]);
-            }
-        }
-    }
-
-    private static void compare(char[] a, char[] b) {
-        for (int i = 0; i < a.length; i++) {
-            if (a[i] != b[i]) {
-                failedCompare(i, "" + a[i], "" + b[i]);
-            }
-        }
     }
 
-    private static void compare(float[] a, float[] b) {
-        for (int i = 0; i < a.length; i++) {
-            if (a[i] != b[i]) {
-                failedCompare(i, "" + a[i], "" + b[i]);
-            }
-        }
-    }
+    private static enum MergingBuilder {
+        ASCENDING {
+            void build(int[] a, int m) {
+                int period = a.length / m;
+                int v = 1, i = 0;
+
+                for (int k = 0; k < m; k++) {
+                    v = 1;
 
-    private static void compare(double[] a, double[] b) {
-        for (int i = 0; i < a.length; i++) {
-            if (a[i] != b[i]) {
-                failedCompare(i, "" + a[i], "" + b[i]);
-            }
-        }
-    }
+                    for (int p = 0; p < period; p++) {
+                        a[i++] = v++;
+                    }
+                }
 
-    private static void compare(Integer[] a, Integer[] b) {
-        for (int i = 0; i < a.length; i++) {
-            if (a[i].compareTo(b[i]) != 0) {
-                failedCompare(i, "" + a[i], "" + b[i]);
-            }
-        }
-    }
+                for (int j = i; j < a.length - 1; j++) {
+                    a[j] = v++;
+                }
 
-    private static void checkSorted(Object object) {
-        if (object instanceof int[]) {
-            checkSorted((int[]) object);
-        } else if (object instanceof long[]) {
-            checkSorted((long[]) object);
-        } else if (object instanceof short[]) {
-            checkSorted((short[]) object);
-        } else if (object instanceof byte[]) {
-            checkSorted((byte[]) object);
-        } else if (object instanceof char[]) {
-            checkSorted((char[]) object);
-        } else if (object instanceof float[]) {
-            checkSorted((float[]) object);
-        } else if (object instanceof double[]) {
-            checkSorted((double[]) object);
-        } else if (object instanceof Integer[]) {
-            checkSorted((Integer[]) object);
-        } else {
-            failed("Unknow type of array: " + object + " of class " +
-                object.getClass().getName());
-        }
-    }
+                a[a.length - 1] = 0;
+            }
+        },
+
+        DESCENDING {
+            void build(int[] a, int m) {
+                int period = a.length / m;
+                int v = -1, i = 0;
 
-    private static void checkSorted(int[] a) {
-        for (int i = 0; i < a.length - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
+                for (int k = 0; k < m; k++) {
+                    v = -1;
+
+                    for (int p = 0; p < period; p++) {
+                        a[i++] = v--;
+                    }
+                }
+
+                for (int j = i; j < a.length - 1; j++) {
+                    a[j] = v--;
+                }
+
+                a[a.length - 1] = 0;
             }
-        }
-    }
-
-    private static void checkSorted(long[] a) {
-        for (int i = 0; i < a.length - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
-            }
-        }
-    }
+        },
 
-    private static void checkSorted(short[] a) {
-        for (int i = 0; i < a.length - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
+        POINT {
+            void build(int[] a, int m) {
+                for (int i = 0; i < a.length; i++) {
+                    a[i] = 0;
+                }
+                a[a.length / 2] = m;
             }
-        }
-    }
+        },
 
-    private static void checkSorted(byte[] a) {
-        for (int i = 0; i < a.length - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
+        LINE {
+            void build(int[] a, int m) {
+                for (int i = 0; i < a.length; i++) {
+                    a[i] = i;
+                }
+                reverse(a, 0, a.length - 1);
             }
-        }
-    }
+        },
 
-    private static void checkSorted(char[] a) {
-        for (int i = 0; i < a.length - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
-            }
-        }
-    }
-
-    private static void checkSorted(float[] a) {
-        for (int i = 0; i < a.length - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
+        PEARL {
+            void build(int[] a, int m) {
+                for (int i = 0; i < a.length; i++) {
+                    a[i] = i;
+                }
+                reverse(a, 0, 2);
             }
-        }
-    }
+        },
+
+        RING {
+            void build(int[] a, int m) {
+                int k1 = a.length / 3;
+                int k2 = a.length / 3 * 2;
+                int level = a.length / 3;
 
-    private static void checkSorted(double[] a) {
-        for (int i = 0; i < a.length - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
+                for (int i = 0, k = level; i < k1; i++) {
+                    a[i] = k--;
+                }
+
+                for (int i = k1; i < k2; i++) {
+                    a[i] = 0;
+                }
+
+                for (int i = k2, k = level; i < a.length; i++) {
+                    a[i] = k--;
+                }
             }
-        }
-    }
+        };
+
+        abstract void build(int[] a, int m);
 
-    private static void checkSorted(Integer[] a) {
-        for (int i = 0; i < a.length - 1; i++) {
-            if (a[i].intValue() > a[i + 1].intValue()) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
+        private static void reverse(int[] a, int lo, int hi) {
+            for (--hi; lo < hi; ) {
+                int tmp = a[lo];
+                a[lo++] = a[hi];
+                a[hi--] = tmp;
             }
         }
     }
 
-    private static void checkCheckSum(Object test, Object golden) {
-        if (checkSumXor(test) != checkSumXor(golden)) {
-            failed("Original and sorted arrays are not identical [xor]");
-        }
-        if (checkSumPlus(test) != checkSumPlus(golden)) {
-            failed("Original and sorted arrays are not identical [plus]");
-        }
-    }
-
-    private static int checkSumXor(Object object) {
-        if (object instanceof int[]) {
-            return checkSumXor((int[]) object);
-        } else if (object instanceof long[]) {
-            return checkSumXor((long[]) object);
-        } else if (object instanceof short[]) {
-            return checkSumXor((short[]) object);
-        } else if (object instanceof byte[]) {
-            return checkSumXor((byte[]) object);
-        } else if (object instanceof char[]) {
-            return checkSumXor((char[]) object);
-        } else if (object instanceof float[]) {
-            return checkSumXor((float[]) object);
-        } else if (object instanceof double[]) {
-            return checkSumXor((double[]) object);
-        } else if (object instanceof Integer[]) {
-            return checkSumXor((Integer[]) object);
-        } else {
-            failed("Unknow type of array: " + object + " of class " +
-                object.getClass().getName());
-            return -1;
-        }
-    }
-
-    private static int checkSumXor(Integer[] a) {
-        int checkSum = 0;
-
-        for (Integer e : a) {
-            checkSum ^= e.intValue();
-        }
-        return checkSum;
-    }
-
-    private static int checkSumXor(int[] a) {
-        int checkSum = 0;
+    private static enum NegativeZeroBuilder {
+        FLOAT {
+            void build(Object o, Random random) {
+                float[] a = (float[]) o;
 
-        for (int e : a) {
-            checkSum ^= e;
-        }
-        return checkSum;
-    }
-
-    private static int checkSumXor(long[] a) {
-        long checkSum = 0;
-
-        for (long e : a) {
-            checkSum ^= e;
-        }
-        return (int) checkSum;
-    }
-
-    private static int checkSumXor(short[] a) {
-        short checkSum = 0;
-
-        for (short e : a) {
-            checkSum ^= e;
-        }
-        return (int) checkSum;
-    }
-
-    private static int checkSumXor(byte[] a) {
-        byte checkSum = 0;
-
-        for (byte e : a) {
-            checkSum ^= e;
-        }
-        return (int) checkSum;
-    }
-
-    private static int checkSumXor(char[] a) {
-        char checkSum = 0;
-
-        for (char e : a) {
-            checkSum ^= e;
-        }
-        return (int) checkSum;
-    }
-
-    private static int checkSumXor(float[] a) {
-        int checkSum = 0;
+                for (int i = 0; i < a.length; i++) {
+                    a[i] = random.nextBoolean() ? -0.0f : 0.0f;
+                }
+            }
+        },
 
-        for (float e : a) {
-            checkSum ^= (int) e;
-        }
-        return checkSum;
-    }
-
-    private static int checkSumXor(double[] a) {
-        int checkSum = 0;
-
-        for (double e : a) {
-            checkSum ^= (int) e;
-        }
-        return checkSum;
-    }
-
-    private static int checkSumPlus(Object object) {
-        if (object instanceof int[]) {
-            return checkSumPlus((int[]) object);
-        } else if (object instanceof long[]) {
-            return checkSumPlus((long[]) object);
-        } else if (object instanceof short[]) {
-            return checkSumPlus((short[]) object);
-        } else if (object instanceof byte[]) {
-            return checkSumPlus((byte[]) object);
-        } else if (object instanceof char[]) {
-            return checkSumPlus((char[]) object);
-        } else if (object instanceof float[]) {
-            return checkSumPlus((float[]) object);
-        } else if (object instanceof double[]) {
-            return checkSumPlus((double[]) object);
-        } else if (object instanceof Integer[]) {
-            return checkSumPlus((Integer[]) object);
-        } else {
-            failed("Unknow type of array: " + object + " of class " +
-                object.getClass().getName());
-            return -1;
-        }
-    }
-
-    private static int checkSumPlus(int[] a) {
-        int checkSum = 0;
+        DOUBLE {
+            void build(Object o, Random random) {
+                double[] a = (double[]) o;
 
-        for (int e : a) {
-            checkSum += e;
-        }
-        return checkSum;
-    }
-
-    private static int checkSumPlus(long[] a) {
-        long checkSum = 0;
-
-        for (long e : a) {
-            checkSum += e;
-        }
-        return (int) checkSum;
-    }
-
-    private static int checkSumPlus(short[] a) {
-        short checkSum = 0;
-
-        for (short e : a) {
-            checkSum += e;
-        }
-        return (int) checkSum;
-    }
+                for (int i = 0; i < a.length; i++) {
+                    a[i] = random.nextBoolean() ? -0.0d : 0.0d;
+                }
+            }
+        };
 
-    private static int checkSumPlus(byte[] a) {
-        byte checkSum = 0;
-
-        for (byte e : a) {
-            checkSum += e;
-        }
-        return (int) checkSum;
-    }
-
-    private static int checkSumPlus(char[] a) {
-        char checkSum = 0;
-
-        for (char e : a) {
-            checkSum += e;
-        }
-        return (int) checkSum;
-    }
-
-    private static int checkSumPlus(float[] a) {
-        int checkSum = 0;
-
-        for (float e : a) {
-            checkSum += (int) e;
-        }
-        return checkSum;
+        abstract void build(Object o, Random random);
     }
 
-    private static int checkSumPlus(double[] a) {
-        int checkSum = 0;
-
-        for (double e : a) {
-            checkSum += (int) e;
-        }
-        return checkSum;
-    }
-
-    private static int checkSumPlus(Integer[] a) {
-        int checkSum = 0;
-
-        for (Integer e : a) {
-            checkSum += e.intValue();
-        }
-        return checkSum;
-    }
+    private static enum FloatingPointBuilder {
+        FLOAT {
+            void build(Object o, int a, int g, int z, int n, int p, Random random) {
+                float negativeValue = -random.nextFloat();
+                float positiveValue =  random.nextFloat();
+                float[] x = (float[]) o;
+                int fromIndex = 0;
 
-    private static void sortByInsertionSort(Object object) {
-        if (object instanceof int[]) {
-            sortByInsertionSort((int[]) object);
-        } else if (object instanceof long[]) {
-            sortByInsertionSort((long[]) object);
-        } else if (object instanceof short[]) {
-            sortByInsertionSort((short[]) object);
-        } else if (object instanceof byte[]) {
-            sortByInsertionSort((byte[]) object);
-        } else if (object instanceof char[]) {
-            sortByInsertionSort((char[]) object);
-        } else if (object instanceof float[]) {
-            sortByInsertionSort((float[]) object);
-        } else if (object instanceof double[]) {
-            sortByInsertionSort((double[]) object);
-        } else if (object instanceof Integer[]) {
-            sortByInsertionSort((Integer[]) object);
-        } else {
-            failed("Unknow type of array: " + object + " of class " +
-                object.getClass().getName());
-        }
-    }
+                writeValue(x, negativeValue, fromIndex, n);
+                fromIndex += n;
 
-    private static void sortByInsertionSort(int[] a) {
-        for (int j, i = 1; i < a.length; i++) {
-            int ai = a[i];
-            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
-                a[j + 1] = a[j];
-            }
-            a[j + 1] = ai;
-        }
-    }
-
-    private static void sortByInsertionSort(long[] a) {
-        for (int j, i = 1; i < a.length; i++) {
-            long ai = a[i];
-            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
-                a[j + 1] = a[j];
-            }
-            a[j + 1] = ai;
-        }
-    }
+                writeValue(x, -0.0f, fromIndex, g);
+                fromIndex += g;
 
-    private static void sortByInsertionSort(short[] a) {
-        for (int j, i = 1; i < a.length; i++) {
-            short ai = a[i];
-            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
-                a[j + 1] = a[j];
-            }
-            a[j + 1] = ai;
-        }
-    }
+                writeValue(x, 0.0f, fromIndex, z);
+                fromIndex += z;
 
-    private static void sortByInsertionSort(byte[] a) {
-        for (int j, i = 1; i < a.length; i++) {
-            byte ai = a[i];
-            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
-                a[j + 1] = a[j];
-            }
-            a[j + 1] = ai;
-        }
-    }
+                writeValue(x, positiveValue, fromIndex, p);
+                fromIndex += p;
 
-    private static void sortByInsertionSort(char[] a) {
-        for (int j, i = 1; i < a.length; i++) {
-            char ai = a[i];
-            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
-                a[j + 1] = a[j];
-            }
-            a[j + 1] = ai;
-        }
-    }
-
-    private static void sortByInsertionSort(float[] a) {
-        for (int j, i = 1; i < a.length; i++) {
-            float ai = a[i];
-            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
-                a[j + 1] = a[j];
+                writeValue(x, Float.NaN, fromIndex, a);
             }
-            a[j + 1] = ai;
-        }
-    }
-
-    private static void sortByInsertionSort(double[] a) {
-        for (int j, i = 1; i < a.length; i++) {
-            double ai = a[i];
-            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
-                a[j + 1] = a[j];
-            }
-            a[j + 1] = ai;
-        }
-    }
+        },
 
-    private static void sortByInsertionSort(Integer[] a) {
-        for (int j, i = 1; i < a.length; i++) {
-            Integer ai = a[i];
-            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
-                a[j + 1] = a[j];
-            }
-            a[j + 1] = ai;
-        }
-    }
+        DOUBLE {
+            void build(Object o, int a, int g, int z, int n, int p, Random random) {
+                double negativeValue = -random.nextFloat();
+                double positiveValue =  random.nextFloat();
+                double[] x = (double[]) o;
+                int fromIndex = 0;
 
-    private static void sort(Object object) {
-        if (object instanceof int[]) {
-            Arrays.sort((int[]) object);
-        } else if (object instanceof long[]) {
-            Arrays.sort((long[]) object);
-        } else if (object instanceof short[]) {
-            Arrays.sort((short[]) object);
-        } else if (object instanceof byte[]) {
-            Arrays.sort((byte[]) object);
-        } else if (object instanceof char[]) {
-            Arrays.sort((char[]) object);
-        } else if (object instanceof float[]) {
-            Arrays.sort((float[]) object);
-        } else if (object instanceof double[]) {
-            Arrays.sort((double[]) object);
-        } else if (object instanceof Integer[]) {
-            Arrays.sort((Integer[]) object);
-        } else {
-            failed("Unknow type of array: " + object + " of class " +
-                object.getClass().getName());
-        }
-    }
+                writeValue(x, negativeValue, fromIndex, n);
+                fromIndex += n;
+
+                writeValue(x, -0.0d, fromIndex, g);
+                fromIndex += g;
 
-    private static void sortSubArray(Object object, int fromIndex, int toIndex) {
-        if (object instanceof int[]) {
-            Arrays.sort((int[]) object, fromIndex, toIndex);
-        } else if (object instanceof long[]) {
-            Arrays.sort((long[]) object, fromIndex, toIndex);
-        } else if (object instanceof short[]) {
-            Arrays.sort((short[]) object, fromIndex, toIndex);
-        } else if (object instanceof byte[]) {
-            Arrays.sort((byte[]) object, fromIndex, toIndex);
-        } else if (object instanceof char[]) {
-            Arrays.sort((char[]) object, fromIndex, toIndex);
-        } else if (object instanceof float[]) {
-            Arrays.sort((float[]) object, fromIndex, toIndex);
-        } else if (object instanceof double[]) {
-            Arrays.sort((double[]) object, fromIndex, toIndex);
-        } else if (object instanceof Integer[]) {
-            Arrays.sort((Integer[]) object, fromIndex, toIndex);
-        } else {
-            failed("Unknow type of array: " + object + " of class " +
-                object.getClass().getName());
-        }
-    }
+                writeValue(x, 0.0d, fromIndex, z);
+                fromIndex += z;
+
+                writeValue(x, positiveValue, fromIndex, p);
+                fromIndex += p;
 
-    private static void checkSubArray(Object object, int fromIndex, int toIndex, int m) {
-        if (object instanceof int[]) {
-            checkSubArray((int[]) object, fromIndex, toIndex, m);
-        } else if (object instanceof long[]) {
-            checkSubArray((long[]) object, fromIndex, toIndex, m);
-        } else if (object instanceof short[]) {
-            checkSubArray((short[]) object, fromIndex, toIndex, m);
-        } else if (object instanceof byte[]) {
-            checkSubArray((byte[]) object, fromIndex, toIndex, m);
-        } else if (object instanceof char[]) {
-            checkSubArray((char[]) object, fromIndex, toIndex, m);
-        } else if (object instanceof float[]) {
-            checkSubArray((float[]) object, fromIndex, toIndex, m);
-        } else if (object instanceof double[]) {
-            checkSubArray((double[]) object, fromIndex, toIndex, m);
-        } else if (object instanceof Integer[]) {
-            checkSubArray((Integer[]) object, fromIndex, toIndex, m);
-        } else {
-            failed("Unknow type of array: " + object + " of class " +
-                object.getClass().getName());
-        }
-    }
+                writeValue(x, Double.NaN, fromIndex, a);
+            }
+        };
 
-    private static void checkSubArray(Integer[] a, int fromIndex, int toIndex, int m) {
-        for (int i = 0; i < fromIndex; i++) {
-            if (a[i].intValue() != 0xDEDA) {
-                failed("Range sort changes left element on position " + i +
-                    ": " + a[i] + ", must be " + 0xDEDA);
+        abstract void build(Object o, int a, int g, int z, int n, int p, Random random);
+
+        private static void writeValue(float[] a, float value, int fromIndex, int count) {
+            for (int i = fromIndex; i < fromIndex + count; i++) {
+                a[i] = value;
             }
         }
 
-        for (int i = fromIndex; i < toIndex - 1; i++) {
-            if (a[i].intValue() > a[i + 1].intValue()) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
-            }
-        }
-
-        for (int i = toIndex; i < a.length; i++) {
-            if (a[i].intValue() != 0xBABA) {
-                failed("Range sort changes right element on position " + i +
-                    ": " + a[i] + ", must be " + 0xBABA);
-            }
-        }
-    }
-
-    private static void checkSubArray(int[] a, int fromIndex, int toIndex, int m) {
-        for (int i = 0; i < fromIndex; i++) {
-            if (a[i] != 0xDEDA) {
-                failed("Range sort changes left element on position " + i +
-                    ": " + a[i] + ", must be " + 0xDEDA);
-            }
-        }
-
-        for (int i = fromIndex; i < toIndex - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
-            }
-        }
-
-        for (int i = toIndex; i < a.length; i++) {
-            if (a[i] != 0xBABA) {
-                failed("Range sort changes right element on position " + i +
-                    ": " + a[i] + ", must be " + 0xBABA);
+        private static void writeValue(double[] a, double value, int fromIndex, int count) {
+            for (int i = fromIndex; i < fromIndex + count; i++) {
+                a[i] = value;
             }
         }
     }
 
-    private static void checkSubArray(byte[] a, int fromIndex, int toIndex, int m) {
-        for (int i = 0; i < fromIndex; i++) {
-            if (a[i] != (byte) 0xDEDA) {
-                failed("Range sort changes left element on position " + i +
-                    ": " + a[i] + ", must be " + 0xDEDA);
-            }
-        }
-
-        for (int i = fromIndex; i < toIndex - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
-            }
-        }
-
-        for (int i = toIndex; i < a.length; i++) {
-            if (a[i] != (byte) 0xBABA) {
-                failed("Range sort changes right element on position " + i +
-                    ": " + a[i] + ", must be " + 0xBABA);
-            }
-        }
-    }
-
-    private static void checkSubArray(long[] a, int fromIndex, int toIndex, int m) {
-        for (int i = 0; i < fromIndex; i++) {
-            if (a[i] != (long) 0xDEDA) {
-                failed("Range sort changes left element on position " + i +
-                    ": " + a[i] + ", must be " + 0xDEDA);
-            }
-        }
-
-        for (int i = fromIndex; i < toIndex - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
-            }
-        }
-
-        for (int i = toIndex; i < a.length; i++) {
-            if (a[i] != (long) 0xBABA) {
-                failed("Range sort changes right element on position " + i +
-                    ": " + a[i] + ", must be " + 0xBABA);
-            }
-        }
-    }
+    private static Comparator<Pair> pairComparator = new Comparator<Pair>() {
 
-    private static void checkSubArray(char[] a, int fromIndex, int toIndex, int m) {
-        for (int i = 0; i < fromIndex; i++) {
-            if (a[i] != (char) 0xDEDA) {
-                failed("Range sort changes left element on position " + i +
-                    ": " + a[i] + ", must be " + 0xDEDA);
-            }
+        @Override
+        public int compare(Pair p1, Pair p2) {
+            return p1.compareTo(p2);
         }
-
-        for (int i = fromIndex; i < toIndex - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
-            }
-        }
-
-        for (int i = toIndex; i < a.length; i++) {
-            if (a[i] != (char) 0xBABA) {
-                failed("Range sort changes right element on position " + i +
-                    ": " + a[i] + ", must be " + 0xBABA);
-            }
-        }
-    }
+    };
 
-    private static void checkSubArray(short[] a, int fromIndex, int toIndex, int m) {
-        for (int i = 0; i < fromIndex; i++) {
-            if (a[i] != (short) 0xDEDA) {
-                failed("Range sort changes left element on position " + i +
-                    ": " + a[i] + ", must be " + 0xDEDA);
-            }
-        }
-
-        for (int i = fromIndex; i < toIndex - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
-            }
-        }
+    private static class Pair implements Comparable<Pair> {
 
-        for (int i = toIndex; i < a.length; i++) {
-            if (a[i] != (short) 0xBABA) {
-                failed("Range sort changes right element on position " + i +
-                    ": " + a[i] + ", must be " + 0xBABA);
-            }
-        }
-    }
-
-    private static void checkSubArray(float[] a, int fromIndex, int toIndex, int m) {
-        for (int i = 0; i < fromIndex; i++) {
-            if (a[i] != (float) 0xDEDA) {
-                failed("Range sort changes left element on position " + i +
-                    ": " + a[i] + ", must be " + 0xDEDA);
-            }
-        }
-
-        for (int i = fromIndex; i < toIndex - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
-            }
+        private Pair(int key, int value) {
+            this.key = key;
+            this.value = value;
         }
 
-        for (int i = toIndex; i < a.length; i++) {
-            if (a[i] != (float) 0xBABA) {
-                failed("Range sort changes right element on position " + i +
-                    ": " + a[i] + ", must be " + 0xBABA);
-            }
-        }
-    }
-
-    private static void checkSubArray(double[] a, int fromIndex, int toIndex, int m) {
-        for (int i = 0; i < fromIndex; i++) {
-            if (a[i] != (double) 0xDEDA) {
-                failed("Range sort changes left element on position " + i +
-                    ": " + a[i] + ", must be " + 0xDEDA);
-            }
+        int getKey() {
+            return key;
         }
 
-        for (int i = fromIndex; i < toIndex - 1; i++) {
-            if (a[i] > a[i + 1]) {
-                failedSort(i, "" + a[i], "" + a[i + 1]);
-            }
+        int getValue() {
+            return value;
         }
 
-        for (int i = toIndex; i < a.length; i++) {
-            if (a[i] != (double) 0xBABA) {
-                failed("Range sort changes right element on position " + i +
-                    ": " + a[i] + ", must be " + 0xBABA);
-            }
+        @Override
+        public int compareTo(Pair pair) {
+            return Integer.compare(key, pair.key);
         }
-    }
-
-    private static void checkRange(Object object, int m) {
-        if (object instanceof int[]) {
-            checkRange((int[]) object, m);
-        } else if (object instanceof long[]) {
-            checkRange((long[]) object, m);
-        } else if (object instanceof short[]) {
-            checkRange((short[]) object, m);
-        } else if (object instanceof byte[]) {
-            checkRange((byte[]) object, m);
-        } else if (object instanceof char[]) {
-            checkRange((char[]) object, m);
-        } else if (object instanceof float[]) {
-            checkRange((float[]) object, m);
-        } else if (object instanceof double[]) {
-            checkRange((double[]) object, m);
-        } else if (object instanceof Integer[]) {
-            checkRange((Integer[]) object, m);
-        } else {
-            failed("Unknow type of array: " + object + " of class " +
-                object.getClass().getName());
-        }
-    }
-
-    private static void checkRange(Integer[] a, int m) {
-        try {
-            Arrays.sort(a, m + 1, m);
-
-            failed("Sort does not throw IllegalArgumentException " +
-                " as expected: fromIndex = " + (m + 1) +
-                " toIndex = " + m);
-        }
-        catch (IllegalArgumentException iae) {
-            try {
-                Arrays.sort(a, -m, a.length);
 
-                failed("Sort does not throw ArrayIndexOutOfBoundsException " +
-                    " as expected: fromIndex = " + (-m));
-            }
-            catch (ArrayIndexOutOfBoundsException aoe) {
-                try {
-                    Arrays.sort(a, 0, a.length + m);
-
-                    failed("Sort does not throw ArrayIndexOutOfBoundsException " +
-                        " as expected: toIndex = " + (a.length + m));
-                }
-                catch (ArrayIndexOutOfBoundsException aie) {
-                    return;
-                }
-            }
+        @Override
+        public String toString() {
+            return "(" + key + ", " + value + ")";
         }
-    }
-
-    private static void checkRange(int[] a, int m) {
-        try {
-            Arrays.sort(a, m + 1, m);
 
-            failed("Sort does not throw IllegalArgumentException " +
-                " as expected: fromIndex = " + (m + 1) +
-                " toIndex = " + m);
-        }
-        catch (IllegalArgumentException iae) {
-            try {
-                Arrays.sort(a, -m, a.length);
-
-                failed("Sort does not throw ArrayIndexOutOfBoundsException " +
-                    " as expected: fromIndex = " + (-m));
-            }
-            catch (ArrayIndexOutOfBoundsException aoe) {
-                try {
-                    Arrays.sort(a, 0, a.length + m);
-
-                    failed("Sort does not throw ArrayIndexOutOfBoundsException " +
-                        " as expected: toIndex = " + (a.length + m));
-                }
-                catch (ArrayIndexOutOfBoundsException aie) {
-                    return;
-                }
-            }
-        }
+        private int key;
+        private int value;
     }
 
-    private static void checkRange(long[] a, int m) {
-        try {
-            Arrays.sort(a, m + 1, m);
-
-            failed("Sort does not throw IllegalArgumentException " +
-                " as expected: fromIndex = " + (m + 1) +
-                " toIndex = " + m);
-        }
-        catch (IllegalArgumentException iae) {
-            try {
-                Arrays.sort(a, -m, a.length);
-
-                failed("Sort does not throw ArrayIndexOutOfBoundsException " +
-                    " as expected: fromIndex = " + (-m));
-            }
-            catch (ArrayIndexOutOfBoundsException aoe) {
-                try {
-                    Arrays.sort(a, 0, a.length + m);
-
-                    failed("Sort does not throw ArrayIndexOutOfBoundsException " +
-                        " as expected: toIndex = " + (a.length + m));
-                }
-                catch (ArrayIndexOutOfBoundsException aie) {
-                    return;
-                }
-            }
-        }
-    }
-
-    private static void checkRange(byte[] a, int m) {
-        try {
-            Arrays.sort(a, m + 1, m);
-
-            failed("Sort does not throw IllegalArgumentException " +
-                " as expected: fromIndex = " + (m + 1) +
-                " toIndex = " + m);
-        }
-        catch (IllegalArgumentException iae) {
-            try {
-                Arrays.sort(a, -m, a.length);
-
-                failed("Sort does not throw ArrayIndexOutOfBoundsException " +
-                    " as expected: fromIndex = " + (-m));
-            }
-            catch (ArrayIndexOutOfBoundsException aoe) {
-                try {
-                    Arrays.sort(a, 0, a.length + m);
-
-                    failed("Sort does not throw ArrayIndexOutOfBoundsException " +
-                        " as expected: toIndex = " + (a.length + m));
-                }
-                catch (ArrayIndexOutOfBoundsException aie) {
-                    return;
-                }
-            }
-        }
-    }
-
-    private static void checkRange(short[] a, int m) {
-        try {
-            Arrays.sort(a, m + 1, m);
-
-            failed("Sort does not throw IllegalArgumentException " +
-                " as expected: fromIndex = " + (m + 1) +
-                " toIndex = " + m);
-        }
-        catch (IllegalArgumentException iae) {
-            try {
-                Arrays.sort(a, -m, a.length);
-
-                failed("Sort does not throw ArrayIndexOutOfBoundsException " +
-                    " as expected: fromIndex = " + (-m));
-            }
-            catch (ArrayIndexOutOfBoundsException aoe) {
-                try {
-                    Arrays.sort(a, 0, a.length + m);
-
-                    failed("Sort does not throw ArrayIndexOutOfBoundsException " +
-                        " as expected: toIndex = " + (a.length + m));
-                }
-                catch (ArrayIndexOutOfBoundsException aie) {
-                    return;
-                }
-            }
-        }
-    }
-
-    private static void checkRange(char[] a, int m) {
-        try {
-            Arrays.sort(a, m + 1, m);
-
-            failed("Sort does not throw IllegalArgumentException " +
-                " as expected: fromIndex = " + (m + 1) +
-                " toIndex = " + m);
-        }
-        catch (IllegalArgumentException iae) {
-            try {
-                Arrays.sort(a, -m, a.length);
+    private static class TestRandom extends Random {
 
-                failed("Sort does not throw ArrayIndexOutOfBoundsException " +
-                    " as expected: fromIndex = " + (-m));
-            }
-            catch (ArrayIndexOutOfBoundsException aoe) {
-                try {
-                    Arrays.sort(a, 0, a.length + m);
-
-                    failed("Sort does not throw ArrayIndexOutOfBoundsException " +
-                        " as expected: toIndex = " + (a.length + m));
-                }
-                catch (ArrayIndexOutOfBoundsException aie) {
-                    return;
-                }
-            }
-        }
-    }
-
-    private static void checkRange(float[] a, int m) {
-        try {
-            Arrays.sort(a, m + 1, m);
-
-            failed("Sort does not throw IllegalArgumentException " +
-                " as expected: fromIndex = " + (m + 1) +
-                " toIndex = " + m);
-        }
-        catch (IllegalArgumentException iae) {
-            try {
-                Arrays.sort(a, -m, a.length);
-
-                failed("Sort does not throw ArrayIndexOutOfBoundsException " +
-                    " as expected: fromIndex = " + (-m));
-            }
-            catch (ArrayIndexOutOfBoundsException aoe) {
-                try {
-                    Arrays.sort(a, 0, a.length + m);
-
-                    failed("Sort does not throw ArrayIndexOutOfBoundsException " +
-                        " as expected: toIndex = " + (a.length + m));
-                }
-                catch (ArrayIndexOutOfBoundsException aie) {
-                    return;
-                }
-            }
-        }
-    }
-
-    private static void checkRange(double[] a, int m) {
-        try {
-            Arrays.sort(a, m + 1, m);
+        private static final TestRandom BABA = new TestRandom(0xBABA);
+        private static final TestRandom DEDA = new TestRandom(0xDEDA);
+        private static final TestRandom C0FFEE = new TestRandom(0xC0FFEE);
 
-            failed("Sort does not throw IllegalArgumentException " +
-                " as expected: fromIndex = " + (m + 1) +
-                " toIndex = " + m);
-        }
-        catch (IllegalArgumentException iae) {
-            try {
-                Arrays.sort(a, -m, a.length);
-
-                failed("Sort does not throw ArrayIndexOutOfBoundsException " +
-                    " as expected: fromIndex = " + (-m));
-            }
-            catch (ArrayIndexOutOfBoundsException aoe) {
-                try {
-                    Arrays.sort(a, 0, a.length + m);
-
-                    failed("Sort does not throw ArrayIndexOutOfBoundsException " +
-                        " as expected: toIndex = " + (a.length + m));
-                }
-                catch (ArrayIndexOutOfBoundsException aie) {
-                    return;
-                }
-            }
-        }
-    }
-
-    private static void outArray(Object[] a) {
-        for (int i = 0; i < a.length; i++) {
-            out.print(a[i] + " ");
-        }
-        out.println();
-    }
-
-    private static void outArray(int[] a) {
-        for (int i = 0; i < a.length; i++) {
-            out.print(a[i] + " ");
-        }
-        out.println();
-    }
-
-    private static void outArray(float[] a) {
-        for (int i = 0; i < a.length; i++) {
-            out.print(a[i] + " ");
-        }
-        out.println();
-    }
-
-    private static void outArray(double[] a) {
-        for (int i = 0; i < a.length; i++) {
-            out.print(a[i] + " ");
-        }
-        out.println();
-    }
-
-    private static class MyRandom extends Random {
-        MyRandom(long seed) {
+        private TestRandom(long seed) {
             super(seed);
-            mySeed = seed;
+            this.seed = Long.toHexString(seed).toUpperCase();
         }
 
-        long getSeed() {
-            return mySeed;
+        @Override
+        public String toString() {
+            return seed;
         }
 
-        private long mySeed;
+        private String seed;
     }
-
-    private static String ourDescription;
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/Arrays/java.base/java/util/SortingHelper.java	Wed Nov 13 09:16:04 2019 +0000
@@ -0,0 +1,352 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package java.util;
+
+/**
+ * This class provides access to package-private
+ * methods of DualPivotQuicksort class.
+ *
+ * @author Vladimir Yaroslavskiy
+ *
+ * @version 2019.09.19
+ *
+ * @since 14
+ */
+public enum SortingHelper {
+
+    DUAL_PIVOT_QUICKSORT("Dual-Pivot Quicksort") {
+
+        @Override
+        public void sort(Object a) {
+            if (a instanceof int[]) {
+                DualPivotQuicksort.sort((int[]) a, SEQUENTIAL, 0, ((int[]) a).length);
+            } else if (a instanceof long[]) {
+                DualPivotQuicksort.sort((long[]) a, SEQUENTIAL, 0, ((long[]) a).length);
+            } else if (a instanceof byte[]) {
+                DualPivotQuicksort.sort((byte[]) a, 0, ((byte[]) a).length);
+            } else if (a instanceof char[]) {
+                DualPivotQuicksort.sort((char[]) a, SEQUENTIAL, 0, ((char[]) a).length);
+            } else if (a instanceof short[]) {
+                DualPivotQuicksort.sort((short[]) a, SEQUENTIAL, 0, ((short[]) a).length);
+            } else if (a instanceof float[]) {
+                DualPivotQuicksort.sort((float[]) a, SEQUENTIAL, 0, ((float[]) a).length);
+            } else if (a instanceof double[]) {
+                DualPivotQuicksort.sort((double[]) a, SEQUENTIAL, 0, ((double[]) a).length);
+            } else {
+                fail(a);
+            }
+        }
+
+        @Override
+        public void sort(Object a, int low, int high) {
+            if (a instanceof int[]) {
+                DualPivotQuicksort.sort((int[]) a, SEQUENTIAL, low, high);
+            } else if (a instanceof long[]) {
+                DualPivotQuicksort.sort((long[]) a, SEQUENTIAL, low, high);
+            } else if (a instanceof byte[]) {
+                DualPivotQuicksort.sort((byte[]) a, low, high);
+            } else if (a instanceof char[]) {
+                DualPivotQuicksort.sort((char[]) a, SEQUENTIAL, low, high);
+            } else if (a instanceof short[]) {
+                DualPivotQuicksort.sort((short[]) a, SEQUENTIAL, low, high);
+            } else if (a instanceof float[]) {
+                DualPivotQuicksort.sort((float[]) a, SEQUENTIAL, low, high);
+            } else if (a instanceof double[]) {
+                DualPivotQuicksort.sort((double[]) a, SEQUENTIAL, low, high);
+            } else {
+                fail(a);
+            }
+        }
+
+        @Override
+        public void sort(Object[] a) {
+            fail(a);
+        }
+
+        @Override
+        public void sort(Object[] a, Comparator comparator) {
+            fail(a);
+        }
+    },
+
+    PARALLEL_SORT("Parallel sort") {
+
+        @Override
+        public void sort(Object a) {
+            if (a instanceof int[]) {
+                DualPivotQuicksort.sort((int[]) a, PARALLEL, 0, ((int[]) a).length);
+            } else if (a instanceof long[]) {
+                DualPivotQuicksort.sort((long[]) a, PARALLEL, 0, ((long[]) a).length);
+            } else if (a instanceof byte[]) {
+                DualPivotQuicksort.sort((byte[]) a, 0, ((byte[]) a).length);
+            } else if (a instanceof char[]) {
+                DualPivotQuicksort.sort((char[]) a, PARALLEL, 0, ((char[]) a).length);
+            } else if (a instanceof short[]) {
+                DualPivotQuicksort.sort((short[]) a, PARALLEL, 0, ((short[]) a).length);
+            } else if (a instanceof float[]) {
+                DualPivotQuicksort.sort((float[]) a, PARALLEL, 0, ((float[]) a).length);
+            } else if (a instanceof double[]) {
+                DualPivotQuicksort.sort((double[]) a, PARALLEL, 0, ((double[]) a).length);
+            } else {
+                fail(a);
+            }
+        }
+
+        @Override
+        public void sort(Object a, int low, int high) {
+            if (a instanceof int[]) {
+                DualPivotQuicksort.sort((int[]) a, PARALLEL, low, high);
+            } else if (a instanceof long[]) {
+                DualPivotQuicksort.sort((long[]) a, PARALLEL, low, high);
+            } else if (a instanceof byte[]) {
+                DualPivotQuicksort.sort((byte[]) a, low, high);
+            } else if (a instanceof char[]) {
+                DualPivotQuicksort.sort((char[]) a, PARALLEL, low, high);
+            } else if (a instanceof short[]) {
+                DualPivotQuicksort.sort((short[]) a, PARALLEL, low, high);
+            } else if (a instanceof float[]) {
+                DualPivotQuicksort.sort((float[]) a, PARALLEL, low, high);
+            } else if (a instanceof double[]) {
+                DualPivotQuicksort.sort((double[]) a, PARALLEL, low, high);
+            } else {
+                fail(a);
+            }
+        }
+
+        @Override
+        public void sort(Object[] a) {
+            fail(a);
+        }
+
+        @Override
+        public void sort(Object[] a, Comparator comparator) {
+            fail(a);
+        }
+    },
+
+    HEAP_SORT("Heap sort") {
+
+        @Override
+        public void sort(Object a) {
+            if (a instanceof int[]) {
+                DualPivotQuicksort.sort(null, (int[]) a, BIG_DEPTH, 0, ((int[]) a).length);
+            } else if (a instanceof long[]) {
+                DualPivotQuicksort.sort(null, (long[]) a, BIG_DEPTH, 0, ((long[]) a).length);
+            } else if (a instanceof byte[]) {
+                DualPivotQuicksort.sort((byte[]) a, 0, ((byte[]) a).length);
+            } else if (a instanceof char[]) {
+                DualPivotQuicksort.sort((char[]) a, BIG_DEPTH, 0, ((char[]) a).length);
+            } else if (a instanceof short[]) {
+                DualPivotQuicksort.sort((short[]) a, BIG_DEPTH, 0, ((short[]) a).length);
+            } else if (a instanceof float[]) {
+                DualPivotQuicksort.sort(null, (float[]) a, BIG_DEPTH, 0, ((float[]) a).length);
+            } else if (a instanceof double[]) {
+                DualPivotQuicksort.sort(null, (double[]) a, BIG_DEPTH, 0, ((double[]) a).length);
+            } else {
+                fail(a);
+            }
+        }
+
+        @Override
+        public void sort(Object a, int low, int high) {
+            if (a instanceof int[]) {
+                DualPivotQuicksort.sort(null, (int[]) a, BIG_DEPTH, low, high);
+            } else if (a instanceof long[]) {
+                DualPivotQuicksort.sort(null, (long[]) a, BIG_DEPTH, low, high);
+            } else if (a instanceof byte[]) {
+                DualPivotQuicksort.sort((byte[]) a, low, high);
+            } else if (a instanceof char[]) {
+                DualPivotQuicksort.sort((char[]) a, BIG_DEPTH, low, high);
+            } else if (a instanceof short[]) {
+                DualPivotQuicksort.sort((short[]) a, BIG_DEPTH, low, high);
+            } else if (a instanceof float[]) {
+                DualPivotQuicksort.sort(null, (float[]) a, BIG_DEPTH, low, high);
+            } else if (a instanceof double[]) {
+                DualPivotQuicksort.sort(null, (double[]) a, BIG_DEPTH, low, high);
+            } else {
+                fail(a);
+            }
+        }
+
+        @Override
+        public void sort(Object[] a) {
+            fail(a);
+        }
+
+        @Override
+        public void sort(Object[] a, Comparator comparator) {
+            fail(a);
+        }
+    },
+
+    ARRAYS_SORT("Arrays.sort") {
+
+        @Override
+        public void sort(Object a) {
+            if (a instanceof int[]) {
+                Arrays.sort((int[]) a);
+            } else if (a instanceof long[]) {
+                Arrays.sort((long[]) a);
+            } else if (a instanceof byte[]) {
+                Arrays.sort((byte[]) a);
+            } else if (a instanceof char[]) {
+                Arrays.sort((char[]) a);
+            } else if (a instanceof short[]) {
+                Arrays.sort((short[]) a);
+            } else if (a instanceof float[]) {
+                Arrays.sort((float[]) a);
+            } else if (a instanceof double[]) {
+                Arrays.sort((double[]) a);
+            } else {
+                fail(a);
+            }
+        }
+
+        @Override
+        public void sort(Object a, int low, int high) {
+            if (a instanceof int[]) {
+                Arrays.sort((int[]) a, low, high);
+            } else if (a instanceof long[]) {
+                Arrays.sort((long[]) a, low, high);
+            } else if (a instanceof byte[]) {
+                Arrays.sort((byte[]) a, low, high);
+            } else if (a instanceof char[]) {
+                Arrays.sort((char[]) a, low, high);
+            } else if (a instanceof short[]) {
+                Arrays.sort((short[]) a, low, high);
+            } else if (a instanceof float[]) {
+                Arrays.sort((float[]) a, low, high);
+            } else if (a instanceof double[]) {
+                Arrays.sort((double[]) a, low, high);
+            } else {
+                fail(a);
+            }
+        }
+
+        @Override
+        public void sort(Object[] a) {
+            Arrays.sort(a);
+        }
+
+        @Override
+        @SuppressWarnings("unchecked")
+        public void sort(Object[] a, Comparator comparator) {
+            Arrays.sort(a, comparator);
+        }
+    },
+
+    ARRAYS_PARALLEL_SORT("Arrays.parallelSort") {
+
+        @Override
+        public void sort(Object a) {
+            if (a instanceof int[]) {
+                Arrays.parallelSort((int[]) a);
+            } else if (a instanceof long[]) {
+                Arrays.parallelSort((long[]) a);
+            } else if (a instanceof byte[]) {
+                Arrays.parallelSort((byte[]) a);
+            } else if (a instanceof char[]) {
+                Arrays.parallelSort((char[]) a);
+            } else if (a instanceof short[]) {
+                Arrays.parallelSort((short[]) a);
+            } else if (a instanceof float[]) {
+                Arrays.parallelSort((float[]) a);
+            } else if (a instanceof double[]) {
+                Arrays.parallelSort((double[]) a);
+            } else {
+                fail(a);
+            }
+        }
+
+        @Override
+        public void sort(Object a, int low, int high) {
+            if (a instanceof int[]) {
+                Arrays.parallelSort((int[]) a, low, high);
+            } else if (a instanceof long[]) {
+                Arrays.parallelSort((long[]) a, low, high);
+            } else if (a instanceof byte[]) {
+                Arrays.parallelSort((byte[]) a, low, high);
+            } else if (a instanceof char[]) {
+                Arrays.parallelSort((char[]) a, low, high);
+            } else if (a instanceof short[]) {
+                Arrays.parallelSort((short[]) a, low, high);
+            } else if (a instanceof float[]) {
+                Arrays.parallelSort((float[]) a, low, high);
+            } else if (a instanceof double[]) {
+                Arrays.parallelSort((double[]) a, low, high);
+            } else {
+                fail(a);
+            }
+        }
+
+        @Override
+        @SuppressWarnings("unchecked")
+        public void sort(Object[] a) {
+            Arrays.parallelSort((Comparable[]) a);
+        }
+
+        @Override
+        @SuppressWarnings("unchecked")
+        public void sort(Object[] a, Comparator comparator) {
+            Arrays.parallelSort(a, comparator);
+        }
+    };
+
+    abstract public void sort(Object a);
+
+    abstract public void sort(Object a, int low, int high);
+
+    abstract public void sort(Object[] a);
+
+    abstract public void sort(Object[] a, Comparator comparator);
+
+    private SortingHelper(String name) {
+        this.name = name;
+    }
+
+    @Override
+    public String toString() {
+        return name;
+    }
+
+    private static void fail(Object a) {
+        throw new RuntimeException("Unexpected type of array: " + a.getClass().getName());
+    }
+
+    private String name;
+
+    /**
+     * Parallelism level for sequential and parallel sorting.
+     */
+    private static final int SEQUENTIAL = 0;
+    private static final int PARALLEL = 87;
+
+    /**
+     * Heap sort will be invoked, if recursion depth is too big.
+     * Value is taken from DualPivotQuicksort.MAX_RECURSION_DEPTH.
+     */
+    private static final int BIG_DEPTH = 64 * (3 << 1);
+}
--- a/test/jdk/java/util/Locale/LocaleProviders.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/jdk/java/util/Locale/LocaleProviders.java	Wed Nov 13 09:16:04 2019 +0000
@@ -24,6 +24,7 @@
 import java.text.spi.*;
 import java.util.*;
 import java.util.spi.*;
+import java.util.stream.IntStream;
 import sun.util.locale.provider.LocaleProviderAdapter;
 
 public class LocaleProviders {
@@ -87,6 +88,10 @@
                 bug8232871Test();
                 break;
 
+            case "bug8232860Test":
+                bug8232860Test();
+                break;
+
             default:
                 throw new RuntimeException("Test method '"+methodName+"' not found.");
         }
@@ -327,4 +332,42 @@
                 "native calendar is not JapaneseCalendar: " + calType);
         }
     }
+
+    static void bug8232860Test() {
+        var inputList = List.of(123, 123.4);
+        var nfExpectedList = List.of("123", "123.4");
+        var ifExpectedList = List.of("123", "123");
+
+        var type = LocaleProviderAdapter.getAdapter(CalendarNameProvider.class, Locale.US)
+                                        .getAdapterType();
+        if (type == LocaleProviderAdapter.Type.HOST && (IS_WINDOWS || IS_MAC)) {
+            final var numf = NumberFormat.getNumberInstance(Locale.US);
+            final var intf = NumberFormat.getIntegerInstance(Locale.US);
+
+            IntStream.range(0, inputList.size())
+                .forEach(i -> {
+                    var input = inputList.get(i);
+                    var nfExpected = nfExpectedList.get(i);
+                    var result = numf.format(input);
+                    if (!result.equals(nfExpected)) {
+                        throw new RuntimeException("Incorrect number format. " +
+                            "input: " + input + ", expected: " +
+                            nfExpected + ", result: " + result);
+                    }
+
+                    var ifExpected = ifExpectedList.get(i);
+                    result = intf.format(input);
+                    if (!result.equals(ifExpected)) {
+                        throw new RuntimeException("Incorrect integer format. " +
+                            "input: " + input + ", expected: " +
+                            ifExpected + ", result: " + result);
+                    }
+                });
+            System.out.println("bug8232860Test succeeded.");
+        } else {
+            System.out.println("Test ignored. Either :-\n" +
+                "OS is neither macOS/Windows, or\n" +
+                "provider is not HOST: " + type);
+        }
+    }
 }
--- a/test/jdk/java/util/Locale/LocaleProvidersRun.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/jdk/java/util/Locale/LocaleProvidersRun.java	Wed Nov 13 09:16:04 2019 +0000
@@ -25,7 +25,7 @@
  * @test
  * @bug 6336885 7196799 7197573 7198834 8000245 8000615 8001440 8008577
  *      8010666 8013086 8013233 8013903 8015960 8028771 8054482 8062006
- *      8150432 8215913 8220227 8228465 8232871
+ *      8150432 8215913 8220227 8228465 8232871 8232860
  * @summary tests for "java.locale.providers" system property
  * @library /test/lib
  * @build LocaleProviders
@@ -159,6 +159,9 @@
 
         //testing 8232871 fix. (macOS only)
         testRun("HOST", "bug8232871Test", "", "", "");
+
+        //testing 8232860 fix. (macOS/Windows only)
+        testRun("HOST", "bug8232860Test", "", "", "");
     }
 
     private static void testRun(String prefList, String methodName,
--- a/test/jdk/jdk/jfr/event/gc/collection/TestG1ParallelPhases.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/jdk/jdk/jfr/event/gc/collection/TestG1ParallelPhases.java	Wed Nov 13 09:16:04 2019 +0000
@@ -176,6 +176,9 @@
     public static void provokeMixedGC(int g1HeapRegionSize) {
         final var arraySize = 20_000;
         var liveOldObjects = new ArrayList<byte[]>();
+
+        // Make sure the heap is in a known state.
+        getWhiteBox().fullGC();
         allocateOldObjects(liveOldObjects, g1HeapRegionSize, arraySize);
         waitTillCMCFinished(10);
         getWhiteBox().g1StartConcMarkCycle();
--- a/test/jdk/jdk/jfr/event/runtime/TestThreadCpuTimeEvent.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/jdk/jdk/jfr/event/runtime/TestThreadCpuTimeEvent.java	Wed Nov 13 09:16:04 2019 +0000
@@ -107,7 +107,7 @@
             } catch (BrokenBarrierException e) {
                 // Another thread has been interrupted - wait for us to be interrupted as well
                 while (!interrupted()) {
-                    yield();
+                    Thread.yield();
                 }
             } catch (InterruptedException e) {
                 // Normal way of stopping the thread
--- a/test/jdk/tools/launcher/ArgsFileTest.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/jdk/tools/launcher/ArgsFileTest.java	Wed Nov 13 09:16:04 2019 +0000
@@ -23,7 +23,7 @@
 
 /**
  * @test
- * @bug 8027634
+ * @bug 8027634 8231863
  * @summary Argument parsing from file
  * @modules jdk.compiler
  *          jdk.zipfs
@@ -61,13 +61,17 @@
         env.put(JLDEBUG_KEY, "true");
     }
 
-    private File createArgFile(String fname, List<String> lines) throws IOException {
+    private File createArgFile(String fname, List<String> lines, boolean endWithNewline) throws IOException {
         File argFile = new File(fname);
         argFile.delete();
-        createAFile(argFile, lines);
+        createAFile(argFile, lines, endWithNewline);
         return argFile;
     }
 
+    private File createArgFile(String fname, List<String> lines) throws IOException {
+        return createArgFile(fname, lines, true);
+    }
+
     private void verifyOptions(List<String> args, TestResult tr) {
         if (args.isEmpty()) {
             return;
@@ -266,6 +270,23 @@
         userArgs.delete();
     }
 
+    @Test
+    public void userApplicationWithoutEmptyLastLine() throws IOException {
+        File cpOpt = createArgFile("cpOpt", Arrays.asList("-classpath ."), false);
+        File vmArgs = createArgFile("vmArgs", Arrays.asList("-Xint"), false);
+
+        TestResult tr = doExec(env, javaCmd, "-cp", "test.jar", "@cpOpt", "Foo", "-test");
+        verifyOptions(Arrays.asList("-cp", "test.jar", "-classpath", ".", "Foo", "-test"), tr);
+        verifyUserArgs(Arrays.asList("-test"), tr, 6);
+
+        tr = doExec(env, javaCmd,  "-cp", "test.jar", "@vmArgs", "Foo", "-test");
+        verifyOptions(Arrays.asList("-cp", "test.jar", "-Xint", "Foo", "-test"), tr);
+        verifyUserArgs(Arrays.asList("-test"), tr, 5);
+
+        cpOpt.delete();
+        vmArgs.delete();
+    }
+
     // test with missing file
     @Test
     public void missingFileNegativeTest() throws IOException {
--- a/test/jdk/tools/launcher/TestHelper.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/jdk/tools/launcher/TestHelper.java	Wed Nov 13 09:16:04 2019 +0000
@@ -349,12 +349,23 @@
      * occurs then back off for a moment and try again. When a number of
      * attempts fail, give up and throw an exception.
      */
-    void createAFile(File aFile, List<String> contents) throws IOException {
+    void createAFile(File aFile, List<String> lines) throws IOException {
+        createAFile(aFile, lines, true);
+    }
+
+    void createAFile(File aFile, List<String> lines, boolean endWithNewline) throws IOException {
         IOException cause = null;
         for (int attempts = 0; attempts < 10; attempts++) {
             try {
-                Files.write(aFile.getAbsoluteFile().toPath(), contents,
-                    Charset.defaultCharset(), CREATE, TRUNCATE_EXISTING, WRITE);
+                if (endWithNewline) {
+                    Files.write(aFile.getAbsoluteFile().toPath(),
+                        lines, Charset.defaultCharset(),
+                        CREATE, TRUNCATE_EXISTING, WRITE);
+                } else {
+                    Files.write(aFile.getAbsoluteFile().toPath(),
+                        String.join(System.lineSeparator(), lines).getBytes(Charset.defaultCharset()),
+                        CREATE, TRUNCATE_EXISTING, WRITE);
+                }
                 if (cause != null) {
                     /*
                      * report attempts and errors that were encountered
--- a/test/langtools/tools/javac/ConditionalWithVoid.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/ConditionalWithVoid.java	Wed Nov 13 09:16:04 2019 +0000
@@ -4,7 +4,7 @@
  * @summary The compiler was allowing void types in its parsing of conditional expressions.
  * @author tball
  *
- * @compile/fail/ref=ConditionalWithVoid.out --enable-preview -source ${jdk.version} -XDrawDiagnostics ConditionalWithVoid.java
+ * @compile/fail/ref=ConditionalWithVoid.out -XDrawDiagnostics ConditionalWithVoid.java
  */
 public class ConditionalWithVoid {
     public void test(Object o, String s) {
--- a/test/langtools/tools/javac/ConditionalWithVoid.out	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/ConditionalWithVoid.out	Wed Nov 13 09:16:04 2019 +0000
@@ -2,6 +2,4 @@
 ConditionalWithVoid.java:14:53: compiler.err.void.not.allowed.here
 ConditionalWithVoid.java:16:82: compiler.err.void.not.allowed.here
 ConditionalWithVoid.java:18:64: compiler.err.void.not.allowed.here
-- compiler.note.preview.filename: ConditionalWithVoid.java
-- compiler.note.preview.recompile
 4 errors
--- a/test/langtools/tools/javac/diags/examples.not-yet.txt	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/diags/examples.not-yet.txt	Wed Nov 13 09:16:04 2019 +0000
@@ -116,6 +116,7 @@
 compiler.warn.override.bridge
 compiler.warn.position.overflow                         # CRTable: caused by files with long lines >= 1024 chars
 compiler.warn.proc.type.already.exists                  # JavacFiler: just mentioned in TODO
+compiler.warn.restricted.type.not.allowed.preview       # not produced by the compiler right now
 compiler.warn.unchecked.assign                          # DEAD, replaced by compiler.misc.unchecked.assign
 compiler.warn.unchecked.cast.to.type                    # DEAD, replaced by compiler.misc.unchecked.cast.to.type
 compiler.warn.unexpected.archive.file                   # Paths: zip file with unknown extn
--- a/test/langtools/tools/javac/diags/examples/BreakOutsideSwitchExpression.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/diags/examples/BreakOutsideSwitchExpression.java	Wed Nov 13 09:16:04 2019 +0000
@@ -22,9 +22,6 @@
  */
 
 // key: compiler.err.break.outside.switch.expression
-// key: compiler.note.preview.filename
-// key: compiler.note.preview.recompile
-// options: --enable-preview -source ${jdk.version}
 
 class BreakOutsideSwitchExpression {
     int t(int i) {
--- a/test/langtools/tools/javac/diags/examples/ContinueOutsideSwitchExpression.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/diags/examples/ContinueOutsideSwitchExpression.java	Wed Nov 13 09:16:04 2019 +0000
@@ -22,9 +22,6 @@
  */
 
 // key: compiler.err.continue.outside.switch.expression
-// key: compiler.note.preview.filename
-// key: compiler.note.preview.recompile
-// options: --enable-preview -source ${jdk.version}
 
 class ContinueOutsideSwitchExpression {
     int t(int i) {
--- a/test/langtools/tools/javac/diags/examples/IllegalRefToRestrictedType.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/diags/examples/IllegalRefToRestrictedType.java	Wed Nov 13 09:16:04 2019 +0000
@@ -22,7 +22,8 @@
  */
 
 // key: compiler.warn.illegal.ref.to.restricted.type
-// key: compiler.warn.restricted.type.not.allowed.preview
+// key: compiler.warn.restricted.type.not.allowed
+// options: -Xlint:-options -source 13
 
 class IllegalRefToVarType {
     yield list() { return null; }
--- a/test/langtools/tools/javac/diags/examples/IncompatibleTypesInSwitchExpression.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/diags/examples/IncompatibleTypesInSwitchExpression.java	Wed Nov 13 09:16:04 2019 +0000
@@ -24,9 +24,6 @@
 // key: compiler.err.prob.found.req
 // key: compiler.misc.incompatible.type.in.switch.expression
 // key: compiler.misc.inconvertible.types
-// key: compiler.note.preview.filename
-// key: compiler.note.preview.recompile
-// options: --enable-preview -source ${jdk.version}
 
 
 class IncompatibleTypesInSwitchExpression {
--- a/test/langtools/tools/javac/diags/examples/InvalidYield.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/diags/examples/InvalidYield.java	Wed Nov 13 09:16:04 2019 +0000
@@ -22,7 +22,6 @@
  */
 
 // key: compiler.err.invalid.yield
-// options: --enable-preview --source ${jdk.version}
 
 class BreakComplexValueNoSwitchExpressions {
     void t() {
--- a/test/langtools/tools/javac/diags/examples/InvalidYieldWarning.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/diags/examples/InvalidYieldWarning.java	Wed Nov 13 09:16:04 2019 +0000
@@ -22,7 +22,7 @@
  */
 
 // key: compiler.warn.invalid.yield
-// options: --source ${jdk.version}
+// options: -Xlint:-options --source 13
 
 class BreakComplexValueNoSwitchExpressions {
     void t() {
--- a/test/langtools/tools/javac/diags/examples/MultipleCaseLabels.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/diags/examples/MultipleCaseLabels.java	Wed Nov 13 09:16:04 2019 +0000
@@ -22,8 +22,8 @@
  */
 
 // key: compiler.misc.feature.multiple.case.labels
-// key: compiler.warn.preview.feature.use.plural
-// options: --enable-preview -source ${jdk.version} -Xlint:preview
+// key: compiler.err.feature.not.supported.in.source.plural
+// options: -Xlint:-options -source 13
 
 class MultipleCaseLabels {
     void m(int i) {
--- a/test/langtools/tools/javac/diags/examples/NoSwitchExpression.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/diags/examples/NoSwitchExpression.java	Wed Nov 13 09:16:04 2019 +0000
@@ -22,7 +22,6 @@
  */
 
 // key: compiler.err.no.switch.expression
-// options: --enable-preview --source ${jdk.version}
 
 class BreakComplexValueNoSwitchExpressions {
     void t() {
--- a/test/langtools/tools/javac/diags/examples/NoSwitchExpressionQualify.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/diags/examples/NoSwitchExpressionQualify.java	Wed Nov 13 09:16:04 2019 +0000
@@ -22,7 +22,6 @@
  */
 
 // key: compiler.err.no.switch.expression.qualify
-// options: --enable-preview --source ${jdk.version}
 
 class BreakComplexValueNoSwitchExpressions {
     void t() {
--- a/test/langtools/tools/javac/diags/examples/NotExhaustive.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/diags/examples/NotExhaustive.java	Wed Nov 13 09:16:04 2019 +0000
@@ -22,9 +22,6 @@
  */
 
 // key: compiler.err.not.exhaustive
-// key: compiler.note.preview.filename
-// key: compiler.note.preview.recompile
-// options: --enable-preview -source ${jdk.version}
 
 class NotExhaustive {
     int t(int i) {
--- a/test/langtools/tools/javac/diags/examples/RestrictedTypeNotAllowedPreview.java	Tue Nov 12 15:07:15 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-// key: compiler.warn.restricted.type.not.allowed.preview
-
-class yield { }
--- a/test/langtools/tools/javac/diags/examples/ReturnOutsideSwitchExpression.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/diags/examples/ReturnOutsideSwitchExpression.java	Wed Nov 13 09:16:04 2019 +0000
@@ -22,9 +22,6 @@
  */
 
 // key: compiler.err.return.outside.switch.expression
-// key: compiler.note.preview.filename
-// key: compiler.note.preview.recompile
-// options: --enable-preview -source ${jdk.version}
 
 class ReturnOutsideSwitchExpression {
     int t(int i) {
--- a/test/langtools/tools/javac/diags/examples/RuleCompletesNormally.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/diags/examples/RuleCompletesNormally.java	Wed Nov 13 09:16:04 2019 +0000
@@ -22,9 +22,6 @@
  */
 
 // key: compiler.err.rule.completes.normally
-// key: compiler.note.preview.filename
-// key: compiler.note.preview.recompile
-// options: --enable-preview -source ${jdk.version}
 
 class RuleCompletesNormally {
     public String convert(int i) {
--- a/test/langtools/tools/javac/diags/examples/SwitchCaseUnexpectedStatement.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/diags/examples/SwitchCaseUnexpectedStatement.java	Wed Nov 13 09:16:04 2019 +0000
@@ -22,9 +22,6 @@
  */
 
 // key: compiler.err.switch.case.unexpected.statement
-// key: compiler.note.preview.filename
-// key: compiler.note.preview.recompile
-// options: --enable-preview -source ${jdk.version}
 
 class ReturnOutsideSwitchExpression {
     void t(int i) {
--- a/test/langtools/tools/javac/diags/examples/SwitchExpressionCompletesNormally.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/diags/examples/SwitchExpressionCompletesNormally.java	Wed Nov 13 09:16:04 2019 +0000
@@ -22,9 +22,6 @@
  */
 
 // key: compiler.err.switch.expression.completes.normally
-// key: compiler.note.preview.filename
-// key: compiler.note.preview.recompile
-// options: --enable-preview -source ${jdk.version}
 
 class SwitchExpressionCompletesNormally {
     public String convert(int i) {
--- a/test/langtools/tools/javac/diags/examples/SwitchExpressionEmpty.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/diags/examples/SwitchExpressionEmpty.java	Wed Nov 13 09:16:04 2019 +0000
@@ -22,9 +22,6 @@
  */
 
 // key: compiler.err.switch.expression.empty
-// key: compiler.note.preview.filename
-// key: compiler.note.preview.recompile
-// options: --enable-preview -source ${jdk.version}
 
 class BreakOutsideSwitchExpression {
     String t(E e) {
--- a/test/langtools/tools/javac/diags/examples/SwitchExpressionNoResultExpressions.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/diags/examples/SwitchExpressionNoResultExpressions.java	Wed Nov 13 09:16:04 2019 +0000
@@ -22,9 +22,6 @@
  */
 
 // key: compiler.err.switch.expression.no.result.expressions
-// key: compiler.note.preview.filename
-// key: compiler.note.preview.recompile
-// options: --enable-preview -source ${jdk.version}
 
 class SwitchExpressionCompletesNormally {
     public String convert(int i) {
--- a/test/langtools/tools/javac/diags/examples/SwitchExpressionTargetCantBeVoid.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/diags/examples/SwitchExpressionTargetCantBeVoid.java	Wed Nov 13 09:16:04 2019 +0000
@@ -24,9 +24,6 @@
 // key: compiler.err.prob.found.req
 // key: compiler.misc.incompatible.ret.type.in.lambda
 // key: compiler.misc.switch.expression.target.cant.be.void
-// key: compiler.note.preview.filename
-// key: compiler.note.preview.recompile
-// options: --enable-preview -source ${jdk.version}
 
 class SwitchExpressionTargetCantBeVoid {
 
--- a/test/langtools/tools/javac/diags/examples/SwitchExpressions.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/diags/examples/SwitchExpressions.java	Wed Nov 13 09:16:04 2019 +0000
@@ -22,8 +22,8 @@
  */
 
 // key: compiler.misc.feature.switch.expressions
-// key: compiler.warn.preview.feature.use.plural
-// options: --enable-preview -source ${jdk.version} -Xlint:preview
+// key: compiler.err.feature.not.supported.in.source.plural
+// options: -Xlint:-options -source 13
 
 class SwitchExpressions {
     int m(int i) {
--- a/test/langtools/tools/javac/diags/examples/SwitchMixingCaseTypes.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/diags/examples/SwitchMixingCaseTypes.java	Wed Nov 13 09:16:04 2019 +0000
@@ -22,9 +22,6 @@
  */
 
 // key: compiler.err.switch.mixing.case.types
-// key: compiler.note.preview.filename
-// key: compiler.note.preview.recompile
-// options: --enable-preview -source ${jdk.version}
 
 class SwitchMixingCaseTypes {
 
--- a/test/langtools/tools/javac/diags/examples/SwitchRules.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/diags/examples/SwitchRules.java	Wed Nov 13 09:16:04 2019 +0000
@@ -22,8 +22,8 @@
  */
 
 // key: compiler.misc.feature.switch.rules
-// key: compiler.warn.preview.feature.use.plural
-// options: --enable-preview -source ${jdk.version} -Xlint:preview
+// key: compiler.err.feature.not.supported.in.source.plural
+// options: -Xlint:-options -source 13
 
 class SwitchExpressions {
     void m(int i) {
--- a/test/langtools/tools/javac/expswitch/ExpSwitchNestingTest.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/expswitch/ExpSwitchNestingTest.java	Wed Nov 13 09:16:04 2019 +0000
@@ -76,9 +76,6 @@
         }
     }
 
-    private static String[] PREVIEW_OPTIONS = {"--enable-preview", "-source",
-                                               Integer.toString(Runtime.version().feature())};
-
     private void program(String... constructs) {
         String s = "class C { static boolean cond = false; static int x = 0; void m() { # } }";
         for (String c : constructs)
@@ -88,7 +85,7 @@
 
     private void assertOK(String... constructs) {
         reset();
-        addCompileOptions(PREVIEW_OPTIONS);
+        addCompileOptions();
         program(constructs);
         try {
             compile();
@@ -101,7 +98,7 @@
 
     private void assertOKWithWarning(String warning, String... constructs) {
         reset();
-        addCompileOptions(PREVIEW_OPTIONS);
+        addCompileOptions();
         program(constructs);
         try {
             compile();
@@ -114,7 +111,7 @@
 
     private void assertFail(String expectedDiag, String... constructs) {
         reset();
-        addCompileOptions(PREVIEW_OPTIONS);
+        addCompileOptions();
         program(constructs);
         try {
             compile();
--- a/test/langtools/tools/javac/lambda/BadSwitchExpressionLambda.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/lambda/BadSwitchExpressionLambda.java	Wed Nov 13 09:16:04 2019 +0000
@@ -2,7 +2,7 @@
  * @test /nodynamiccopyright/
  * @bug 8206986
  * @summary Adding switch expressions
- * @compile/fail/ref=BadSwitchExpressionLambda.out -XDrawDiagnostics --enable-preview -source ${jdk.version} BadSwitchExpressionLambda.java
+ * @compile/fail/ref=BadSwitchExpressionLambda.out -XDrawDiagnostics BadSwitchExpressionLambda.java
  */
 
 class BadSwitchExpressionLambda {
--- a/test/langtools/tools/javac/lambda/BadSwitchExpressionLambda.out	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/lambda/BadSwitchExpressionLambda.out	Wed Nov 13 09:16:04 2019 +0000
@@ -1,6 +1,4 @@
 BadSwitchExpressionLambda.java:19:26: compiler.err.prob.found.req: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.switch.expression.target.cant.be.void))
 BadSwitchExpressionLambda.java:21:9: compiler.err.cant.apply.symbol: kindname.method, r, BadSwitchExpressionLambda.SAM, @11, kindname.class, BadSwitchExpressionLambda, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.switch.expression.target.cant.be.void)))
 BadSwitchExpressionLambda.java:22:16: compiler.err.prob.found.req: (compiler.misc.unexpected.ret.val)
-- compiler.note.preview.filename: BadSwitchExpressionLambda.java
-- compiler.note.preview.recompile
 3 errors
--- a/test/langtools/tools/javac/parser/JavacParserTest.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/parser/JavacParserTest.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1096,7 +1096,7 @@
         String expectedErrors = "Test.java:1:178: compiler.err.switch.case.unexpected.statement\n";
         StringWriter out = new StringWriter();
         JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(out, fm, null,
-                Arrays.asList("-XDrawDiagnostics", "--enable-preview", "-source", SOURCE_VERSION),
+                Arrays.asList("-XDrawDiagnostics"),
                 null, Arrays.asList(new MyFileObject(code)));
 
         CompilationUnitTree cut = ct.parse().iterator().next();
--- a/test/langtools/tools/javac/switchexpr/BlockExpression.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/BlockExpression.java	Wed Nov 13 09:16:04 2019 +0000
@@ -25,8 +25,8 @@
  * @test
  * @bug 8206986
  * @summary Verify rule cases with expression statements and throw statements work.
- * @compile --enable-preview -source ${jdk.version} BlockExpression.java
- * @run main/othervm --enable-preview BlockExpression
+ * @compile BlockExpression.java
+ * @run main BlockExpression
  */
 
 public class BlockExpression {
--- a/test/langtools/tools/javac/switchexpr/BooleanNumericNonNumeric.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/BooleanNumericNonNumeric.java	Wed Nov 13 09:16:04 2019 +0000
@@ -2,7 +2,7 @@
  * @test /nodynamiccopyright/
  * @bug 8206986
  * @summary Verify the type of a conditional expression with nested switch expression is computed properly
- * @compile/fail/ref=BooleanNumericNonNumeric.out -XDrawDiagnostics --enable-preview -source ${jdk.version} BooleanNumericNonNumeric.java
+ * @compile/fail/ref=BooleanNumericNonNumeric.out -XDrawDiagnostics BooleanNumericNonNumeric.java
  */
 
 public class BooleanNumericNonNumeric {
--- a/test/langtools/tools/javac/switchexpr/BooleanNumericNonNumeric.out	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/BooleanNumericNonNumeric.out	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,3 @@
 BooleanNumericNonNumeric.java:11:20: compiler.err.operator.cant.be.applied.1: +, int, boolean
 BooleanNumericNonNumeric.java:19:15: compiler.err.cant.deref: int
-- compiler.note.preview.filename: BooleanNumericNonNumeric.java
-- compiler.note.preview.recompile
 2 errors
--- a/test/langtools/tools/javac/switchexpr/BreakTest.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/BreakTest.java	Wed Nov 13 09:16:04 2019 +0000
@@ -67,7 +67,7 @@
 
         StringWriter out = new StringWriter();
         JavacTask ct = (JavacTask) tool.getTask(out, null, noErrors,
-            List.of("-XDdev", "--enable-preview", "-source", sourceVersion), null,
+            List.of("-XDdev"), null,
             Arrays.asList(new MyFileObject(CODE)));
         List<String> labels = new ArrayList<>();
         new TreePathScanner<Void, Void>() {
--- a/test/langtools/tools/javac/switchexpr/CRT.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/CRT.java	Wed Nov 13 09:16:04 2019 +0000
@@ -151,9 +151,7 @@
         tb.createDirectories(classes);
         tb.cleanDirectory(classes);
         new JavacTask(tb)
-                .options("-Xjcov",
-                         "--enable-preview",
-                         "-source", SOURCE_VERSION)
+                .options("-Xjcov")
                 .outdir(classes)
                 .sources("public class Test {\n" +
                          code +
--- a/test/langtools/tools/javac/switchexpr/DefiniteAssignment1.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/DefiniteAssignment1.java	Wed Nov 13 09:16:04 2019 +0000
@@ -25,8 +25,8 @@
  * @test
  * @bug 8214031 8221413
  * @summary Verify that definite assignment when true works (legal code)
- * @compile --enable-preview --source ${jdk.version} DefiniteAssignment1.java
- * @run main/othervm --enable-preview DefiniteAssignment1
+ * @compile DefiniteAssignment1.java
+ * @run main DefiniteAssignment1
  */
 public class DefiniteAssignment1 {
     public static void main(String[] args) {
--- a/test/langtools/tools/javac/switchexpr/DefiniteAssignment2.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/DefiniteAssignment2.java	Wed Nov 13 09:16:04 2019 +0000
@@ -2,7 +2,7 @@
  * @test /nodynamiccopyright/
  * @bug 8214031
  * @summary Verify that definite assignment when true works (illegal code)
- * @compile/fail/ref=DefiniteAssignment2.out --enable-preview --source ${jdk.version} -XDrawDiagnostics DefiniteAssignment2.java
+ * @compile/fail/ref=DefiniteAssignment2.out -XDrawDiagnostics DefiniteAssignment2.java
  */
 public class DefiniteAssignment2 {
 
--- a/test/langtools/tools/javac/switchexpr/DefiniteAssignment2.out	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/DefiniteAssignment2.out	Wed Nov 13 09:16:04 2019 +0000
@@ -5,6 +5,4 @@
 DefiniteAssignment2.java:59:19: compiler.err.var.might.not.have.been.initialized: x
 DefiniteAssignment2.java:69:19: compiler.err.var.might.not.have.been.initialized: x
 DefiniteAssignment2.java:79:20: compiler.err.var.might.already.be.assigned: x
-- compiler.note.preview.filename: DefiniteAssignment2.java
-- compiler.note.preview.recompile
 7 errors
--- a/test/langtools/tools/javac/switchexpr/EmptySwitch.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/EmptySwitch.java	Wed Nov 13 09:16:04 2019 +0000
@@ -25,7 +25,7 @@
  * @test
  * @bug 8206986 8226510
  * @summary Verify than a switch that does not yield a value is rejected.
- * @compile/fail/ref=EmptySwitch.out --enable-preview -source ${jdk.version} -XDrawDiagnostics -XDshould-stop.at=FLOW EmptySwitch.java
+ * @compile/fail/ref=EmptySwitch.out -XDrawDiagnostics -XDshould-stop.at=FLOW EmptySwitch.java
  */
 
 public class EmptySwitch {
--- a/test/langtools/tools/javac/switchexpr/EmptySwitch.out	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/EmptySwitch.out	Wed Nov 13 09:16:04 2019 +0000
@@ -3,6 +3,4 @@
 EmptySwitch.java:38:10: compiler.err.switch.expression.no.result.expressions
 EmptySwitch.java:44:9: compiler.err.switch.expression.completes.normally
 EmptySwitch.java:47:26: compiler.err.rule.completes.normally
-- compiler.note.preview.filename: EmptySwitch.java
-- compiler.note.preview.recompile
 5 errors
--- a/test/langtools/tools/javac/switchexpr/ExhaustiveEnumSwitch.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ExhaustiveEnumSwitch.java	Wed Nov 13 09:16:04 2019 +0000
@@ -25,9 +25,9 @@
  * @test
  * @bug 8206986
  * @summary Verify that an switch expression over enum can be exhaustive without default.
- * @compile --enable-preview -source ${jdk.version} ExhaustiveEnumSwitch.java
+ * @compile ExhaustiveEnumSwitch.java
  * @compile ExhaustiveEnumSwitchExtra.java
- * @run main/othervm --enable-preview ExhaustiveEnumSwitch
+ * @run main ExhaustiveEnumSwitch
  */
 
 public class ExhaustiveEnumSwitch {
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitch-old.out	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitch-old.out	Wed Nov 13 09:16:04 2019 +0000
@@ -1,4 +1,4 @@
-ExpressionSwitch.java:40:16: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.switch.expressions)
-ExpressionSwitch.java:41:20: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.switch.rules)
-ExpressionSwitch.java:93:31: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.multiple.case.labels)
+ExpressionSwitch.java:40:16: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.switch.expressions), 9, 14
+ExpressionSwitch.java:41:20: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.switch.rules), 9, 14
+ExpressionSwitch.java:93:31: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.multiple.case.labels), 9, 14
 3 errors
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitch.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitch.java	Wed Nov 13 09:16:04 2019 +0000
@@ -3,8 +3,8 @@
  * @bug 8206986 8222169 8224031
  * @summary Check expression switch works.
  * @compile/fail/ref=ExpressionSwitch-old.out -source 9 -Xlint:-options -XDrawDiagnostics ExpressionSwitch.java
- * @compile --enable-preview -source ${jdk.version} ExpressionSwitch.java
- * @run main/othervm --enable-preview ExpressionSwitch
+ * @compile ExpressionSwitch.java
+ * @run main ExpressionSwitch
  */
 
 import java.util.Objects;
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitchBreaks1.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitchBreaks1.java	Wed Nov 13 09:16:04 2019 +0000
@@ -25,8 +25,8 @@
  * @test
  * @bug 8206986
  * @summary Verify behavior of various kinds of breaks.
- * @compile --enable-preview -source ${jdk.version} ExpressionSwitchBreaks1.java
- * @run main/othervm --enable-preview ExpressionSwitchBreaks1
+ * @compile ExpressionSwitchBreaks1.java
+ * @run main ExpressionSwitchBreaks1
  */
 
 import java.util.Objects;
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitchBreaks2.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitchBreaks2.java	Wed Nov 13 09:16:04 2019 +0000
@@ -2,7 +2,7 @@
  * @test /nodynamiccopyright/
  * @bug 8206986
  * @summary Check behavior for invalid breaks.
- * @compile/fail/ref=ExpressionSwitchBreaks2.out -XDrawDiagnostics --enable-preview -source ${jdk.version} ExpressionSwitchBreaks2.java
+ * @compile/fail/ref=ExpressionSwitchBreaks2.out -XDrawDiagnostics ExpressionSwitchBreaks2.java
  */
 
 public class ExpressionSwitchBreaks2 {
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitchBreaks2.out	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitchBreaks2.out	Wed Nov 13 09:16:04 2019 +0000
@@ -7,6 +7,4 @@
 ExpressionSwitchBreaks2.java:40:29: compiler.err.cant.resolve.location: kindname.variable, undef, , , (compiler.misc.location: kindname.class, ExpressionSwitchBreaks2, null)
 ExpressionSwitchBreaks2.java:45:22: compiler.err.break.outside.switch.expression
 ExpressionSwitchBreaks2.java:49:22: compiler.err.break.outside.switch.expression
-- compiler.note.preview.filename: ExpressionSwitchBreaks2.java
-- compiler.note.preview.recompile
 9 errors
\ No newline at end of file
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitchBugs.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitchBugs.java	Wed Nov 13 09:16:04 2019 +0000
@@ -25,8 +25,8 @@
  * @test
  * @bug 8206986 8214114 8214529
  * @summary Verify various corner cases with nested switch expressions.
- * @compile --enable-preview -source ${jdk.version} ExpressionSwitchBugs.java
- * @run main/othervm --enable-preview ExpressionSwitchBugs
+ * @compile ExpressionSwitchBugs.java
+ * @run main ExpressionSwitchBugs
  */
 
 public class ExpressionSwitchBugs {
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitchBugsInGen.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitchBugsInGen.java	Wed Nov 13 09:16:04 2019 +0000
@@ -25,8 +25,8 @@
  * @test
  * @bug 8214031
  * @summary Verify various corner cases with nested switch expressions.
- * @compile --enable-preview -source ${jdk.version} ExpressionSwitchBugsInGen.java
- * @run main/othervm --enable-preview ExpressionSwitchBugsInGen
+ * @compile ExpressionSwitchBugsInGen.java
+ * @run main ExpressionSwitchBugsInGen
  */
 
 public class ExpressionSwitchBugsInGen {
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitchCodeFromJLS.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitchCodeFromJLS.java	Wed Nov 13 09:16:04 2019 +0000
@@ -25,8 +25,8 @@
  * @test
  * @bug 8206986
  * @summary Check switch expressions
- * @compile --enable-preview -source ${jdk.version} ExpressionSwitchCodeFromJLS.java
- * @run main/othervm --enable-preview ExpressionSwitchCodeFromJLS
+ * @compile ExpressionSwitchCodeFromJLS.java
+ * @run main ExpressionSwitchCodeFromJLS
  */
 
 public class ExpressionSwitchCodeFromJLS {
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitchDA.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitchDA.java	Wed Nov 13 09:16:04 2019 +0000
@@ -25,8 +25,8 @@
  * @test
  * @bug 8206986
  * @summary Check definite (un)assignment for in switch expressions.
- * @compile --enable-preview -source ${jdk.version} ExpressionSwitchDA.java
- * @run main/othervm --enable-preview ExpressionSwitchDA
+ * @compile ExpressionSwitchDA.java
+ * @run main ExpressionSwitchDA
  */
 
 public class ExpressionSwitchDA {
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitchEmbedding.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitchEmbedding.java	Wed Nov 13 09:16:04 2019 +0000
@@ -25,8 +25,8 @@
  * @test
  * @bug 8214031 8214114
  * @summary Verify switch expressions embedded in various statements work properly.
- * @compile --enable-preview -source ${jdk.version} ExpressionSwitchEmbedding.java
- * @run main/othervm --enable-preview ExpressionSwitchEmbedding
+ * @compile ExpressionSwitchEmbedding.java
+ * @run main ExpressionSwitchEmbedding
  */
 
 public class ExpressionSwitchEmbedding {
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitchFallThrough.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitchFallThrough.java	Wed Nov 13 09:16:04 2019 +0000
@@ -25,8 +25,8 @@
  * @test
  * @bug 8206986
  * @summary Check fall through in switch expressions.
- * @compile --enable-preview -source ${jdk.version} ExpressionSwitchFallThrough.java
- * @run main/othervm --enable-preview ExpressionSwitchFallThrough
+ * @compile ExpressionSwitchFallThrough.java
+ * @run main ExpressionSwitchFallThrough
  */
 
 import java.util.Objects;
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitchFallThrough1.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitchFallThrough1.java	Wed Nov 13 09:16:04 2019 +0000
@@ -25,8 +25,8 @@
  * @test
  * @bug 8206986
  * @summary Check fall through in switch expressions.
- * @compile --enable-preview -source ${jdk.version} ExpressionSwitchFallThrough1.java
- * @run main/othervm --enable-preview ExpressionSwitchFallThrough1
+ * @compile ExpressionSwitchFallThrough1.java
+ * @run main ExpressionSwitchFallThrough1
  */
 
 import java.util.Objects;
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitchFlow.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitchFlow.java	Wed Nov 13 09:16:04 2019 +0000
@@ -2,7 +2,7 @@
  * @test /nodynamiccopyright/
  * @bug 8212982
  * @summary Verify a compile-time error is produced if switch expression does not provide a value
- * @compile/fail/ref=ExpressionSwitchFlow.out --enable-preview -source ${jdk.version} -XDrawDiagnostics ExpressionSwitchFlow.java
+ * @compile/fail/ref=ExpressionSwitchFlow.out -XDrawDiagnostics ExpressionSwitchFlow.java
  */
 
 public class ExpressionSwitchFlow {
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitchFlow.out	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitchFlow.out	Wed Nov 13 09:16:04 2019 +0000
@@ -7,6 +7,4 @@
 ExpressionSwitchFlow.java:53:9: compiler.err.switch.expression.completes.normally
 ExpressionSwitchFlow.java:61:9: compiler.err.switch.expression.completes.normally
 ExpressionSwitchFlow.java:69:9: compiler.err.switch.expression.completes.normally
-- compiler.note.preview.filename: ExpressionSwitchFlow.java
-- compiler.note.preview.recompile
 9 errors
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitchInExpressionSwitch.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitchInExpressionSwitch.java	Wed Nov 13 09:16:04 2019 +0000
@@ -25,8 +25,8 @@
  * @test
  * @bug 8206986
  * @summary Check switch expressions embedded in switch expressions.
- * @compile --enable-preview -source ${jdk.version} ExpressionSwitchInExpressionSwitch.java
- * @run main/othervm --enable-preview ExpressionSwitchInExpressionSwitch
+ * @compile ExpressionSwitchInExpressionSwitch.java
+ * @run main ExpressionSwitchInExpressionSwitch
  */
 
 public class ExpressionSwitchInExpressionSwitch {
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitchInfer.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitchInfer.java	Wed Nov 13 09:16:04 2019 +0000
@@ -2,7 +2,7 @@
  * @test /nodynamiccopyright/
  * @bug 8206986
  * @summary Check types inferred for switch expressions.
- * @compile/fail/ref=ExpressionSwitchInfer.out -XDrawDiagnostics --enable-preview -source ${jdk.version} ExpressionSwitchInfer.java
+ * @compile/fail/ref=ExpressionSwitchInfer.out -XDrawDiagnostics ExpressionSwitchInfer.java
  */
 
 import java.util.ArrayList;
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitchInfer.out	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitchInfer.out	Wed Nov 13 09:16:04 2019 +0000
@@ -1,6 +1,4 @@
 ExpressionSwitchInfer.java:17:95: compiler.err.cant.resolve.location.args: kindname.method, substring, , int, (compiler.misc.location: kindname.interface, java.lang.CharSequence, null)
 ExpressionSwitchInfer.java:26:38: compiler.err.cant.resolve.location.args: kindname.method, substring, , int, (compiler.misc.location: kindname.interface, java.lang.CharSequence, null)
 ExpressionSwitchInfer.java:30:23: compiler.err.prob.found.req: (compiler.misc.incompatible.type.in.switch.expression: (compiler.misc.inconvertible.types: int, java.lang.String))
-- compiler.note.preview.filename: ExpressionSwitchInfer.java
-- compiler.note.preview.recompile
 3 errors
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitchIntersectionTypes.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitchIntersectionTypes.java	Wed Nov 13 09:16:04 2019 +0000
@@ -25,8 +25,8 @@
  * @test
  * @bug 8206986
  * @summary Verify behavior when an intersection type is inferred for switch expression.
- * @compile --enable-preview -source ${jdk.version} ExpressionSwitchIntersectionTypes.java
- * @run main/othervm --enable-preview ExpressionSwitchIntersectionTypes
+ * @compile ExpressionSwitchIntersectionTypes.java
+ * @run main ExpressionSwitchIntersectionTypes
  */
 
 public class ExpressionSwitchIntersectionTypes<X  extends java.io.Serializable & Runnable> {
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitchNotExhaustive.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitchNotExhaustive.java	Wed Nov 13 09:16:04 2019 +0000
@@ -2,7 +2,7 @@
  * @test /nodynamiccopyright/
  * @bug 8206986
  * @summary Verify behavior of not exhaustive switch expressions.
- * @compile/fail/ref=ExpressionSwitchNotExhaustive.out -XDrawDiagnostics --enable-preview -source ${jdk.version} ExpressionSwitchNotExhaustive.java
+ * @compile/fail/ref=ExpressionSwitchNotExhaustive.out -XDrawDiagnostics ExpressionSwitchNotExhaustive.java
  */
 
 public class ExpressionSwitchNotExhaustive {
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitchNotExhaustive.out	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitchNotExhaustive.out	Wed Nov 13 09:16:04 2019 +0000
@@ -1,6 +1,4 @@
 ExpressionSwitchNotExhaustive.java:10:16: compiler.err.not.exhaustive
 ExpressionSwitchNotExhaustive.java:16:16: compiler.err.not.exhaustive
 ExpressionSwitchNotExhaustive.java:29:23: compiler.err.var.might.not.have.been.initialized: s
-- compiler.note.preview.filename: ExpressionSwitchNotExhaustive.java
-- compiler.note.preview.recompile
 3 errors
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitchToString.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitchToString.java	Wed Nov 13 09:16:04 2019 +0000
@@ -99,7 +99,7 @@
         String sourceVersion = Integer.toString(Runtime.version().feature());
 
         JavacTask ct = (JavacTask) tool.getTask(null, null, noErrors,
-            List.of("-XDdev", "--enable-preview", "-source", sourceVersion), null,
+            List.of("-XDdev"), null,
             Arrays.asList(new MyFileObject(CODE)));
         String actualCode = ct.parse().iterator().next().toString();
         actualCode = actualCode.replace(System.getProperty("line.separator"), "\n");
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitchUnreachable.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitchUnreachable.java	Wed Nov 13 09:16:04 2019 +0000
@@ -2,7 +2,7 @@
  * @test /nodynamiccopyright/
  * @bug 8206986
  * @summary Verify reachability in switch expressions.
- * @compile/fail/ref=ExpressionSwitchUnreachable.out -XDrawDiagnostics --enable-preview -source ${jdk.version} ExpressionSwitchUnreachable.java
+ * @compile/fail/ref=ExpressionSwitchUnreachable.out -XDrawDiagnostics ExpressionSwitchUnreachable.java
  */
 
 public class ExpressionSwitchUnreachable {
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitchUnreachable.out	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitchUnreachable.out	Wed Nov 13 09:16:04 2019 +0000
@@ -4,6 +4,4 @@
 ExpressionSwitchUnreachable.java:37:17: compiler.err.unreachable.stmt
 ExpressionSwitchUnreachable.java:45:17: compiler.err.unreachable.stmt
 ExpressionSwitchUnreachable.java:52:17: compiler.err.unreachable.stmt
-- compiler.note.preview.filename: ExpressionSwitchUnreachable.java
-- compiler.note.preview.recompile
 6 errors
\ No newline at end of file
--- a/test/langtools/tools/javac/switchexpr/LambdaCapture.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/LambdaCapture.java	Wed Nov 13 09:16:04 2019 +0000
@@ -26,7 +26,7 @@
  * @bug 8220041
  * @summary Verify variable capture works inside switch expressions which are
  *          inside variable declarations
- * @compile --enable-preview -source ${jdk.version} LambdaCapture.java
+ * @compile LambdaCapture.java
  */
 
 import java.util.Objects;
--- a/test/langtools/tools/javac/switchexpr/ParseIncomplete.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ParseIncomplete.java	Wed Nov 13 09:16:04 2019 +0000
@@ -68,7 +68,7 @@
             StringWriter out = new StringWriter();
             try {
                 JavacTask ct = (JavacTask) tool.getTask(out, null, noErrors,
-                    List.of("-XDdev", "--enable-preview", "-source", sourceVersion), null,
+                    List.of("-XDdev"), null,
                     Arrays.asList(new MyFileObject(code)));
                 ct.parse().iterator().next();
             } catch (Throwable t) {
--- a/test/langtools/tools/javac/switchexpr/ParserRecovery.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ParserRecovery.java	Wed Nov 13 09:16:04 2019 +0000
@@ -2,7 +2,7 @@
  * @test /nodynamiccopyright/
  * @bug 8206986
  * @summary Verify the parser handles broken input gracefully.
- * @compile/fail/ref=ParserRecovery.out -XDrawDiagnostics --enable-preview -source ${jdk.version} ParserRecovery.java
+ * @compile/fail/ref=ParserRecovery.out -XDrawDiagnostics ParserRecovery.java
  */
 
 public class ParserRecovery {
--- a/test/langtools/tools/javac/switchexpr/ParserRecovery.out	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/ParserRecovery.out	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,3 @@
 ParserRecovery.java:10:39: compiler.err.expected2: :, ->
 ParserRecovery.java:13:31: compiler.err.expected2: :, ->
-- compiler.note.preview.filename: ParserRecovery.java
-- compiler.note.preview.recompile
 2 errors
--- a/test/langtools/tools/javac/switchexpr/SwitchExpressionIsNotAConstant.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/SwitchExpressionIsNotAConstant.java	Wed Nov 13 09:16:04 2019 +0000
@@ -26,8 +26,8 @@
  * @bug 8214113
  * @summary Verify the switch expression's type does not have a constant attached,
  *          and so the switch expression is not elided.
- * @compile --enable-preview --source ${jdk.version} SwitchExpressionIsNotAConstant.java
- * @run main/othervm --enable-preview SwitchExpressionIsNotAConstant
+ * @compile SwitchExpressionIsNotAConstant.java
+ * @run main SwitchExpressionIsNotAConstant
  */
 public class SwitchExpressionIsNotAConstant {
 
--- a/test/langtools/tools/javac/switchexpr/SwitchExpressionScopesIsolated.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/SwitchExpressionScopesIsolated.java	Wed Nov 13 09:16:04 2019 +0000
@@ -2,7 +2,7 @@
  * @test /nodynamiccopyright/
  * @bug 8206986
  * @summary Verify that scopes in rule cases are isolated.
- * @compile/fail/ref=SwitchExpressionScopesIsolated.out -XDrawDiagnostics --enable-preview -source ${jdk.version} SwitchExpressionScopesIsolated.java
+ * @compile/fail/ref=SwitchExpressionScopesIsolated.out -XDrawDiagnostics SwitchExpressionScopesIsolated.java
  */
 
 public class SwitchExpressionScopesIsolated {
--- a/test/langtools/tools/javac/switchexpr/SwitchExpressionScopesIsolated.out	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/SwitchExpressionScopesIsolated.out	Wed Nov 13 09:16:04 2019 +0000
@@ -2,6 +2,4 @@
 SwitchExpressionScopesIsolated.java:13:41: compiler.err.cant.resolve.location: kindname.variable, res, , , (compiler.misc.location: kindname.class, SwitchExpressionScopesIsolated, null)
 SwitchExpressionScopesIsolated.java:14:26: compiler.err.cant.resolve.location: kindname.variable, res, , , (compiler.misc.location: kindname.class, SwitchExpressionScopesIsolated, null)
 SwitchExpressionScopesIsolated.java:14:42: compiler.err.cant.resolve.location: kindname.variable, res, , , (compiler.misc.location: kindname.class, SwitchExpressionScopesIsolated, null)
-- compiler.note.preview.filename: SwitchExpressionScopesIsolated.java
-- compiler.note.preview.recompile
 4 errors
--- a/test/langtools/tools/javac/switchexpr/SwitchExpressionSimpleVisitorTest.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/SwitchExpressionSimpleVisitorTest.java	Wed Nov 13 09:16:04 2019 +0000
@@ -107,7 +107,7 @@
 
         StringWriter out = new StringWriter();
         JavacTask ct = (JavacTask) tool.getTask(out, null, noErrors,
-            List.of("--enable-preview", "-source", Integer.toString(Runtime.version().feature())), null,
+            List.of(), null,
             Arrays.asList(new MyFileObject(code)));
         return ct.parse().iterator().next();
     }
--- a/test/langtools/tools/javac/switchexpr/TryCatch.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/TryCatch.java	Wed Nov 13 09:16:04 2019 +0000
@@ -25,8 +25,8 @@
  * @test
  * @bug 8214114
  * @summary Verify try-catch inside a switch expression works properly.
- * @compile --enable-preview -source ${jdk.version} TryCatch.java
- * @run main/othervm --enable-preview TryCatch
+ * @compile TryCatch.java
+ * @run main TryCatch
  */
 public class TryCatch {
     public static void main(String[] args) {
--- a/test/langtools/tools/javac/switchexpr/TryCatchFinally.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/TryCatchFinally.java	Wed Nov 13 09:16:04 2019 +0000
@@ -25,8 +25,8 @@
  * @test
  * @bug 8220018
  * @summary Verify that try-catch-finally inside a switch expression works properly.
- * @compile --enable-preview -source ${jdk.version} TryCatchFinally.java
- * @run main/othervm --enable-preview TryCatchFinally
+ * @compile TryCatchFinally.java
+ * @run main TryCatchFinally
  */
 public class TryCatchFinally {//TODO: yield <double>
     public static void main(String[] args) {
--- a/test/langtools/tools/javac/switchexpr/WarnWrongYieldTest.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/WarnWrongYieldTest.java	Wed Nov 13 09:16:04 2019 +0000
@@ -25,7 +25,7 @@
  * @test
  * @bug 8223305 8226522
  * @summary Verify correct warnings w.r.t. yield
- * @compile/ref=WarnWrongYieldTest.out -source ${jdk.version} -XDrawDiagnostics -XDshould-stop.at=ATTR WarnWrongYieldTest.java
+ * @compile/ref=WarnWrongYieldTest.out -Xlint:-options -source 13 -XDrawDiagnostics -XDshould-stop.at=ATTR WarnWrongYieldTest.java
  */
 
 package t;
--- a/test/langtools/tools/javac/switchexpr/WarnWrongYieldTest.out	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/WarnWrongYieldTest.out	Wed Nov 13 09:16:04 2019 +0000
@@ -1,8 +1,8 @@
-WarnWrongYieldTest.java:39:11: compiler.warn.restricted.type.not.allowed.preview: yield, 13
-WarnWrongYieldTest.java:45:5: compiler.warn.restricted.type.not.allowed.preview: yield, 13
-WarnWrongYieldTest.java:72:15: compiler.warn.restricted.type.not.allowed.preview: yield, 13
-WarnWrongYieldTest.java:75:15: compiler.warn.restricted.type.not.allowed.preview: yield, 13
-WarnWrongYieldTest.java:81:21: compiler.warn.restricted.type.not.allowed.preview: yield, 13
+WarnWrongYieldTest.java:39:11: compiler.warn.restricted.type.not.allowed: yield, 14
+WarnWrongYieldTest.java:45:5: compiler.warn.restricted.type.not.allowed: yield, 14
+WarnWrongYieldTest.java:72:15: compiler.warn.restricted.type.not.allowed: yield, 14
+WarnWrongYieldTest.java:75:15: compiler.warn.restricted.type.not.allowed: yield, 14
+WarnWrongYieldTest.java:81:21: compiler.warn.restricted.type.not.allowed: yield, 14
 WarnWrongYieldTest.java:93:9: compiler.warn.invalid.yield
 WarnWrongYieldTest.java:98:9: compiler.warn.invalid.yield
 WarnWrongYieldTest.java:103:9: compiler.warn.invalid.yield
@@ -11,8 +11,8 @@
 WarnWrongYieldTest.java:118:9: compiler.warn.invalid.yield
 WarnWrongYieldTest.java:123:22: compiler.warn.invalid.yield
 WarnWrongYieldTest.java:152:24: compiler.warn.invalid.yield
-WarnWrongYieldTest.java:164:18: compiler.warn.restricted.type.not.allowed.preview: yield, 13
-WarnWrongYieldTest.java:168:23: compiler.warn.restricted.type.not.allowed.preview: yield, 13
+WarnWrongYieldTest.java:164:18: compiler.warn.restricted.type.not.allowed: yield, 14
+WarnWrongYieldTest.java:168:23: compiler.warn.restricted.type.not.allowed: yield, 14
 WarnWrongYieldTest.java:34:28: compiler.warn.illegal.ref.to.restricted.type: yield
 WarnWrongYieldTest.java:45:5: compiler.warn.illegal.ref.to.restricted.type: yield
 WarnWrongYieldTest.java:168:23: compiler.warn.illegal.ref.to.restricted.type: yield
--- a/test/langtools/tools/javac/switchexpr/WrongBreakTest.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/WrongBreakTest.java	Wed Nov 13 09:16:04 2019 +0000
@@ -25,7 +25,7 @@
  * @test
  * @bug 8223305
  * @summary Ensure javac is not crashing for wrong breaks.
- * @compile/fail/ref=WrongBreakTest.out --enable-preview -source ${jdk.version} -XDrawDiagnostics -XDshould-stop.at=FLOW WrongBreakTest.java
+ * @compile/fail/ref=WrongBreakTest.out -XDrawDiagnostics -XDshould-stop.at=FLOW WrongBreakTest.java
  */
 
 public class WrongBreakTest {
--- a/test/langtools/tools/javac/switchexpr/WrongBreakTest.out	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/WrongBreakTest.out	Wed Nov 13 09:16:04 2019 +0000
@@ -4,6 +4,4 @@
 WrongBreakTest.java:36:9: compiler.err.ref.ambiguous: test, kindname.method, test(int), WrongBreakTest, kindname.method, test(java.lang.Object), WrongBreakTest
 WrongBreakTest.java:38:13: compiler.err.no.switch.expression
 WrongBreakTest.java:41:13: compiler.err.no.switch.expression
-- compiler.note.preview.filename: WrongBreakTest.java
-- compiler.note.preview.recompile
 6 errors
--- a/test/langtools/tools/javac/switchexpr/WrongYieldTest.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/WrongYieldTest.java	Wed Nov 13 09:16:04 2019 +0000
@@ -25,7 +25,7 @@
  * @test
  * @bug 8223305 8226522
  * @summary Ensure proper errors are returned for yields.
- * @compile/fail/ref=WrongYieldTest.out --enable-preview -source ${jdk.version} -XDrawDiagnostics -XDshould-stop.at=ATTR WrongYieldTest.java
+ * @compile/fail/ref=WrongYieldTest.out -XDrawDiagnostics -XDshould-stop.at=ATTR WrongYieldTest.java
  */
 
 package t;
--- a/test/langtools/tools/javac/switchexpr/WrongYieldTest.out	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchexpr/WrongYieldTest.out	Wed Nov 13 09:16:04 2019 +0000
@@ -26,6 +26,4 @@
 WrongYieldTest.java:201:9: compiler.err.no.switch.expression
 WrongYieldTest.java:202:9: compiler.err.no.switch.expression
 WrongYieldTest.java:216:24: compiler.err.illegal.ref.to.restricted.type: yield
-- compiler.note.preview.filename: WrongYieldTest.java
-- compiler.note.preview.recompile
 28 errors
--- a/test/langtools/tools/javac/switchextra/CaseTest.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchextra/CaseTest.java	Wed Nov 13 09:16:04 2019 +0000
@@ -137,7 +137,7 @@
 
         StringWriter out = new StringWriter();
         JavacTask ct = (JavacTask) tool.getTask(out, null, noErrors,
-            List.of("-XDdev", "--enable-preview", "-source", sourceVersion), null,
+            List.of("-XDdev"), null,
             Arrays.asList(new MyFileObject(code)));
         return ct.parse().iterator().next();
     }
--- a/test/langtools/tools/javac/switchextra/DefiniteAssignment1.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchextra/DefiniteAssignment1.java	Wed Nov 13 09:16:04 2019 +0000
@@ -24,8 +24,8 @@
 /**
  * @test
  * @summary Verify that definite assignment works (legal code)
- * @compile --enable-preview -source ${jdk.version} DefiniteAssignment1.java
- * @run main/othervm --enable-preview DefiniteAssignment1
+ * @compile DefiniteAssignment1.java
+ * @run main DefiniteAssignment1
  */
 public class DefiniteAssignment1 {
     public static void main(String[] args) {
--- a/test/langtools/tools/javac/switchextra/DefiniteAssignment2.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchextra/DefiniteAssignment2.java	Wed Nov 13 09:16:04 2019 +0000
@@ -1,7 +1,7 @@
 /**
  * @test /nodynamiccopyright/
  * @summary Verify that definite assignment works (illegal code)
- * @compile/fail/ref=DefiniteAssignment2.out -XDrawDiagnostics --enable-preview -source ${jdk.version} DefiniteAssignment2.java
+ * @compile/fail/ref=DefiniteAssignment2.out -XDrawDiagnostics DefiniteAssignment2.java
  */
 public class DefiniteAssignment2 {
 
--- a/test/langtools/tools/javac/switchextra/DefiniteAssignment2.out	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchextra/DefiniteAssignment2.out	Wed Nov 13 09:16:04 2019 +0000
@@ -4,6 +4,4 @@
 DefiniteAssignment2.java:52:28: compiler.err.var.might.not.have.been.initialized: x
 DefiniteAssignment2.java:62:28: compiler.err.var.might.not.have.been.initialized: x
 DefiniteAssignment2.java:73:28: compiler.err.var.might.not.have.been.initialized: x
-- compiler.note.preview.filename: DefiniteAssignment2.java
-- compiler.note.preview.recompile
 6 errors
--- a/test/langtools/tools/javac/switchextra/MultipleLabelsExpression-old.out	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchextra/MultipleLabelsExpression-old.out	Wed Nov 13 09:16:04 2019 +0000
@@ -1,4 +1,4 @@
-MultipleLabelsExpression.java:31:16: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.switch.expressions)
-MultipleLabelsExpression.java:32:20: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.switch.rules)
-MultipleLabelsExpression.java:33:19: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.multiple.case.labels)
+MultipleLabelsExpression.java:31:16: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.switch.expressions), 9, 14
+MultipleLabelsExpression.java:32:20: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.switch.rules), 9, 14
+MultipleLabelsExpression.java:33:19: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.multiple.case.labels), 9, 14
 3 errors
--- a/test/langtools/tools/javac/switchextra/MultipleLabelsExpression.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchextra/MultipleLabelsExpression.java	Wed Nov 13 09:16:04 2019 +0000
@@ -3,8 +3,8 @@
  * @bug 8206986
  * @summary Verify cases with multiple labels work properly.
  * @compile/fail/ref=MultipleLabelsExpression-old.out -source 9 -Xlint:-options -XDrawDiagnostics MultipleLabelsExpression.java
- * @compile --enable-preview -source ${jdk.version} MultipleLabelsExpression.java
- * @run main/othervm --enable-preview MultipleLabelsExpression
+ * @compile MultipleLabelsExpression.java
+ * @run main MultipleLabelsExpression
  */
 
 import java.util.Objects;
--- a/test/langtools/tools/javac/switchextra/MultipleLabelsStatement-old.out	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchextra/MultipleLabelsStatement-old.out	Wed Nov 13 09:16:04 2019 +0000
@@ -1,2 +1,2 @@
-MultipleLabelsStatement.java:35:21: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.multiple.case.labels)
+MultipleLabelsStatement.java:35:21: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.multiple.case.labels), 9, 14
 1 error
--- a/test/langtools/tools/javac/switchextra/MultipleLabelsStatement.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchextra/MultipleLabelsStatement.java	Wed Nov 13 09:16:04 2019 +0000
@@ -3,8 +3,8 @@
  * @bug 8206986
  * @summary Verify cases with multiple labels work properly.
  * @compile/fail/ref=MultipleLabelsStatement-old.out -source 9 -Xlint:-options -XDrawDiagnostics MultipleLabelsStatement.java
- * @compile --enable-preview -source ${jdk.version} MultipleLabelsStatement.java
- * @run main/othervm --enable-preview MultipleLabelsStatement
+ * @compile MultipleLabelsStatement.java
+ * @run main MultipleLabelsStatement
  */
 
 import java.util.Objects;
--- a/test/langtools/tools/javac/switchextra/RuleParsingTest.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchextra/RuleParsingTest.java	Wed Nov 13 09:16:04 2019 +0000
@@ -95,7 +95,7 @@
 
         StringWriter out = new StringWriter();
         JavacTask ct = (JavacTask) tool.getTask(out, null, noErrors,
-            List.of("--enable-preview", "-source", sourceVersion), null,
+            List.of(), null,
             Arrays.asList(new MyFileObject(code.toString())));
         CompilationUnitTree cut = ct.parse().iterator().next();
         Trees trees = Trees.instance(ct);
--- a/test/langtools/tools/javac/switchextra/SwitchArrowBrokenConstant.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchextra/SwitchArrowBrokenConstant.java	Wed Nov 13 09:16:04 2019 +0000
@@ -3,7 +3,7 @@
  * @bug 8206986
  * @summary Verify reasonable errors are produced when neither ':' nor '->'
  *          is found are the expression of a case
- * @compile/fail/ref=SwitchArrowBrokenConstant.out -source ${jdk.version} --enable-preview -Xlint:-preview -XDrawDiagnostics SwitchArrowBrokenConstant.java
+ * @compile/fail/ref=SwitchArrowBrokenConstant.out -Xlint:-preview -XDrawDiagnostics SwitchArrowBrokenConstant.java
  */
 
 public class SwitchArrowBrokenConstant {
--- a/test/langtools/tools/javac/switchextra/SwitchArrowBrokenConstant.out	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchextra/SwitchArrowBrokenConstant.out	Wed Nov 13 09:16:04 2019 +0000
@@ -6,6 +6,4 @@
 SwitchArrowBrokenConstant.java:22:19: compiler.err.expected2: :, ->
 SwitchArrowBrokenConstant.java:25:20: compiler.err.expected2: :, ->
 SwitchArrowBrokenConstant.java:28:20: compiler.err.expected2: :, ->
-- compiler.note.preview.filename: SwitchArrowBrokenConstant.java
-- compiler.note.preview.recompile
 8 errors
--- a/test/langtools/tools/javac/switchextra/SwitchStatementArrow-old.out	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchextra/SwitchStatementArrow-old.out	Wed Nov 13 09:16:04 2019 +0000
@@ -1,3 +1,3 @@
-SwitchStatementArrow.java:41:20: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.switch.rules)
-SwitchStatementArrow.java:42:21: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.multiple.case.labels)
+SwitchStatementArrow.java:41:20: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.switch.rules), 9, 14
+SwitchStatementArrow.java:42:21: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.multiple.case.labels), 9, 14
 2 errors
--- a/test/langtools/tools/javac/switchextra/SwitchStatementArrow.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchextra/SwitchStatementArrow.java	Wed Nov 13 09:16:04 2019 +0000
@@ -3,8 +3,8 @@
  * @bug 8206986
  * @summary Verify rule cases work properly.
  * @compile/fail/ref=SwitchStatementArrow-old.out -source 9 -Xlint:-options -XDrawDiagnostics SwitchStatementArrow.java
- * @compile --enable-preview -source ${jdk.version} SwitchStatementArrow.java
- * @run main/othervm --enable-preview SwitchStatementArrow
+ * @compile SwitchStatementArrow.java
+ * @run main SwitchStatementArrow
  */
 
 import java.util.Objects;
--- a/test/langtools/tools/javac/switchextra/SwitchStatementBroken.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchextra/SwitchStatementBroken.java	Wed Nov 13 09:16:04 2019 +0000
@@ -2,7 +2,7 @@
  * @test /nodynamiccopyright/
  * @bug 8206986
  * @summary Verify that rule and ordinary cases cannot be mixed.
- * @compile/fail/ref=SwitchStatementBroken.out -XDrawDiagnostics --enable-preview -source ${jdk.version} SwitchStatementBroken.java
+ * @compile/fail/ref=SwitchStatementBroken.out -XDrawDiagnostics SwitchStatementBroken.java
  */
 
 public class SwitchStatementBroken {
--- a/test/langtools/tools/javac/switchextra/SwitchStatementBroken.out	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchextra/SwitchStatementBroken.out	Wed Nov 13 09:16:04 2019 +0000
@@ -1,4 +1,2 @@
 SwitchStatementBroken.java:15:13: compiler.err.switch.mixing.case.types
-- compiler.note.preview.filename: SwitchStatementBroken.java
-- compiler.note.preview.recompile
 1 error
--- a/test/langtools/tools/javac/switchextra/SwitchStatementBroken2.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchextra/SwitchStatementBroken2.java	Wed Nov 13 09:16:04 2019 +0000
@@ -2,7 +2,7 @@
  * @test /nodynamiccopyright/
  * @bug 8206986
  * @summary Verify that not allowed types of statements cannot be used in rule case.
- * @compile/fail/ref=SwitchStatementBroken2.out -XDrawDiagnostics --enable-preview -source ${jdk.version} SwitchStatementBroken2.java
+ * @compile/fail/ref=SwitchStatementBroken2.out -XDrawDiagnostics SwitchStatementBroken2.java
  */
 
 public class SwitchStatementBroken2 {
--- a/test/langtools/tools/javac/switchextra/SwitchStatementBroken2.out	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchextra/SwitchStatementBroken2.out	Wed Nov 13 09:16:04 2019 +0000
@@ -3,6 +3,4 @@
 SwitchStatementBroken2.java:19:23: compiler.err.switch.case.unexpected.statement
 SwitchStatementBroken2.java:22:27: compiler.err.variable.not.allowed
 SwitchStatementBroken2.java:23:24: compiler.err.switch.case.unexpected.statement
-- compiler.note.preview.filename: SwitchStatementBroken2.java
-- compiler.note.preview.recompile
 5 errors
--- a/test/langtools/tools/javac/switchextra/SwitchStatementScopesIsolated.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchextra/SwitchStatementScopesIsolated.java	Wed Nov 13 09:16:04 2019 +0000
@@ -2,7 +2,7 @@
  * @test /nodynamiccopyright/
  * @bug 8206986
  * @summary Verify that scopes in rule cases are isolated.
- * @compile/fail/ref=SwitchStatementScopesIsolated.out -XDrawDiagnostics --enable-preview -source ${jdk.version} SwitchStatementScopesIsolated.java
+ * @compile/fail/ref=SwitchStatementScopesIsolated.out -XDrawDiagnostics SwitchStatementScopesIsolated.java
  */
 
 public class SwitchStatementScopesIsolated {
--- a/test/langtools/tools/javac/switchextra/SwitchStatementScopesIsolated.out	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/javac/switchextra/SwitchStatementScopesIsolated.out	Wed Nov 13 09:16:04 2019 +0000
@@ -1,5 +1,3 @@
 SwitchStatementScopesIsolated.java:13:25: compiler.err.cant.resolve.location: kindname.variable, res, , , (compiler.misc.location: kindname.class, SwitchStatementScopesIsolated, null)
 SwitchStatementScopesIsolated.java:14:26: compiler.err.cant.resolve.location: kindname.variable, res, , , (compiler.misc.location: kindname.class, SwitchStatementScopesIsolated, null)
-- compiler.note.preview.filename: SwitchStatementScopesIsolated.java
-- compiler.note.preview.recompile
 2 errors
--- a/test/langtools/tools/jdeps/listdeps/ListModuleDeps.java	Tue Nov 12 15:07:15 2019 +0000
+++ b/test/langtools/tools/jdeps/listdeps/ListModuleDeps.java	Wed Nov 13 09:16:04 2019 +0000
@@ -92,7 +92,6 @@
     public Object[][] jdkModules() {
         return new Object[][]{
             {"jdk.compiler", new String[]{
-                                "java.base/jdk.internal",
                                 "java.base/jdk.internal.jmod",
                                 "java.base/jdk.internal.misc",
                                 "java.base/sun.reflect.annotation",