# HG changeset patch # User lana # Date 1370417831 25200 # Node ID 1bbdae29327c5fb24fe39360b1e61c2f81050832 # Parent 14a0ae3ca9733f91b9f4d632264ac8a0098e33a1# Parent 6ae3db58fff1e14faf9beb34c62cbf243a8db19e Merge diff -r 14a0ae3ca973 -r 1bbdae29327c .hgtags --- a/.hgtags Mon Jun 03 16:37:13 2013 +0400 +++ b/.hgtags Wed Jun 05 00:37:11 2013 -0700 @@ -212,3 +212,4 @@ e517701a4d0e25ae9c7945bca6e1762a8c5d8aa6 jdk8-b88 4dec41b3c5e3bb616f0c6f15830d940905aa5d16 jdk8-b89 f09ab0c416185e3cba371e81bcb6a16060c90f44 jdk8-b90 +80b6c3172dc2cfceb022411292d290a967f9c728 jdk8-b91 diff -r 14a0ae3ca973 -r 1bbdae29327c .hgtags-top-repo --- a/.hgtags-top-repo Mon Jun 03 16:37:13 2013 +0400 +++ b/.hgtags-top-repo Wed Jun 05 00:37:11 2013 -0700 @@ -212,3 +212,4 @@ e1a929afcfc492470d50be0b6b0e8dc77d3760b9 jdk8-b88 892a0196d10c67f3a12f0eefb0bb536e423d8868 jdk8-b89 69b773a221b956a3386933ecdbfeccee0edeac47 jdk8-b90 +cb51fb4789ac0b8be4056482077ddfb8f3bd3805 jdk8-b91 diff -r 14a0ae3ca973 -r 1bbdae29327c common/autoconf/basics.m4 --- a/common/autoconf/basics.m4 Mon Jun 03 16:37:13 2013 +0400 +++ b/common/autoconf/basics.m4 Wed Jun 05 00:37:11 2013 -0700 @@ -23,14 +23,23 @@ # questions. # +# Test if $1 is a valid argument to $3 (often is $JAVA passed as $3) +# If so, then append $1 to $2\ +# Also set JVM_ARG_OK to true/false depending on outcome. AC_DEFUN([ADD_JVM_ARG_IF_OK], [ - # Test if $1 is a valid argument to $3 (often is $JAVA passed as $3) - # If so, then append $1 to $2 - FOUND_WARN=`$3 $1 -version 2>&1 | grep -i warn` - FOUND_VERSION=`$3 $1 -version 2>&1 | grep " version \""` + $ECHO "Check if jvm arg is ok: $1" >&AS_MESSAGE_LOG_FD + $ECHO "Command: $3 $1 -version" >&AS_MESSAGE_LOG_FD + OUTPUT=`$3 $1 -version 2>&1` + FOUND_WARN=`$ECHO "$OUTPUT" | grep -i warn` + FOUND_VERSION=`$ECHO $OUTPUT | grep " version \""` if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then $2="[$]$2 $1" + JVM_ARG_OK=true + else + $ECHO "Arg failed:" >&AS_MESSAGE_LOG_FD + $ECHO "$OUTPUT" >&AS_MESSAGE_LOG_FD + JVM_ARG_OK=false fi ]) @@ -51,16 +60,19 @@ else # We're on a posix platform. Hooray! :) path="[$]$1" - - if test ! -f "$path" && test ! -d "$path"; then - AC_MSG_ERROR([The path of $1, which resolves as "$path", is not found.]) - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then AC_MSG_NOTICE([The path of $1, which resolves as "$path", is invalid.]) AC_MSG_ERROR([Spaces are not allowed in this path.]) fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + AC_MSG_ERROR([The path of $1, which resolves as "$path", is not found.]) + fi + + $1="`cd "$path"; $THEPWDCMD`" fi ]) diff -r 14a0ae3ca973 -r 1bbdae29327c common/autoconf/build-performance.m4 --- a/common/autoconf/build-performance.m4 Mon Jun 03 16:37:13 2013 +0400 +++ b/common/autoconf/build-performance.m4 Wed Jun 05 00:37:11 2013 -0700 @@ -278,60 +278,37 @@ fi AC_SUBST(SJAVAC_SERVER_JAVA) -AC_ARG_WITH(sjavac-server-cores, [AS_HELP_STRING([--with-sjavac-server-cores], - [use at most this number of concurrent threads on the sjavac server @<:@probed@:>@])]) -if test "x$with_sjavac_server_cores" != x; then - SJAVAC_SERVER_CORES="$with_sjavac_server_cores" -else - if test "$NUM_CORES" -gt 16; then - # We set this arbitrary limit because we want to limit the heap - # size of the javac server. - # In the future we will make the javac compilers in the server - # share more and more state, thus enabling us to use more and - # more concurrent threads in the server. - SJAVAC_SERVER_CORES="16" - else - SJAVAC_SERVER_CORES="$NUM_CORES" +if test "$MEMORY_SIZE" -gt "2500"; then + ADD_JVM_ARG_IF_OK([-d64],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA]) + if test "$JVM_ARG_OK" = true; then + JVM_64BIT=true + JVM_ARG_OK=false + fi fi +if test "$JVM_64BIT" = true; then if test "$MEMORY_SIZE" -gt "17000"; then - MAX_HEAP_MEM=10000 - ADD_JVM_ARG_IF_OK([-d64],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA]) ADD_JVM_ARG_IF_OK([-Xms10G -Xmx10G],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA]) - elif test "$MEMORY_SIZE" -gt "10000"; then - MAX_HEAP_MEM=6000 - ADD_JVM_ARG_IF_OK([-d64],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA]) + fi + if test "$MEMORY_SIZE" -gt "10000" && test "$JVM_ARG_OK" = false; then ADD_JVM_ARG_IF_OK([-Xms6G -Xmx6G],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA]) - elif test "$MEMORY_SIZE" -gt "5000"; then - MAX_HEAP_MEM=3000 - ADD_JVM_ARG_IF_OK([-d64],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA]) + fi + if test "$MEMORY_SIZE" -gt "5000" && test "$JVM_ARG_OK" = false; then ADD_JVM_ARG_IF_OK([-Xms1G -Xmx3G],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA]) - elif test "$MEMORY_SIZE" -gt "3800"; then - MAX_HEAP_MEM=2500 + fi + if test "$MEMORY_SIZE" -gt "3800" && test "$JVM_ARG_OK" = false; then ADD_JVM_ARG_IF_OK([-Xms1G -Xmx2500M],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA]) - elif test "$MEMORY_SIZE" -gt "1900"; then - MAX_HEAP_MEM=1200 - ADD_JVM_ARG_IF_OK([-Xms700M -Xmx1400M],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA]) - elif test "$MEMORY_SIZE" -gt "1000"; then - MAX_HEAP_MEM=900 - ADD_JVM_ARG_IF_OK([-Xms400M -Xmx1100M],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA]) - else - MAX_HEAP_MEM=512 - ADD_JVM_ARG_IF_OK([-Xms256M -Xmx512M],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA]) fi - - ADD_JVM_ARG_IF_OK([-XX:PermSize=32m],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA]) - ADD_JVM_ARG_IF_OK([-XX:MaxPermSize=160m],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA]) - ADD_JVM_ARG_IF_OK([-XX:ThreadStackSize=$STACK_SIZE],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA]) - - MAX_COMPILERS_IN_HEAP=`expr $MAX_HEAP_MEM / 501` - if test "$SJAVAC_SERVER_CORES" -gt "$MAX_COMPILERS_IN_HEAP"; then - AC_MSG_CHECKING([if number of server cores must be reduced]) - SJAVAC_SERVER_CORES="$MAX_COMPILERS_IN_HEAP" - AC_MSG_RESULT([yes, to $SJAVAC_SERVER_CORES with max heap size $MAX_HEAP_MEM MB]) - fi -fi -AC_SUBST(SJAVAC_SERVER_CORES) +fi +if test "$MEMORY_SIZE" -gt "2500" && test "$JVM_ARG_OK" = false; then + ADD_JVM_ARG_IF_OK([-Xms1000M -Xmx1500M],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA]) +fi +if test "$MEMORY_SIZE" -gt "1000" && test "$JVM_ARG_OK" = false; then + ADD_JVM_ARG_IF_OK([-Xms400M -Xmx1100M],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA]) +fi +if test "$JVM_ARG_OK" = false; then + ADD_JVM_ARG_IF_OK([-Xms256M -Xmx512M],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA]) +fi AC_MSG_CHECKING([whether to use sjavac]) AC_ARG_ENABLE([sjavac], [AS_HELP_STRING([--enable-sjavac], diff -r 14a0ae3ca973 -r 1bbdae29327c common/autoconf/generated-configure.sh --- a/common/autoconf/generated-configure.sh Mon Jun 03 16:37:13 2013 +0400 +++ b/common/autoconf/generated-configure.sh Wed Jun 05 00:37:11 2013 -0700 @@ -599,7 +599,6 @@ USE_PRECOMPILED_HEADER SJAVAC_SERVER_DIR ENABLE_SJAVAC -SJAVAC_SERVER_CORES SJAVAC_SERVER_JAVA JOBS MEMORY_SIZE @@ -682,6 +681,8 @@ SHARED_LIBRARY OBJ_SUFFIX COMPILER_NAME +JTREGEXE +JT_HOME LIPO ac_ct_OBJDUMP OBJDUMP @@ -1005,6 +1006,7 @@ with_dxsdk with_dxsdk_lib with_dxsdk_include +with_jtreg with_extra_cflags with_extra_cxxflags with_extra_ldflags @@ -1025,7 +1027,6 @@ with_memory_size with_jobs with_sjavac_server_java -with_sjavac_server_cores enable_sjavac enable_precompiled_headers enable_ccache @@ -1764,6 +1765,7 @@ [probed] --with-dxsdk-include the DirectX SDK include directory (Windows only) [probed] + --with-jtreg Regression Test Harness [probed] --with-extra-cflags extra flags to be used when compiling jdk c-files --with-extra-cxxflags extra flags to be used when compiling jdk c++-files --with-extra-ldflags extra flags to be used when linking jdk @@ -1796,9 +1798,6 @@ --with-sjavac-server-java use this java binary for running the sjavac background server [Boot JDK java] - --with-sjavac-server-cores - use at most this number of concurrent threads on the - sjavac server [probed] --with-ccache-dir where to store ccache files [~/.ccache] Some influential environment variables: @@ -3077,6 +3076,9 @@ # questions. # +# Test if $1 is a valid argument to $3 (often is $JAVA passed as $3) +# If so, then append $1 to $2\ +# Also set JVM_ARG_OK to true/false depending on outcome. # This will make sure the given variable points to a full and proper @@ -3725,6 +3727,9 @@ +# Setup the JTREG paths + + # # Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -3775,7 +3780,7 @@ #CUSTOM_AUTOCONF_INCLUDE # Do not change or remove the following line, it is needed for consistency checks: -DATE_WHEN_GENERATED=1367502949 +DATE_WHEN_GENERATED=1369723814 ############################################################################### # @@ -7389,17 +7394,20 @@ else # We're on a posix platform. Hooray! :) path="$SRC_ROOT" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of SRC_ROOT, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of SRC_ROOT, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of SRC_ROOT, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of SRC_ROOT, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + SRC_ROOT="`cd "$path"; $THEPWDCMD`" fi @@ -7508,17 +7516,20 @@ else # We're on a posix platform. Hooray! :) path="$CURDIR" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of CURDIR, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of CURDIR, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of CURDIR, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of CURDIR, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + CURDIR="`cd "$path"; $THEPWDCMD`" fi @@ -8104,17 +8115,20 @@ else # We're on a posix platform. Hooray! :) path="$OUTPUT_ROOT" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of OUTPUT_ROOT, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of OUTPUT_ROOT, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of OUTPUT_ROOT, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of OUTPUT_ROOT, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + OUTPUT_ROOT="`cd "$path"; $THEPWDCMD`" fi @@ -11161,17 +11175,20 @@ else # We're on a posix platform. Hooray! :) path="$BOOT_JDK" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + BOOT_JDK="`cd "$path"; $THEPWDCMD`" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Boot JDK" >&5 @@ -11490,17 +11507,20 @@ else # We're on a posix platform. Hooray! :) path="$BOOT_JDK" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + BOOT_JDK="`cd "$path"; $THEPWDCMD`" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Boot JDK" >&5 @@ -11633,17 +11653,20 @@ else # We're on a posix platform. Hooray! :) path="$JAVA_HOME_PROCESSED" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of JAVA_HOME_PROCESSED, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of JAVA_HOME_PROCESSED, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of JAVA_HOME_PROCESSED, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of JAVA_HOME_PROCESSED, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + JAVA_HOME_PROCESSED="`cd "$path"; $THEPWDCMD`" fi if test ! -d "$JAVA_HOME_PROCESSED"; then @@ -11802,17 +11825,20 @@ else # We're on a posix platform. Hooray! :) path="$BOOT_JDK" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + BOOT_JDK="`cd "$path"; $THEPWDCMD`" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Boot JDK" >&5 @@ -11987,17 +12013,20 @@ else # We're on a posix platform. Hooray! :) path="$BOOT_JDK" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + BOOT_JDK="`cd "$path"; $THEPWDCMD`" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Boot JDK" >&5 @@ -12312,17 +12341,20 @@ else # We're on a posix platform. Hooray! :) path="$BOOT_JDK" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + BOOT_JDK="`cd "$path"; $THEPWDCMD`" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Boot JDK" >&5 @@ -12524,17 +12556,20 @@ else # We're on a posix platform. Hooray! :) path="$BOOT_JDK" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + BOOT_JDK="`cd "$path"; $THEPWDCMD`" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Boot JDK" >&5 @@ -12701,17 +12736,20 @@ else # We're on a posix platform. Hooray! :) path="$BOOT_JDK" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + BOOT_JDK="`cd "$path"; $THEPWDCMD`" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Boot JDK" >&5 @@ -12906,17 +12944,20 @@ else # We're on a posix platform. Hooray! :) path="$BOOT_JDK" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + BOOT_JDK="`cd "$path"; $THEPWDCMD`" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Boot JDK" >&5 @@ -13083,17 +13124,20 @@ else # We're on a posix platform. Hooray! :) path="$BOOT_JDK" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + BOOT_JDK="`cd "$path"; $THEPWDCMD`" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Boot JDK" >&5 @@ -13288,17 +13332,20 @@ else # We're on a posix platform. Hooray! :) path="$BOOT_JDK" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + BOOT_JDK="`cd "$path"; $THEPWDCMD`" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Boot JDK" >&5 @@ -13465,17 +13512,20 @@ else # We're on a posix platform. Hooray! :) path="$BOOT_JDK" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + BOOT_JDK="`cd "$path"; $THEPWDCMD`" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Boot JDK" >&5 @@ -13670,17 +13720,20 @@ else # We're on a posix platform. Hooray! :) path="$BOOT_JDK" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + BOOT_JDK="`cd "$path"; $THEPWDCMD`" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Boot JDK" >&5 @@ -13847,17 +13900,20 @@ else # We're on a posix platform. Hooray! :) path="$BOOT_JDK" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + BOOT_JDK="`cd "$path"; $THEPWDCMD`" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Boot JDK" >&5 @@ -14039,17 +14095,20 @@ else # We're on a posix platform. Hooray! :) path="$BOOT_JDK" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + BOOT_JDK="`cd "$path"; $THEPWDCMD`" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Boot JDK" >&5 @@ -14214,17 +14273,20 @@ else # We're on a posix platform. Hooray! :) path="$BOOT_JDK" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + BOOT_JDK="`cd "$path"; $THEPWDCMD`" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Boot JDK" >&5 @@ -14407,17 +14469,20 @@ else # We're on a posix platform. Hooray! :) path="$BOOT_JDK" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + BOOT_JDK="`cd "$path"; $THEPWDCMD`" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Boot JDK" >&5 @@ -14582,17 +14647,20 @@ else # We're on a posix platform. Hooray! :) path="$BOOT_JDK" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + BOOT_JDK="`cd "$path"; $THEPWDCMD`" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Boot JDK" >&5 @@ -14774,17 +14842,20 @@ else # We're on a posix platform. Hooray! :) path="$BOOT_JDK" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + BOOT_JDK="`cd "$path"; $THEPWDCMD`" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Boot JDK" >&5 @@ -14949,17 +15020,20 @@ else # We're on a posix platform. Hooray! :) path="$BOOT_JDK" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + BOOT_JDK="`cd "$path"; $THEPWDCMD`" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Boot JDK" >&5 @@ -15142,17 +15216,20 @@ else # We're on a posix platform. Hooray! :) path="$BOOT_JDK" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + BOOT_JDK="`cd "$path"; $THEPWDCMD`" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Boot JDK" >&5 @@ -15317,17 +15394,20 @@ else # We're on a posix platform. Hooray! :) path="$BOOT_JDK" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + BOOT_JDK="`cd "$path"; $THEPWDCMD`" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Boot JDK" >&5 @@ -15491,17 +15571,20 @@ else # We're on a posix platform. Hooray! :) path="$BOOT_JDK" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of BOOT_JDK, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of BOOT_JDK, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + BOOT_JDK="`cd "$path"; $THEPWDCMD`" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Boot JDK" >&5 @@ -15705,73 +15788,115 @@ # Minimum amount of heap memory. - # Test if -Xms64M is a valid argument to $JAVA (often is $JAVA passed as $JAVA) - # If so, then append -Xms64M to boot_jdk_jvmargs - FOUND_WARN=`$JAVA -Xms64M -version 2>&1 | grep -i warn` - FOUND_VERSION=`$JAVA -Xms64M -version 2>&1 | grep " version \""` + $ECHO "Check if jvm arg is ok: -Xms64M" >&5 + $ECHO "Command: $JAVA -Xms64M -version" >&5 + OUTPUT=`$JAVA -Xms64M -version 2>&1` + FOUND_WARN=`$ECHO "$OUTPUT" | grep -i warn` + FOUND_VERSION=`$ECHO $OUTPUT | grep " version \""` if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then boot_jdk_jvmargs="$boot_jdk_jvmargs -Xms64M" + JVM_ARG_OK=true + else + $ECHO "Arg failed:" >&5 + $ECHO "$OUTPUT" >&5 + JVM_ARG_OK=false fi if test "x$OPENJDK_TARGET_OS" = "xmacosx"; then # Why does macosx need more heap? Its the huge JDK batch. - # Test if -Xmx1600M is a valid argument to $JAVA (often is $JAVA passed as $JAVA) - # If so, then append -Xmx1600M to boot_jdk_jvmargs - FOUND_WARN=`$JAVA -Xmx1600M -version 2>&1 | grep -i warn` - FOUND_VERSION=`$JAVA -Xmx1600M -version 2>&1 | grep " version \""` + $ECHO "Check if jvm arg is ok: -Xmx1600M" >&5 + $ECHO "Command: $JAVA -Xmx1600M -version" >&5 + OUTPUT=`$JAVA -Xmx1600M -version 2>&1` + FOUND_WARN=`$ECHO "$OUTPUT" | grep -i warn` + FOUND_VERSION=`$ECHO $OUTPUT | grep " version \""` if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then boot_jdk_jvmargs="$boot_jdk_jvmargs -Xmx1600M" - fi - - else - - # Test if -Xmx1100M is a valid argument to $JAVA (often is $JAVA passed as $JAVA) - # If so, then append -Xmx1100M to boot_jdk_jvmargs - FOUND_WARN=`$JAVA -Xmx1100M -version 2>&1 | grep -i warn` - FOUND_VERSION=`$JAVA -Xmx1100M -version 2>&1 | grep " version \""` + JVM_ARG_OK=true + else + $ECHO "Arg failed:" >&5 + $ECHO "$OUTPUT" >&5 + JVM_ARG_OK=false + fi + + else + + $ECHO "Check if jvm arg is ok: -Xmx1100M" >&5 + $ECHO "Command: $JAVA -Xmx1100M -version" >&5 + OUTPUT=`$JAVA -Xmx1100M -version 2>&1` + FOUND_WARN=`$ECHO "$OUTPUT" | grep -i warn` + FOUND_VERSION=`$ECHO $OUTPUT | grep " version \""` if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then boot_jdk_jvmargs="$boot_jdk_jvmargs -Xmx1100M" + JVM_ARG_OK=true + else + $ECHO "Arg failed:" >&5 + $ECHO "$OUTPUT" >&5 + JVM_ARG_OK=false fi fi # When is adding -client something that speeds up the JVM? # ADD_JVM_ARG_IF_OK([-client],boot_jdk_jvmargs,[$JAVA]) - # Test if -XX:PermSize=32m is a valid argument to $JAVA (often is $JAVA passed as $JAVA) - # If so, then append -XX:PermSize=32m to boot_jdk_jvmargs - FOUND_WARN=`$JAVA -XX:PermSize=32m -version 2>&1 | grep -i warn` - FOUND_VERSION=`$JAVA -XX:PermSize=32m -version 2>&1 | grep " version \""` + $ECHO "Check if jvm arg is ok: -XX:PermSize=32m" >&5 + $ECHO "Command: $JAVA -XX:PermSize=32m -version" >&5 + OUTPUT=`$JAVA -XX:PermSize=32m -version 2>&1` + FOUND_WARN=`$ECHO "$OUTPUT" | grep -i warn` + FOUND_VERSION=`$ECHO $OUTPUT | grep " version \""` if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then boot_jdk_jvmargs="$boot_jdk_jvmargs -XX:PermSize=32m" - fi - - - # Test if -XX:MaxPermSize=160m is a valid argument to $JAVA (often is $JAVA passed as $JAVA) - # If so, then append -XX:MaxPermSize=160m to boot_jdk_jvmargs - FOUND_WARN=`$JAVA -XX:MaxPermSize=160m -version 2>&1 | grep -i warn` - FOUND_VERSION=`$JAVA -XX:MaxPermSize=160m -version 2>&1 | grep " version \""` + JVM_ARG_OK=true + else + $ECHO "Arg failed:" >&5 + $ECHO "$OUTPUT" >&5 + JVM_ARG_OK=false + fi + + + $ECHO "Check if jvm arg is ok: -XX:MaxPermSize=160m" >&5 + $ECHO "Command: $JAVA -XX:MaxPermSize=160m -version" >&5 + OUTPUT=`$JAVA -XX:MaxPermSize=160m -version 2>&1` + FOUND_WARN=`$ECHO "$OUTPUT" | grep -i warn` + FOUND_VERSION=`$ECHO $OUTPUT | grep " version \""` if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then boot_jdk_jvmargs="$boot_jdk_jvmargs -XX:MaxPermSize=160m" - fi - - - # Test if -XX:ThreadStackSize=$STACK_SIZE is a valid argument to $JAVA (often is $JAVA passed as $JAVA) - # If so, then append -XX:ThreadStackSize=$STACK_SIZE to boot_jdk_jvmargs - FOUND_WARN=`$JAVA -XX:ThreadStackSize=$STACK_SIZE -version 2>&1 | grep -i warn` - FOUND_VERSION=`$JAVA -XX:ThreadStackSize=$STACK_SIZE -version 2>&1 | grep " version \""` + JVM_ARG_OK=true + else + $ECHO "Arg failed:" >&5 + $ECHO "$OUTPUT" >&5 + JVM_ARG_OK=false + fi + + + $ECHO "Check if jvm arg is ok: -XX:ThreadStackSize=$STACK_SIZE" >&5 + $ECHO "Command: $JAVA -XX:ThreadStackSize=$STACK_SIZE -version" >&5 + OUTPUT=`$JAVA -XX:ThreadStackSize=$STACK_SIZE -version 2>&1` + FOUND_WARN=`$ECHO "$OUTPUT" | grep -i warn` + FOUND_VERSION=`$ECHO $OUTPUT | grep " version \""` if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then boot_jdk_jvmargs="$boot_jdk_jvmargs -XX:ThreadStackSize=$STACK_SIZE" + JVM_ARG_OK=true + else + $ECHO "Arg failed:" >&5 + $ECHO "$OUTPUT" >&5 + JVM_ARG_OK=false fi # Disable special log output when a debug build is used as Boot JDK... - # Test if -XX:-PrintVMOptions -XX:-UnlockDiagnosticVMOptions -XX:-LogVMOutput is a valid argument to $JAVA (often is $JAVA passed as $JAVA) - # If so, then append -XX:-PrintVMOptions -XX:-UnlockDiagnosticVMOptions -XX:-LogVMOutput to boot_jdk_jvmargs - FOUND_WARN=`$JAVA -XX:-PrintVMOptions -XX:-UnlockDiagnosticVMOptions -XX:-LogVMOutput -version 2>&1 | grep -i warn` - FOUND_VERSION=`$JAVA -XX:-PrintVMOptions -XX:-UnlockDiagnosticVMOptions -XX:-LogVMOutput -version 2>&1 | grep " version \""` + $ECHO "Check if jvm arg is ok: -XX:-PrintVMOptions -XX:-UnlockDiagnosticVMOptions -XX:-LogVMOutput" >&5 + $ECHO "Command: $JAVA -XX:-PrintVMOptions -XX:-UnlockDiagnosticVMOptions -XX:-LogVMOutput -version" >&5 + OUTPUT=`$JAVA -XX:-PrintVMOptions -XX:-UnlockDiagnosticVMOptions -XX:-LogVMOutput -version 2>&1` + FOUND_WARN=`$ECHO "$OUTPUT" | grep -i warn` + FOUND_VERSION=`$ECHO $OUTPUT | grep " version \""` if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then boot_jdk_jvmargs="$boot_jdk_jvmargs -XX:-PrintVMOptions -XX:-UnlockDiagnosticVMOptions -XX:-LogVMOutput" + JVM_ARG_OK=true + else + $ECHO "Arg failed:" >&5 + $ECHO "$OUTPUT" >&5 + JVM_ARG_OK=false fi fi @@ -16132,6 +16257,157 @@ # Locate the actual tools + +# Check whether --with-jtreg was given. +if test "${with_jtreg+set}" = set; then : + withval=$with_jtreg; +fi + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for JTReg Regression Test Harness" >&5 +$as_echo_n "checking for JTReg Regression Test Harness... " >&6; } + + if test "x$with_jtreg" != x; then + JT_HOME="$with_jtreg" + + if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then + + # Input might be given as Windows format, start by converting to + # unix format. + path="$JT_HOME" + new_path=`$CYGPATH -u "$path"` + + # Cygwin tries to hide some aspects of the Windows file system, such that binaries are + # named .exe but called without that suffix. Therefore, "foo" and "foo.exe" are considered + # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then + # "foo.exe" is OK but "foo" is an error. + # + # This test is therefore slightly more accurate than "test -f" to check for file precense. + # It is also a way to make sure we got the proper file name for the real test later on. + test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` + if test "x$test_shortpath" = x; then + { $as_echo "$as_me:${as_lineno-$LINENO}: The path of JT_HOME, which resolves as \"$path\", is invalid." >&5 +$as_echo "$as_me: The path of JT_HOME, which resolves as \"$path\", is invalid." >&6;} + as_fn_error $? "Cannot locate the the path of JT_HOME" "$LINENO" 5 + fi + + # Call helper function which possibly converts this using DOS-style short mode. + # If so, the updated path is stored in $new_path. + + input_path="$new_path" + # Check if we need to convert this using DOS-style short mode. If the path + # contains just simple characters, use it. Otherwise (spaces, weird characters), + # take no chances and rewrite it. + # Note: m4 eats our [], so we need to use [ and ] instead. + has_forbidden_chars=`$ECHO "$input_path" | $GREP [^-._/a-zA-Z0-9]` + if test "x$has_forbidden_chars" != x; then + # Now convert it to mixed DOS-style, short mode (no spaces, and / instead of \) + shortmode_path=`$CYGPATH -s -m -a "$input_path"` + path_after_shortmode=`$CYGPATH -u "$shortmode_path"` + if test "x$path_after_shortmode" != "x$input_to_shortpath"; then + # Going to short mode and back again did indeed matter. Since short mode is + # case insensitive, let's make it lowercase to improve readability. + shortmode_path=`$ECHO "$shortmode_path" | $TR 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + # Now convert it back to Unix-stile (cygpath) + input_path=`$CYGPATH -u "$shortmode_path"` + new_path="$input_path" + fi + fi + + test_cygdrive_prefix=`$ECHO $input_path | $GREP ^/cygdrive/` + if test "x$test_cygdrive_prefix" = x; then + # As a simple fix, exclude /usr/bin since it's not a real path. + if test "x`$ECHO $new_path | $GREP ^/usr/bin/`" = x; then + # The path is in a Cygwin special directory (e.g. /home). We need this converted to + # a path prefixed by /cygdrive for fixpath to work. + new_path="$CYGWIN_ROOT_PATH$input_path" + fi + fi + + + if test "x$path" != "x$new_path"; then + JT_HOME="$new_path" + { $as_echo "$as_me:${as_lineno-$LINENO}: Rewriting JT_HOME to \"$new_path\"" >&5 +$as_echo "$as_me: Rewriting JT_HOME to \"$new_path\"" >&6;} + fi + + elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then + + path="$JT_HOME" + has_colon=`$ECHO $path | $GREP ^.:` + new_path="$path" + if test "x$has_colon" = x; then + # Not in mixed or Windows style, start by that. + new_path=`cmd //c echo $path` + fi + + + input_path="$new_path" + # Check if we need to convert this using DOS-style short mode. If the path + # contains just simple characters, use it. Otherwise (spaces, weird characters), + # take no chances and rewrite it. + # Note: m4 eats our [], so we need to use [ and ] instead. + has_forbidden_chars=`$ECHO "$input_path" | $GREP [^-_/:a-zA-Z0-9]` + if test "x$has_forbidden_chars" != x; then + # Now convert it to mixed DOS-style, short mode (no spaces, and / instead of \) + new_path=`cmd /c "for %A in (\"$input_path\") do @echo %~sA"|$TR \\\\\\\\ / | $TR 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + fi + + + windows_path="$new_path" + if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then + unix_path=`$CYGPATH -u "$windows_path"` + new_path="$unix_path" + elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then + unix_path=`$ECHO "$windows_path" | $SED -e 's,^\\(.\\):,/\\1,g' -e 's,\\\\,/,g'` + new_path="$unix_path" + fi + + if test "x$path" != "x$new_path"; then + JT_HOME="$new_path" + { $as_echo "$as_me:${as_lineno-$LINENO}: Rewriting JT_HOME to \"$new_path\"" >&5 +$as_echo "$as_me: Rewriting JT_HOME to \"$new_path\"" >&6;} + fi + + # Save the first 10 bytes of this path to the storage, so fixpath can work. + all_fixpath_prefixes=("${all_fixpath_prefixes[@]}" "${new_path:0:10}") + + else + # We're on a posix platform. Hooray! :) + path="$JT_HOME" + has_space=`$ECHO "$path" | $GREP " "` + if test "x$has_space" != x; then + { $as_echo "$as_me:${as_lineno-$LINENO}: The path of JT_HOME, which resolves as \"$path\", is invalid." >&5 +$as_echo "$as_me: The path of JT_HOME, which resolves as \"$path\", is invalid." >&6;} + as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 + fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of JT_HOME, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + JT_HOME="`cd "$path"; $THEPWDCMD`" + fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $JT_HOME" >&5 +$as_echo "$JT_HOME" >&6; } + + # jtreg win32 script works for everybody + JTREGEXE="$JT_HOME/win32/bin/jtreg" + if test ! -f "$JTREGEXE"; then + as_fn_error $? "JTReg executable does not exist: $JTREGEXE" "$LINENO" 5 + fi + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + fi + + + + + if test "x$OPENJDK_TARGET_OS" = "xwindows"; then # Store path to cygwin link.exe to help excluding it when searching for @@ -17088,17 +17364,20 @@ else # We're on a posix platform. Hooray! :) path="$MSVCR_DLL" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of MSVCR_DLL, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of MSVCR_DLL, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of MSVCR_DLL, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of MSVCR_DLL, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + MSVCR_DLL="`cd "$path"; $THEPWDCMD`" fi @@ -17242,17 +17521,20 @@ else # We're on a posix platform. Hooray! :) path="$dxsdk_path" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of dxsdk_path, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of dxsdk_path, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of dxsdk_path, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of dxsdk_path, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + dxsdk_path="`cd "$path"; $THEPWDCMD`" fi @@ -17377,17 +17659,20 @@ else # We're on a posix platform. Hooray! :) path="$DXSDK_LIB_PATH" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of DXSDK_LIB_PATH, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of DXSDK_LIB_PATH, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of DXSDK_LIB_PATH, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of DXSDK_LIB_PATH, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + DXSDK_LIB_PATH="`cd "$path"; $THEPWDCMD`" fi @@ -17510,17 +17795,20 @@ else # We're on a posix platform. Hooray! :) path="$DXSDK_INCLUDE_PATH" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of DXSDK_INCLUDE_PATH, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of DXSDK_INCLUDE_PATH, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of DXSDK_INCLUDE_PATH, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of DXSDK_INCLUDE_PATH, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + DXSDK_INCLUDE_PATH="`cd "$path"; $THEPWDCMD`" fi @@ -28199,6 +28487,8 @@ fi + + # Restore old path without tools dir PATH="$OLD_PATH" @@ -30828,17 +31118,20 @@ else # We're on a posix platform. Hooray! :) path="$with_freetype" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of with_freetype, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of with_freetype, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of with_freetype, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of with_freetype, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + with_freetype="`cd "$path"; $THEPWDCMD`" fi FREETYPE2_LIBS="-L$with_freetype/lib -lfreetype" @@ -31127,17 +31420,20 @@ else # We're on a posix platform. Hooray! :) path="$FREETYPELOCATION" - - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of FREETYPELOCATION, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - has_space=`$ECHO "$path" | $GREP " "` if test "x$has_space" != x; then { $as_echo "$as_me:${as_lineno-$LINENO}: The path of FREETYPELOCATION, which resolves as \"$path\", is invalid." >&5 $as_echo "$as_me: The path of FREETYPELOCATION, which resolves as \"$path\", is invalid." >&6;} as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 fi + + # Use eval to expand a potential ~ + eval path="$path" + if test ! -f "$path" && test ! -d "$path"; then + as_fn_error $? "The path of FREETYPELOCATION, which resolves as \"$path\", is not found." "$LINENO" 5 + fi + + FREETYPELOCATION="`cd "$path"; $THEPWDCMD`" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for freetype in some standard windows locations" >&5 @@ -32664,192 +32960,183 @@ SJAVAC_SERVER_JAVA="" # Hotspot specific options. - # Test if -verbosegc is a valid argument to $JAVA (often is $JAVA passed as $JAVA) - # If so, then append -verbosegc to SJAVAC_SERVER_JAVA - FOUND_WARN=`$JAVA -verbosegc -version 2>&1 | grep -i warn` - FOUND_VERSION=`$JAVA -verbosegc -version 2>&1 | grep " version \""` + $ECHO "Check if jvm arg is ok: -verbosegc" >&5 + $ECHO "Command: $JAVA -verbosegc -version" >&5 + OUTPUT=`$JAVA -verbosegc -version 2>&1` + FOUND_WARN=`$ECHO "$OUTPUT" | grep -i warn` + FOUND_VERSION=`$ECHO $OUTPUT | grep " version \""` if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then SJAVAC_SERVER_JAVA="$SJAVAC_SERVER_JAVA -verbosegc" + JVM_ARG_OK=true + else + $ECHO "Arg failed:" >&5 + $ECHO "$OUTPUT" >&5 + JVM_ARG_OK=false fi # JRockit specific options. - # Test if -Xverbose:gc is a valid argument to $JAVA (often is $JAVA passed as $JAVA) - # If so, then append -Xverbose:gc to SJAVAC_SERVER_JAVA - FOUND_WARN=`$JAVA -Xverbose:gc -version 2>&1 | grep -i warn` - FOUND_VERSION=`$JAVA -Xverbose:gc -version 2>&1 | grep " version \""` + $ECHO "Check if jvm arg is ok: -Xverbose:gc" >&5 + $ECHO "Command: $JAVA -Xverbose:gc -version" >&5 + OUTPUT=`$JAVA -Xverbose:gc -version 2>&1` + FOUND_WARN=`$ECHO "$OUTPUT" | grep -i warn` + FOUND_VERSION=`$ECHO $OUTPUT | grep " version \""` if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then SJAVAC_SERVER_JAVA="$SJAVAC_SERVER_JAVA -Xverbose:gc" + JVM_ARG_OK=true + else + $ECHO "Arg failed:" >&5 + $ECHO "$OUTPUT" >&5 + JVM_ARG_OK=false fi SJAVAC_SERVER_JAVA="$JAVA $SJAVAC_SERVER_JAVA" fi - -# Check whether --with-sjavac-server-cores was given. -if test "${with_sjavac_server_cores+set}" = set; then : - withval=$with_sjavac_server_cores; -fi - -if test "x$with_sjavac_server_cores" != x; then - SJAVAC_SERVER_CORES="$with_sjavac_server_cores" -else - if test "$NUM_CORES" -gt 16; then - # We set this arbitrary limit because we want to limit the heap - # size of the javac server. - # In the future we will make the javac compilers in the server - # share more and more state, thus enabling us to use more and - # more concurrent threads in the server. - SJAVAC_SERVER_CORES="16" - else - SJAVAC_SERVER_CORES="$NUM_CORES" - fi - - if test "$MEMORY_SIZE" -gt "17000"; then - MAX_HEAP_MEM=10000 - - # Test if -d64 is a valid argument to $SJAVAC_SERVER_JAVA (often is $JAVA passed as $SJAVAC_SERVER_JAVA) - # If so, then append -d64 to SJAVAC_SERVER_JAVA - FOUND_WARN=`$SJAVAC_SERVER_JAVA -d64 -version 2>&1 | grep -i warn` - FOUND_VERSION=`$SJAVAC_SERVER_JAVA -d64 -version 2>&1 | grep " version \""` +if test "$MEMORY_SIZE" -gt "2500"; then + + $ECHO "Check if jvm arg is ok: -d64" >&5 + $ECHO "Command: $SJAVAC_SERVER_JAVA -d64 -version" >&5 + OUTPUT=`$SJAVAC_SERVER_JAVA -d64 -version 2>&1` + FOUND_WARN=`$ECHO "$OUTPUT" | grep -i warn` + FOUND_VERSION=`$ECHO $OUTPUT | grep " version \""` if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then SJAVAC_SERVER_JAVA="$SJAVAC_SERVER_JAVA -d64" - fi - - - # Test if -Xms10G -Xmx10G is a valid argument to $SJAVAC_SERVER_JAVA (often is $JAVA passed as $SJAVAC_SERVER_JAVA) - # If so, then append -Xms10G -Xmx10G to SJAVAC_SERVER_JAVA - FOUND_WARN=`$SJAVAC_SERVER_JAVA -Xms10G -Xmx10G -version 2>&1 | grep -i warn` - FOUND_VERSION=`$SJAVAC_SERVER_JAVA -Xms10G -Xmx10G -version 2>&1 | grep " version \""` + JVM_ARG_OK=true + else + $ECHO "Arg failed:" >&5 + $ECHO "$OUTPUT" >&5 + JVM_ARG_OK=false + fi + + if test "$JVM_ARG_OK" = true; then + JVM_64BIT=true + JVM_ARG_OK=false + fi + fi + +if test "$JVM_64BIT" = true; then + if test "$MEMORY_SIZE" -gt "17000"; then + + $ECHO "Check if jvm arg is ok: -Xms10G -Xmx10G" >&5 + $ECHO "Command: $SJAVAC_SERVER_JAVA -Xms10G -Xmx10G -version" >&5 + OUTPUT=`$SJAVAC_SERVER_JAVA -Xms10G -Xmx10G -version 2>&1` + FOUND_WARN=`$ECHO "$OUTPUT" | grep -i warn` + FOUND_VERSION=`$ECHO $OUTPUT | grep " version \""` if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then SJAVAC_SERVER_JAVA="$SJAVAC_SERVER_JAVA -Xms10G -Xmx10G" - fi - - elif test "$MEMORY_SIZE" -gt "10000"; then - MAX_HEAP_MEM=6000 - - # Test if -d64 is a valid argument to $SJAVAC_SERVER_JAVA (often is $JAVA passed as $SJAVAC_SERVER_JAVA) - # If so, then append -d64 to SJAVAC_SERVER_JAVA - FOUND_WARN=`$SJAVAC_SERVER_JAVA -d64 -version 2>&1 | grep -i warn` - FOUND_VERSION=`$SJAVAC_SERVER_JAVA -d64 -version 2>&1 | grep " version \""` - if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then - SJAVAC_SERVER_JAVA="$SJAVAC_SERVER_JAVA -d64" - fi - - - # Test if -Xms6G -Xmx6G is a valid argument to $SJAVAC_SERVER_JAVA (often is $JAVA passed as $SJAVAC_SERVER_JAVA) - # If so, then append -Xms6G -Xmx6G to SJAVAC_SERVER_JAVA - FOUND_WARN=`$SJAVAC_SERVER_JAVA -Xms6G -Xmx6G -version 2>&1 | grep -i warn` - FOUND_VERSION=`$SJAVAC_SERVER_JAVA -Xms6G -Xmx6G -version 2>&1 | grep " version \""` + JVM_ARG_OK=true + else + $ECHO "Arg failed:" >&5 + $ECHO "$OUTPUT" >&5 + JVM_ARG_OK=false + fi + + fi + if test "$MEMORY_SIZE" -gt "10000" && test "$JVM_ARG_OK" = false; then + + $ECHO "Check if jvm arg is ok: -Xms6G -Xmx6G" >&5 + $ECHO "Command: $SJAVAC_SERVER_JAVA -Xms6G -Xmx6G -version" >&5 + OUTPUT=`$SJAVAC_SERVER_JAVA -Xms6G -Xmx6G -version 2>&1` + FOUND_WARN=`$ECHO "$OUTPUT" | grep -i warn` + FOUND_VERSION=`$ECHO $OUTPUT | grep " version \""` if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then SJAVAC_SERVER_JAVA="$SJAVAC_SERVER_JAVA -Xms6G -Xmx6G" - fi - - elif test "$MEMORY_SIZE" -gt "5000"; then - MAX_HEAP_MEM=3000 - - # Test if -d64 is a valid argument to $SJAVAC_SERVER_JAVA (often is $JAVA passed as $SJAVAC_SERVER_JAVA) - # If so, then append -d64 to SJAVAC_SERVER_JAVA - FOUND_WARN=`$SJAVAC_SERVER_JAVA -d64 -version 2>&1 | grep -i warn` - FOUND_VERSION=`$SJAVAC_SERVER_JAVA -d64 -version 2>&1 | grep " version \""` - if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then - SJAVAC_SERVER_JAVA="$SJAVAC_SERVER_JAVA -d64" - fi - - - # Test if -Xms1G -Xmx3G is a valid argument to $SJAVAC_SERVER_JAVA (often is $JAVA passed as $SJAVAC_SERVER_JAVA) - # If so, then append -Xms1G -Xmx3G to SJAVAC_SERVER_JAVA - FOUND_WARN=`$SJAVAC_SERVER_JAVA -Xms1G -Xmx3G -version 2>&1 | grep -i warn` - FOUND_VERSION=`$SJAVAC_SERVER_JAVA -Xms1G -Xmx3G -version 2>&1 | grep " version \""` + JVM_ARG_OK=true + else + $ECHO "Arg failed:" >&5 + $ECHO "$OUTPUT" >&5 + JVM_ARG_OK=false + fi + + fi + if test "$MEMORY_SIZE" -gt "5000" && test "$JVM_ARG_OK" = false; then + + $ECHO "Check if jvm arg is ok: -Xms1G -Xmx3G" >&5 + $ECHO "Command: $SJAVAC_SERVER_JAVA -Xms1G -Xmx3G -version" >&5 + OUTPUT=`$SJAVAC_SERVER_JAVA -Xms1G -Xmx3G -version 2>&1` + FOUND_WARN=`$ECHO "$OUTPUT" | grep -i warn` + FOUND_VERSION=`$ECHO $OUTPUT | grep " version \""` if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then SJAVAC_SERVER_JAVA="$SJAVAC_SERVER_JAVA -Xms1G -Xmx3G" - fi - - elif test "$MEMORY_SIZE" -gt "3800"; then - MAX_HEAP_MEM=2500 - - # Test if -Xms1G -Xmx2500M is a valid argument to $SJAVAC_SERVER_JAVA (often is $JAVA passed as $SJAVAC_SERVER_JAVA) - # If so, then append -Xms1G -Xmx2500M to SJAVAC_SERVER_JAVA - FOUND_WARN=`$SJAVAC_SERVER_JAVA -Xms1G -Xmx2500M -version 2>&1 | grep -i warn` - FOUND_VERSION=`$SJAVAC_SERVER_JAVA -Xms1G -Xmx2500M -version 2>&1 | grep " version \""` + JVM_ARG_OK=true + else + $ECHO "Arg failed:" >&5 + $ECHO "$OUTPUT" >&5 + JVM_ARG_OK=false + fi + + fi + if test "$MEMORY_SIZE" -gt "3800" && test "$JVM_ARG_OK" = false; then + + $ECHO "Check if jvm arg is ok: -Xms1G -Xmx2500M" >&5 + $ECHO "Command: $SJAVAC_SERVER_JAVA -Xms1G -Xmx2500M -version" >&5 + OUTPUT=`$SJAVAC_SERVER_JAVA -Xms1G -Xmx2500M -version 2>&1` + FOUND_WARN=`$ECHO "$OUTPUT" | grep -i warn` + FOUND_VERSION=`$ECHO $OUTPUT | grep " version \""` if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then SJAVAC_SERVER_JAVA="$SJAVAC_SERVER_JAVA -Xms1G -Xmx2500M" - fi - - elif test "$MEMORY_SIZE" -gt "1900"; then - MAX_HEAP_MEM=1200 - - # Test if -Xms700M -Xmx1400M is a valid argument to $SJAVAC_SERVER_JAVA (often is $JAVA passed as $SJAVAC_SERVER_JAVA) - # If so, then append -Xms700M -Xmx1400M to SJAVAC_SERVER_JAVA - FOUND_WARN=`$SJAVAC_SERVER_JAVA -Xms700M -Xmx1400M -version 2>&1 | grep -i warn` - FOUND_VERSION=`$SJAVAC_SERVER_JAVA -Xms700M -Xmx1400M -version 2>&1 | grep " version \""` + JVM_ARG_OK=true + else + $ECHO "Arg failed:" >&5 + $ECHO "$OUTPUT" >&5 + JVM_ARG_OK=false + fi + + fi +fi +if test "$MEMORY_SIZE" -gt "2500" && test "$JVM_ARG_OK" = false; then + + $ECHO "Check if jvm arg is ok: -Xms1000M -Xmx1500M" >&5 + $ECHO "Command: $SJAVAC_SERVER_JAVA -Xms1000M -Xmx1500M -version" >&5 + OUTPUT=`$SJAVAC_SERVER_JAVA -Xms1000M -Xmx1500M -version 2>&1` + FOUND_WARN=`$ECHO "$OUTPUT" | grep -i warn` + FOUND_VERSION=`$ECHO $OUTPUT | grep " version \""` if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then - SJAVAC_SERVER_JAVA="$SJAVAC_SERVER_JAVA -Xms700M -Xmx1400M" - fi - - elif test "$MEMORY_SIZE" -gt "1000"; then - MAX_HEAP_MEM=900 - - # Test if -Xms400M -Xmx1100M is a valid argument to $SJAVAC_SERVER_JAVA (often is $JAVA passed as $SJAVAC_SERVER_JAVA) - # If so, then append -Xms400M -Xmx1100M to SJAVAC_SERVER_JAVA - FOUND_WARN=`$SJAVAC_SERVER_JAVA -Xms400M -Xmx1100M -version 2>&1 | grep -i warn` - FOUND_VERSION=`$SJAVAC_SERVER_JAVA -Xms400M -Xmx1100M -version 2>&1 | grep " version \""` + SJAVAC_SERVER_JAVA="$SJAVAC_SERVER_JAVA -Xms1000M -Xmx1500M" + JVM_ARG_OK=true + else + $ECHO "Arg failed:" >&5 + $ECHO "$OUTPUT" >&5 + JVM_ARG_OK=false + fi + +fi +if test "$MEMORY_SIZE" -gt "1000" && test "$JVM_ARG_OK" = false; then + + $ECHO "Check if jvm arg is ok: -Xms400M -Xmx1100M" >&5 + $ECHO "Command: $SJAVAC_SERVER_JAVA -Xms400M -Xmx1100M -version" >&5 + OUTPUT=`$SJAVAC_SERVER_JAVA -Xms400M -Xmx1100M -version 2>&1` + FOUND_WARN=`$ECHO "$OUTPUT" | grep -i warn` + FOUND_VERSION=`$ECHO $OUTPUT | grep " version \""` if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then SJAVAC_SERVER_JAVA="$SJAVAC_SERVER_JAVA -Xms400M -Xmx1100M" - fi - - else - MAX_HEAP_MEM=512 - - # Test if -Xms256M -Xmx512M is a valid argument to $SJAVAC_SERVER_JAVA (often is $JAVA passed as $SJAVAC_SERVER_JAVA) - # If so, then append -Xms256M -Xmx512M to SJAVAC_SERVER_JAVA - FOUND_WARN=`$SJAVAC_SERVER_JAVA -Xms256M -Xmx512M -version 2>&1 | grep -i warn` - FOUND_VERSION=`$SJAVAC_SERVER_JAVA -Xms256M -Xmx512M -version 2>&1 | grep " version \""` + JVM_ARG_OK=true + else + $ECHO "Arg failed:" >&5 + $ECHO "$OUTPUT" >&5 + JVM_ARG_OK=false + fi + +fi +if test "$JVM_ARG_OK" = false; then + + $ECHO "Check if jvm arg is ok: -Xms256M -Xmx512M" >&5 + $ECHO "Command: $SJAVAC_SERVER_JAVA -Xms256M -Xmx512M -version" >&5 + OUTPUT=`$SJAVAC_SERVER_JAVA -Xms256M -Xmx512M -version 2>&1` + FOUND_WARN=`$ECHO "$OUTPUT" | grep -i warn` + FOUND_VERSION=`$ECHO $OUTPUT | grep " version \""` if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then SJAVAC_SERVER_JAVA="$SJAVAC_SERVER_JAVA -Xms256M -Xmx512M" - fi - - fi - - - # Test if -XX:PermSize=32m is a valid argument to $SJAVAC_SERVER_JAVA (often is $JAVA passed as $SJAVAC_SERVER_JAVA) - # If so, then append -XX:PermSize=32m to SJAVAC_SERVER_JAVA - FOUND_WARN=`$SJAVAC_SERVER_JAVA -XX:PermSize=32m -version 2>&1 | grep -i warn` - FOUND_VERSION=`$SJAVAC_SERVER_JAVA -XX:PermSize=32m -version 2>&1 | grep " version \""` - if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then - SJAVAC_SERVER_JAVA="$SJAVAC_SERVER_JAVA -XX:PermSize=32m" - fi - - - # Test if -XX:MaxPermSize=160m is a valid argument to $SJAVAC_SERVER_JAVA (often is $JAVA passed as $SJAVAC_SERVER_JAVA) - # If so, then append -XX:MaxPermSize=160m to SJAVAC_SERVER_JAVA - FOUND_WARN=`$SJAVAC_SERVER_JAVA -XX:MaxPermSize=160m -version 2>&1 | grep -i warn` - FOUND_VERSION=`$SJAVAC_SERVER_JAVA -XX:MaxPermSize=160m -version 2>&1 | grep " version \""` - if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then - SJAVAC_SERVER_JAVA="$SJAVAC_SERVER_JAVA -XX:MaxPermSize=160m" - fi - - - # Test if -XX:ThreadStackSize=$STACK_SIZE is a valid argument to $SJAVAC_SERVER_JAVA (often is $JAVA passed as $SJAVAC_SERVER_JAVA) - # If so, then append -XX:ThreadStackSize=$STACK_SIZE to SJAVAC_SERVER_JAVA - FOUND_WARN=`$SJAVAC_SERVER_JAVA -XX:ThreadStackSize=$STACK_SIZE -version 2>&1 | grep -i warn` - FOUND_VERSION=`$SJAVAC_SERVER_JAVA -XX:ThreadStackSize=$STACK_SIZE -version 2>&1 | grep " version \""` - if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then - SJAVAC_SERVER_JAVA="$SJAVAC_SERVER_JAVA -XX:ThreadStackSize=$STACK_SIZE" - fi - - - MAX_COMPILERS_IN_HEAP=`expr $MAX_HEAP_MEM / 501` - if test "$SJAVAC_SERVER_CORES" -gt "$MAX_COMPILERS_IN_HEAP"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking if number of server cores must be reduced" >&5 -$as_echo_n "checking if number of server cores must be reduced... " >&6; } - SJAVAC_SERVER_CORES="$MAX_COMPILERS_IN_HEAP" - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes, to $SJAVAC_SERVER_CORES with max heap size $MAX_HEAP_MEM MB" >&5 -$as_echo "yes, to $SJAVAC_SERVER_CORES with max heap size $MAX_HEAP_MEM MB" >&6; } - fi -fi - + JVM_ARG_OK=true + else + $ECHO "Arg failed:" >&5 + $ECHO "$OUTPUT" >&5 + JVM_ARG_OK=false + fi + +fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to use sjavac" >&5 $as_echo_n "checking whether to use sjavac... " >&6; } diff -r 14a0ae3ca973 -r 1bbdae29327c common/autoconf/spec.gmk.in --- a/common/autoconf/spec.gmk.in Mon Jun 03 16:37:13 2013 +0400 +++ b/common/autoconf/spec.gmk.in Wed Jun 05 00:37:11 2013 -0700 @@ -528,6 +528,8 @@ OBJCOPY:=@OBJCOPY@ SETFILE:=@SETFILE@ XATTR:=@XATTR@ +JT_HOME:=@JT_HOME@ +JTREGEXE:=@JTREGEXE@ FIXPATH:=@FIXPATH@ diff -r 14a0ae3ca973 -r 1bbdae29327c common/autoconf/toolchain.m4 --- a/common/autoconf/toolchain.m4 Mon Jun 03 16:37:13 2013 +0400 +++ b/common/autoconf/toolchain.m4 Wed Jun 05 00:37:11 2013 -0700 @@ -479,6 +479,8 @@ BASIC_FIXUP_EXECUTABLE(LIPO) fi +TOOLCHAIN_SETUP_JTREG + # Restore old path without tools dir PATH="$OLD_PATH" ]) @@ -1089,3 +1091,29 @@ [COMPILER_SUPPORTS_TARGET_BITS_FLAG=false]) AC_SUBST(COMPILER_SUPPORTS_TARGET_BITS_FLAG) ]) + +# Setup the JTREG paths +AC_DEFUN_ONCE([TOOLCHAIN_SETUP_JTREG], +[ + AC_ARG_WITH(jtreg, [AS_HELP_STRING([--with-jtreg], + [Regression Test Harness @<:@probed@:>@])]) + + AC_MSG_CHECKING([for JTReg Regression Test Harness]) + + if test "x$with_jtreg" != x; then + JT_HOME="$with_jtreg" + BASIC_FIXUP_PATH([JT_HOME]) + AC_MSG_RESULT($JT_HOME) + + # jtreg win32 script works for everybody + JTREGEXE="$JT_HOME/win32/bin/jtreg" + if test ! -f "$JTREGEXE"; then + AC_MSG_ERROR([JTReg executable does not exist: $JTREGEXE]) + fi + else + AC_MSG_RESULT(no) + fi + + AC_SUBST(JT_HOME) + AC_SUBST(JTREGEXE) +]) diff -r 14a0ae3ca973 -r 1bbdae29327c corba/.hgtags --- a/corba/.hgtags Mon Jun 03 16:37:13 2013 +0400 +++ b/corba/.hgtags Wed Jun 05 00:37:11 2013 -0700 @@ -212,3 +212,4 @@ 4e3a881ebb1ee96ce0872508b0066d74f310dbfa jdk8-b88 fe4150590ee597f4e125fea950aa3b352622cc2d jdk8-b89 c8286839d0df04aba819ec4bef12b86babccf30e jdk8-b90 +8f7ffb296385f85a4a6d53f9f2d4a7b13a8fa1ff jdk8-b91 diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/.hgtags --- a/hotspot/.hgtags Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/.hgtags Wed Jun 05 00:37:11 2013 -0700 @@ -343,3 +343,5 @@ 69494caf57908ba2c8efa9eaaa472b4d1875588a hs25-b32 1ae0472ff3a0117b5b019d380ad59fface2fde14 jdk8-b90 b19517cecc2e91636d7c16ba2f35e3d3dc628099 hs25-b33 +7cbdf0e3725c0c56a2ff7540fc70b6d4b5890d04 jdk8-b91 +38da9f4f67096745f851318d792d6468aa1f6cf8 hs25-b34 diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/cdbg/basic/amd64/AMD64CFrame.java --- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/cdbg/basic/amd64/AMD64CFrame.java Mon Jun 03 16:37:13 2013 +0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2003, 2012, 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. - * - */ - -package sun.jvm.hotspot.debugger.cdbg.basic.amd64; - -import sun.jvm.hotspot.debugger.*; -import sun.jvm.hotspot.debugger.amd64.*; -import sun.jvm.hotspot.debugger.cdbg.*; -import sun.jvm.hotspot.debugger.cdbg.basic.*; - -/** Basic AMD64 frame functionality providing sender() functionality. */ - -public class AMD64CFrame extends BasicCFrame { - private Address rbp; - private Address pc; - - private static final int ADDRESS_SIZE = 8; - - /** Constructor for topmost frame */ - public AMD64CFrame(CDebugger dbg, Address rbp, Address pc) { - super(dbg); - this.rbp = rbp; - this.pc = pc; - } - - public CFrame sender(ThreadProxy thread) { - AMD64ThreadContext context = (AMD64ThreadContext) thread.getContext(); - Address rsp = context.getRegisterAsAddress(AMD64ThreadContext.RSP); - - if ( (rbp == null) || rbp.lessThan(rsp) ) { - return null; - } - - Address nextRBP = rbp.getAddressAt( 0 * ADDRESS_SIZE); - if (nextRBP == null) { - return null; - } - Address nextPC = rbp.getAddressAt( 1 * ADDRESS_SIZE); - if (nextPC == null) { - return null; - } - return new AMD64CFrame(dbg(), nextRBP, nextPC); - } - - public Address pc() { - return pc; - } - - public Address localVariableBase() { - return rbp; - } -} diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/cdbg/basic/x86/X86CFrame.java --- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/cdbg/basic/x86/X86CFrame.java Mon Jun 03 16:37:13 2013 +0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2001, 2012, 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. - * - */ - -package sun.jvm.hotspot.debugger.cdbg.basic.x86; - -import sun.jvm.hotspot.debugger.*; -import sun.jvm.hotspot.debugger.x86.*; -import sun.jvm.hotspot.debugger.cdbg.*; -import sun.jvm.hotspot.debugger.cdbg.basic.*; - -/** Basic X86 frame functionality providing sender() functionality. */ - -public class X86CFrame extends BasicCFrame { - private Address ebp; - private Address pc; - - private static final int ADDRESS_SIZE = 4; - - /** Constructor for topmost frame */ - public X86CFrame(CDebugger dbg, Address ebp, Address pc) { - super(dbg); - this.ebp = ebp; - this.pc = pc; - } - - public CFrame sender(ThreadProxy thread) { - X86ThreadContext context = (X86ThreadContext) thread.getContext(); - Address esp = context.getRegisterAsAddress(X86ThreadContext.ESP); - - if ( (ebp == null) || ebp.lessThan(esp) ) { - return null; - } - - Address nextEBP = ebp.getAddressAt( 0 * ADDRESS_SIZE); - if (nextEBP == null) { - return null; - } - Address nextPC = ebp.getAddressAt( 1 * ADDRESS_SIZE); - if (nextPC == null) { - return null; - } - return new X86CFrame(dbg(), nextEBP, nextPC); - } - - public Address pc() { - return pc; - } - - public Address localVariableBase() { - return ebp; - } -} diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/windbg/WindbgCDebugger.java --- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/windbg/WindbgCDebugger.java Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/windbg/WindbgCDebugger.java Wed Jun 05 00:37:11 2013 -0700 @@ -28,10 +28,10 @@ import java.util.*; import sun.jvm.hotspot.debugger.*; import sun.jvm.hotspot.debugger.cdbg.*; -import sun.jvm.hotspot.debugger.cdbg.basic.x86.*; -import sun.jvm.hotspot.debugger.cdbg.basic.amd64.*; import sun.jvm.hotspot.debugger.x86.*; import sun.jvm.hotspot.debugger.amd64.*; +import sun.jvm.hotspot.debugger.windows.x86.*; +import sun.jvm.hotspot.debugger.windows.amd64.*; import sun.jvm.hotspot.utilities.AddressOps; class WindbgCDebugger implements CDebugger { @@ -75,14 +75,14 @@ if (ebp == null) return null; Address pc = context.getRegisterAsAddress(X86ThreadContext.EIP); if (pc == null) return null; - return new X86CFrame(this, ebp, pc); + return new WindowsX86CFrame(dbg, ebp, pc); } else if (dbg.getCPU().equals("amd64")) { AMD64ThreadContext context = (AMD64ThreadContext) thread.getContext(); Address rbp = context.getRegisterAsAddress(AMD64ThreadContext.RBP); if (rbp == null) return null; Address pc = context.getRegisterAsAddress(AMD64ThreadContext.RIP); if (pc == null) return null; - return new AMD64CFrame(this, rbp, pc); + return new WindowsAMD64CFrame(dbg, rbp, pc); } else { // unsupported CPU! return null; diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/windows/amd64/WindowsAMD64CFrame.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/windows/amd64/WindowsAMD64CFrame.java Wed Jun 05 00:37:11 2013 -0700 @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2003, 2012, 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. + * + */ + +package sun.jvm.hotspot.debugger.windows.amd64; + +import sun.jvm.hotspot.debugger.*; +import sun.jvm.hotspot.debugger.amd64.*; +import sun.jvm.hotspot.debugger.cdbg.*; +import sun.jvm.hotspot.debugger.cdbg.basic.*; +import sun.jvm.hotspot.debugger.windbg.*; + +public class WindowsAMD64CFrame extends BasicCFrame { + private Address rbp; + private Address pc; + + private static final int ADDRESS_SIZE = 8; + + /** Constructor for topmost frame */ + public WindowsAMD64CFrame(WindbgDebugger dbg, Address rbp, Address pc) { + super(dbg.getCDebugger()); + this.rbp = rbp; + this.pc = pc; + this.dbg = dbg; + } + + public CFrame sender(ThreadProxy thread) { + AMD64ThreadContext context = (AMD64ThreadContext) thread.getContext(); + Address rsp = context.getRegisterAsAddress(AMD64ThreadContext.RSP); + + if ( (rbp == null) || rbp.lessThan(rsp) ) { + return null; + } + + // Check alignment of rbp + if ( dbg.getAddressValue(rbp) % ADDRESS_SIZE != 0) { + return null; + } + + Address nextRBP = rbp.getAddressAt( 0 * ADDRESS_SIZE); + if (nextRBP == null || nextRBP.lessThanOrEqual(rbp)) { + return null; + } + Address nextPC = rbp.getAddressAt( 1 * ADDRESS_SIZE); + if (nextPC == null) { + return null; + } + return new WindowsAMD64CFrame(dbg, nextRBP, nextPC); + } + + public Address pc() { + return pc; + } + + public Address localVariableBase() { + return rbp; + } + + private WindbgDebugger dbg; +} diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/windows/x86/WindowsX86CFrame.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/windows/x86/WindowsX86CFrame.java Wed Jun 05 00:37:11 2013 -0700 @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2001, 2012, 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. + * + */ + +package sun.jvm.hotspot.debugger.windows.x86; + +import sun.jvm.hotspot.debugger.*; +import sun.jvm.hotspot.debugger.x86.*; +import sun.jvm.hotspot.debugger.cdbg.*; +import sun.jvm.hotspot.debugger.cdbg.basic.*; +import sun.jvm.hotspot.debugger.windbg.*; + +public class WindowsX86CFrame extends BasicCFrame { + private Address ebp; + private Address pc; + + private static final int ADDRESS_SIZE = 4; + + /** Constructor for topmost frame */ + public WindowsX86CFrame(WindbgDebugger dbg, Address ebp, Address pc) { + super(dbg.getCDebugger()); + this.ebp = ebp; + this.pc = pc; + this.dbg = dbg; + } + + public CFrame sender(ThreadProxy thread) { + X86ThreadContext context = (X86ThreadContext) thread.getContext(); + Address esp = context.getRegisterAsAddress(X86ThreadContext.ESP); + + if ( (ebp == null) || ebp.lessThan(esp) ) { + return null; + } + + // Check alignment of ebp + if ( dbg.getAddressValue(ebp) % ADDRESS_SIZE != 0) { + return null; + } + + Address nextEBP = ebp.getAddressAt( 0 * ADDRESS_SIZE); + if (nextEBP == null || nextEBP.lessThanOrEqual(ebp)) { + return null; + } + Address nextPC = ebp.getAddressAt( 1 * ADDRESS_SIZE); + if (nextPC == null) { + return null; + } + return new WindowsX86CFrame(dbg, nextEBP, nextPC); + } + + public Address pc() { + return pc; + } + + public Address localVariableBase() { + return ebp; + } + + private WindbgDebugger dbg; +} diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/make/bsd/makefiles/arm.make --- a/hotspot/make/bsd/makefiles/arm.make Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/make/bsd/makefiles/arm.make Wed Jun 05 00:37:11 2013 -0700 @@ -1,5 +1,5 @@ # -# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2008, 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 @@ -24,6 +24,8 @@ Obj_Files += bsd_arm.o -LIBS += $(EXT_LIBS_PATH)/sflt_glibc.a +ifneq ($(EXT_LIBS_PATH),) + LIBS += $(EXT_LIBS_PATH)/sflt_glibc.a +endif CFLAGS += -DVM_LITTLE_ENDIAN diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/make/hotspot_version --- a/hotspot/make/hotspot_version Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/make/hotspot_version Wed Jun 05 00:37:11 2013 -0700 @@ -35,7 +35,7 @@ HS_MAJOR_VER=25 HS_MINOR_VER=0 -HS_BUILD_NUMBER=33 +HS_BUILD_NUMBER=34 JDK_MAJOR_VER=1 JDK_MINOR_VER=8 diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/make/linux/makefiles/arm.make --- a/hotspot/make/linux/makefiles/arm.make Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/make/linux/makefiles/arm.make Wed Jun 05 00:37:11 2013 -0700 @@ -1,5 +1,5 @@ # -# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2008, 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 @@ -24,6 +24,8 @@ Obj_Files += linux_arm.o -LIBS += $(EXT_LIBS_PATH)/sflt_glibc.a +ifneq ($(EXT_LIBS_PATH),) + LIBS += $(EXT_LIBS_PATH)/sflt_glibc.a +endif CFLAGS += -DVM_LITTLE_ENDIAN diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/make/linux/makefiles/jsig.make --- a/hotspot/make/linux/makefiles/jsig.make Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/make/linux/makefiles/jsig.make Wed Jun 05 00:37:11 2013 -0700 @@ -54,7 +54,7 @@ $(LIBJSIG): $(JSIGSRCDIR)/jsig.c $(LIBJSIG_MAPFILE) @echo Making signal interposition lib... $(QUIETLY) $(CC) $(SYMFLAG) $(ARCHFLAG) $(SHARED_FLAG) $(PICFLAG) \ - $(LFLAGS_JSIG) $(JSIG_DEBUG_CFLAGS) -o $@ $< -ldl + $(LFLAGS_JSIG) $(JSIG_DEBUG_CFLAGS) $(EXTRA_CFLAGS) -o $@ $< -ldl ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1) $(QUIETLY) $(OBJCOPY) --only-keep-debug $@ $(LIBJSIG_DEBUGINFO) $(QUIETLY) $(OBJCOPY) --add-gnu-debuglink=$(LIBJSIG_DEBUGINFO) $@ diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/make/linux/makefiles/saproc.make --- a/hotspot/make/linux/makefiles/saproc.make Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/make/linux/makefiles/saproc.make Wed Jun 05 00:37:11 2013 -0700 @@ -92,6 +92,7 @@ $(SASRCFILES) \ $(SA_LFLAGS) \ $(SA_DEBUG_CFLAGS) \ + $(EXTRA_CFLAGS) \ -o $@ \ -lthread_db ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1) diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/make/sa.files --- a/hotspot/make/sa.files Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/make/sa.files Wed Jun 05 00:37:11 2013 -0700 @@ -48,8 +48,6 @@ $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/bsd/x86/*.java \ $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/cdbg/*.java \ $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/cdbg/basic/*.java \ -$(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/cdbg/basic/x86/*.java \ -$(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/cdbg/basic/amd64/*.java \ $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/dummy/*.java \ $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/linux/*.java \ $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/linux/amd64/*.java \ @@ -70,6 +68,8 @@ $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/windbg/*.java \ $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/windbg/amd64/*.java \ $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/windbg/x86/*.java \ +$(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/windows/x86/*.java \ +$(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/windows/amd64/*.java \ $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/x86/*.java \ $(AGENT_SRC_DIR)/sun/jvm/hotspot/gc_implementation/g1/*.java \ $(AGENT_SRC_DIR)/sun/jvm/hotspot/gc_implementation/parallelScavenge/*.java \ diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/cpu/x86/vm/stubGenerator_x86_32.cpp --- a/hotspot/src/cpu/x86/vm/stubGenerator_x86_32.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/cpu/x86/vm/stubGenerator_x86_32.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -1498,27 +1498,29 @@ __ movptr(elem_klass, elem_klass_addr); // query the object klass generate_type_check(elem_klass, ckoff_arg, ckval_arg, temp, &L_store_element, NULL); - // (On fall-through, we have failed the element type check.) + // (On fall-through, we have failed the element type check.) // ======== end loop ======== // It was a real error; we must depend on the caller to finish the job. // Register "count" = -1 * number of *remaining* oops, length_arg = *total* oops. // Emit GC store barriers for the oops we have copied (length_arg + count), // and report their number to the caller. + assert_different_registers(to, count, rax); + Label L_post_barrier; __ addl(count, length_arg); // transfers = (length - remaining) __ movl2ptr(rax, count); // save the value - __ notptr(rax); // report (-1^K) to caller - __ movptr(to, to_arg); // reload - assert_different_registers(to, count, rax); - gen_write_ref_array_post_barrier(to, count); - __ jmpb(L_done); + __ notptr(rax); // report (-1^K) to caller (does not affect flags) + __ jccb(Assembler::notZero, L_post_barrier); + __ jmp(L_done); // K == 0, nothing was copied, skip post barrier // Come here on success only. __ BIND(L_do_card_marks); + __ xorptr(rax, rax); // return 0 on success __ movl2ptr(count, length_arg); - __ movptr(to, to_arg); // reload + + __ BIND(L_post_barrier); + __ movptr(to, to_arg); // reload gen_write_ref_array_post_barrier(to, count); - __ xorptr(rax, rax); // return 0 on success // Common exit point (success or failure). __ BIND(L_done); diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/cpu/x86/vm/stubGenerator_x86_64.cpp --- a/hotspot/src/cpu/x86/vm/stubGenerator_x86_64.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/cpu/x86/vm/stubGenerator_x86_64.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -1217,27 +1217,28 @@ // // Input: // start - register containing starting address of destination array - // end - register containing ending address of destination array + // count - elements count // scratch - scratch register // // The input registers are overwritten. - // The ending address is inclusive. - void gen_write_ref_array_post_barrier(Register start, Register end, Register scratch) { - assert_different_registers(start, end, scratch); + // + void gen_write_ref_array_post_barrier(Register start, Register count, Register scratch) { + assert_different_registers(start, count, scratch); BarrierSet* bs = Universe::heap()->barrier_set(); switch (bs->kind()) { case BarrierSet::G1SATBCT: case BarrierSet::G1SATBCTLogging: - { - __ pusha(); // push registers (overkill) - // must compute element count unless barrier set interface is changed (other platforms supply count) - assert_different_registers(start, end, scratch); - __ lea(scratch, Address(end, BytesPerHeapOop)); - __ subptr(scratch, start); // subtract start to get #bytes - __ shrptr(scratch, LogBytesPerHeapOop); // convert to element count - __ mov(c_rarg0, start); - __ mov(c_rarg1, scratch); + __ pusha(); // push registers (overkill) + if (c_rarg0 == count) { // On win64 c_rarg0 == rcx + assert_different_registers(c_rarg1, start); + __ mov(c_rarg1, count); + __ mov(c_rarg0, start); + } else { + assert_different_registers(c_rarg0, count); + __ mov(c_rarg0, start); + __ mov(c_rarg1, count); + } __ call_VM_leaf(CAST_FROM_FN_PTR(address, BarrierSet::static_write_ref_array_post), 2); __ popa(); } @@ -1249,22 +1250,16 @@ assert(sizeof(*ct->byte_map_base) == sizeof(jbyte), "adjust this code"); Label L_loop; - - __ shrptr(start, CardTableModRefBS::card_shift); - __ addptr(end, BytesPerHeapOop); - __ shrptr(end, CardTableModRefBS::card_shift); - __ subptr(end, start); // number of bytes to copy - - intptr_t disp = (intptr_t) ct->byte_map_base; - if (Assembler::is_simm32(disp)) { - Address cardtable(noreg, noreg, Address::no_scale, disp); - __ lea(scratch, cardtable); - } else { - ExternalAddress cardtable((address)disp); - __ lea(scratch, cardtable); - } - - const Register count = end; // 'end' register contains bytes count now + const Register end = count; + + __ leaq(end, Address(start, count, TIMES_OOP, 0)); // end == start+count*oop_size + __ subptr(end, BytesPerHeapOop); // end - 1 to make inclusive + __ shrptr(start, CardTableModRefBS::card_shift); + __ shrptr(end, CardTableModRefBS::card_shift); + __ subptr(end, start); // end --> cards count + + int64_t disp = (int64_t) ct->byte_map_base; + __ mov64(scratch, disp); __ addptr(start, scratch); __ BIND(L_loop); __ movb(Address(start, count, Address::times_1), 0); @@ -1916,8 +1911,7 @@ __ BIND(L_exit); if (is_oop) { - __ leaq(end_to, Address(saved_to, dword_count, Address::times_4, -4)); - gen_write_ref_array_post_barrier(saved_to, end_to, rax); + gen_write_ref_array_post_barrier(saved_to, dword_count, rax); } restore_arg_regs(); inc_counter_np(SharedRuntime::_jint_array_copy_ctr); // Update counter after rscratch1 is free @@ -2012,12 +2006,10 @@ // Copy in multi-bytes chunks copy_bytes_backward(from, to, qword_count, rax, L_copy_bytes, L_copy_8_bytes); - __ bind(L_exit); - if (is_oop) { - Register end_to = rdx; - __ leaq(end_to, Address(to, dword_count, Address::times_4, -4)); - gen_write_ref_array_post_barrier(to, end_to, rax); - } + __ BIND(L_exit); + if (is_oop) { + gen_write_ref_array_post_barrier(to, dword_count, rax); + } restore_arg_regs(); inc_counter_np(SharedRuntime::_jint_array_copy_ctr); // Update counter after rscratch1 is free __ xorptr(rax, rax); // return 0 @@ -2055,6 +2047,7 @@ const Register end_from = from; // source array end address const Register end_to = rcx; // destination array end address const Register saved_to = to; + const Register saved_count = r11; // End pointers are inclusive, and if count is not zero they point // to the last unit copied: end_to[0] := end_from[0] @@ -2072,6 +2065,8 @@ // r9 and r10 may be used to save non-volatile registers // 'from', 'to' and 'qword_count' are now valid if (is_oop) { + // Save to and count for store barrier + __ movptr(saved_count, qword_count); // no registers are destroyed by this call gen_write_ref_array_pre_barrier(to, qword_count, dest_uninitialized); } @@ -2104,7 +2099,7 @@ if (is_oop) { __ BIND(L_exit); - gen_write_ref_array_post_barrier(saved_to, end_to, rax); + gen_write_ref_array_post_barrier(saved_to, saved_count, rax); } restore_arg_regs(); if (is_oop) { @@ -2187,8 +2182,7 @@ if (is_oop) { __ BIND(L_exit); - __ lea(rcx, Address(to, saved_count, Address::times_8, -8)); - gen_write_ref_array_post_barrier(to, rcx, rax); + gen_write_ref_array_post_barrier(to, saved_count, rax); } restore_arg_regs(); if (is_oop) { @@ -2375,20 +2369,20 @@ // Register rdx = -1 * number of *remaining* oops, r14 = *total* oops. // Emit GC store barriers for the oops we have copied (r14 + rdx), // and report their number to the caller. - assert_different_registers(rax, r14_length, count, to, end_to, rcx); - __ lea(end_to, to_element_addr); - __ addptr(end_to, -heapOopSize); // make an inclusive end pointer - gen_write_ref_array_post_barrier(to, end_to, rscratch1); - __ movptr(rax, r14_length); // original oops - __ addptr(rax, count); // K = (original - remaining) oops - __ notptr(rax); // report (-1^K) to caller - __ jmp(L_done); + assert_different_registers(rax, r14_length, count, to, end_to, rcx, rscratch1); + Label L_post_barrier; + __ addptr(r14_length, count); // K = (original - remaining) oops + __ movptr(rax, r14_length); // save the value + __ notptr(rax); // report (-1^K) to caller (does not affect flags) + __ jccb(Assembler::notZero, L_post_barrier); + __ jmp(L_done); // K == 0, nothing was copied, skip post barrier // Come here on success only. __ BIND(L_do_card_marks); - __ addptr(end_to, -heapOopSize); // make an inclusive end pointer - gen_write_ref_array_post_barrier(to, end_to, rscratch1); - __ xorptr(rax, rax); // return 0 on success + __ xorptr(rax, rax); // return 0 on success + + __ BIND(L_post_barrier); + gen_write_ref_array_post_barrier(to, r14_length, rscratch1); // Common exit point (success or failure). __ BIND(L_done); diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/tools/hsdis/hsdis.c --- a/hotspot/src/share/tools/hsdis/hsdis.c Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/tools/hsdis/hsdis.c Wed Jun 05 00:37:11 2013 -0700 @@ -27,6 +27,7 @@ HotSpot PrintAssembly option. */ +#include /* required by bfd.h */ #include #include #include diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/c1/c1_Compiler.cpp --- a/hotspot/src/share/vm/c1/c1_Compiler.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/c1/c1_Compiler.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -77,30 +77,42 @@ } -BufferBlob* Compiler::build_buffer_blob() { +BufferBlob* Compiler::get_buffer_blob(ciEnv* env) { + // Allocate buffer blob once at startup since allocation for each + // compilation seems to be too expensive (at least on Intel win32). + BufferBlob* buffer_blob = CompilerThread::current()->get_buffer_blob(); + if (buffer_blob != NULL) { + return buffer_blob; + } + // setup CodeBuffer. Preallocate a BufferBlob of size // NMethodSizeLimit plus some extra space for constants. int code_buffer_size = Compilation::desired_max_code_buffer_size() + Compilation::desired_max_constant_size(); - BufferBlob* blob = BufferBlob::create("Compiler1 temporary CodeBuffer", - code_buffer_size); - guarantee(blob != NULL, "must create initial code buffer"); - return blob; + + buffer_blob = BufferBlob::create("Compiler1 temporary CodeBuffer", + code_buffer_size); + if (buffer_blob == NULL) { + CompileBroker::handle_full_code_cache(); + env->record_failure("CodeCache is full"); + } else { + CompilerThread::current()->set_buffer_blob(buffer_blob); + } + + return buffer_blob; } void Compiler::compile_method(ciEnv* env, ciMethod* method, int entry_bci) { - // Allocate buffer blob once at startup since allocation for each - // compilation seems to be too expensive (at least on Intel win32). - BufferBlob* buffer_blob = CompilerThread::current()->get_buffer_blob(); + BufferBlob* buffer_blob = Compiler::get_buffer_blob(env); if (buffer_blob == NULL) { - buffer_blob = build_buffer_blob(); - CompilerThread::current()->set_buffer_blob(buffer_blob); + return; } if (!is_initialized()) { initialize(); } + // invoke compilation { // We are nested here because we need for the destructor diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/c1/c1_Compiler.hpp --- a/hotspot/src/share/vm/c1/c1_Compiler.hpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/c1/c1_Compiler.hpp Wed Jun 05 00:37:11 2013 -0700 @@ -46,7 +46,7 @@ virtual bool is_c1() { return true; }; - BufferBlob* build_buffer_blob(); + BufferBlob* get_buffer_blob(ciEnv* env); // Missing feature tests virtual bool supports_native() { return true; } diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/classfile/classFileParser.cpp --- a/hotspot/src/share/vm/classfile/classFileParser.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/classfile/classFileParser.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -1719,15 +1719,28 @@ coll->set_annotation(id); if (id == AnnotationCollector::_sun_misc_Contended) { + // @Contended can optionally specify the contention group. + // + // Contended group defines the equivalence class over the fields: + // the fields within the same contended group are not treated distinct. + // The only exception is default group, which does not incur the + // equivalence. Naturally, contention group for classes is meaningless. + // + // While the contention group is specified as String, annotation + // values are already interned, and we might as well use the constant + // pool index as the group tag. + // + u2 group_index = 0; // default contended group if (count == 1 && s_size == (index - index0) // match size && s_tag_val == *(abase + tag_off) && member == vmSymbols::value_name()) { - u2 group_index = Bytes::get_Java_u2(abase + s_con_off); - coll->set_contended_group(group_index); - } else { - coll->set_contended_group(0); // default contended group + group_index = Bytes::get_Java_u2(abase + s_con_off); + if (_cp->symbol_at(group_index)->utf8_length() == 0) { + group_index = 0; // default contended group + } } + coll->set_contended_group(group_index); } } } @@ -3108,10 +3121,6 @@ FieldLayoutInfo* info, TRAPS) { - // get the padding width from the option - // TODO: Ask VM about specific CPU we are running on - int pad_size = ContendedPaddingWidth; - // Field size and offset computation int nonstatic_field_size = _super_klass() == NULL ? 0 : _super_klass()->nonstatic_field_size(); int next_static_oop_offset; @@ -3124,13 +3133,14 @@ int next_nonstatic_word_offset; int next_nonstatic_short_offset; int next_nonstatic_byte_offset; - int next_nonstatic_type_offset; int first_nonstatic_oop_offset; - int first_nonstatic_field_offset; int next_nonstatic_field_offset; int next_nonstatic_padded_offset; // Count the contended fields by type. + // + // We ignore static fields, because @Contended is not supported for them. + // The layout code below will also ignore the static fields. int nonstatic_contended_count = 0; FieldAllocationCount fac_contended; for (AllFieldStream fs(_fields, _cp); !fs.done(); fs.next()) { @@ -3162,16 +3172,17 @@ next_static_byte_offset = next_static_short_offset + ((fac->count[STATIC_SHORT]) * BytesPerShort); - first_nonstatic_field_offset = instanceOopDesc::base_offset_in_bytes() + - nonstatic_field_size * heapOopSize; - - // class is contended, pad before all the fields + int nonstatic_fields_start = instanceOopDesc::base_offset_in_bytes() + + nonstatic_field_size * heapOopSize; + + next_nonstatic_field_offset = nonstatic_fields_start; + + // Class is contended, pad before all the fields if (parsed_annotations->is_contended()) { - first_nonstatic_field_offset += pad_size; + next_nonstatic_field_offset += ContendedPaddingWidth; } - next_nonstatic_field_offset = first_nonstatic_field_offset; - + // Compute the non-contended fields count unsigned int nonstatic_double_count = fac->count[NONSTATIC_DOUBLE] - fac_contended.count[NONSTATIC_DOUBLE]; unsigned int nonstatic_word_count = fac->count[NONSTATIC_WORD] - fac_contended.count[NONSTATIC_WORD]; unsigned int nonstatic_short_count = fac->count[NONSTATIC_SHORT] - fac_contended.count[NONSTATIC_SHORT]; @@ -3229,6 +3240,7 @@ compact_fields = false; // Don't compact fields } + // Rearrange fields for a given allocation style if( allocation_style == 0 ) { // Fields order: oops, longs/doubles, ints, shorts/chars, bytes, padded fields next_nonstatic_oop_offset = next_nonstatic_field_offset; @@ -3269,6 +3281,8 @@ int nonstatic_short_space_offset; int nonstatic_byte_space_offset; + // Try to squeeze some of the fields into the gaps due to + // long/double alignment. if( nonstatic_double_count > 0 ) { int offset = next_nonstatic_double_offset; next_nonstatic_double_offset = align_size_up(offset, BytesPerLong); @@ -3442,7 +3456,7 @@ // if there is at least one contended field, we need to have pre-padding for them if (nonstatic_contended_count > 0) { - next_nonstatic_padded_offset += pad_size; + next_nonstatic_padded_offset += ContendedPaddingWidth; } // collect all contended groups @@ -3521,7 +3535,7 @@ // the fields within the same contended group are not inter-padded. // The only exception is default group, which does not incur the // equivalence, and so requires intra-padding. - next_nonstatic_padded_offset += pad_size; + next_nonstatic_padded_offset += ContendedPaddingWidth; } fs.set_offset(real_offset); @@ -3533,7 +3547,7 @@ // subclass fields and/or adjacent object. // If this was the default group, the padding is already in place. if (current_group != 0) { - next_nonstatic_padded_offset += pad_size; + next_nonstatic_padded_offset += ContendedPaddingWidth; } } @@ -3547,22 +3561,22 @@ // This helps to alleviate memory contention effects for subclass fields // and/or adjacent object. if (parsed_annotations->is_contended()) { - notaligned_offset += pad_size; + notaligned_offset += ContendedPaddingWidth; } - int next_static_type_offset = align_size_up(next_static_byte_offset, wordSize); - int static_field_size = (next_static_type_offset - - InstanceMirrorKlass::offset_of_static_fields()) / wordSize; - - next_nonstatic_type_offset = align_size_up(notaligned_offset, heapOopSize ); - nonstatic_field_size = nonstatic_field_size + ((next_nonstatic_type_offset - - first_nonstatic_field_offset)/heapOopSize); - - next_nonstatic_type_offset = align_size_up(notaligned_offset, wordSize ); - int instance_size = align_object_size(next_nonstatic_type_offset / wordSize); + int nonstatic_fields_end = align_size_up(notaligned_offset, heapOopSize); + int instance_end = align_size_up(notaligned_offset, wordSize); + int static_fields_end = align_size_up(next_static_byte_offset, wordSize); + + int static_field_size = (static_fields_end - + InstanceMirrorKlass::offset_of_static_fields()) / wordSize; + nonstatic_field_size = nonstatic_field_size + + (nonstatic_fields_end - nonstatic_fields_start) / heapOopSize; + + int instance_size = align_object_size(instance_end / wordSize); assert(instance_size == align_object_size(align_size_up( - (instanceOopDesc::base_offset_in_bytes() + nonstatic_field_size*heapOopSize + ((parsed_annotations->is_contended()) ? pad_size : 0)), + (instanceOopDesc::base_offset_in_bytes() + nonstatic_field_size*heapOopSize), wordSize) / wordSize), "consistent layout helper value"); // Number of non-static oop map blocks allocated at end of klass. @@ -3576,9 +3590,9 @@ _fields, _cp, instance_size, - first_nonstatic_field_offset, - next_nonstatic_field_offset, - next_static_type_offset); + nonstatic_fields_start, + nonstatic_fields_end, + static_fields_end); } #endif diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/classfile/symbolTable.cpp --- a/hotspot/src/share/vm/classfile/symbolTable.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/classfile/symbolTable.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -35,7 +35,6 @@ #include "oops/oop.inline2.hpp" #include "runtime/mutexLocker.hpp" #include "utilities/hashtable.inline.hpp" -#include "utilities/numberSeq.hpp" // -------------------------------------------------------------------------- @@ -451,21 +450,7 @@ } void SymbolTable::dump(outputStream* st) { - NumberSeq summary; - for (int i = 0; i < the_table()->table_size(); ++i) { - int count = 0; - for (HashtableEntry* e = the_table()->bucket(i); - e != NULL; e = e->next()) { - count++; - } - summary.add((double)count); - } - st->print_cr("SymbolTable statistics:"); - st->print_cr("Number of buckets : %7d", summary.num()); - st->print_cr("Average bucket size : %7.0f", summary.avg()); - st->print_cr("Variance of bucket size : %7.0f", summary.variance()); - st->print_cr("Std. dev. of bucket size: %7.0f", summary.sd()); - st->print_cr("Maximum bucket size : %7.0f", summary.maximum()); + the_table()->dump_table(st, "SymbolTable"); } @@ -814,21 +799,7 @@ } void StringTable::dump(outputStream* st) { - NumberSeq summary; - for (int i = 0; i < the_table()->table_size(); ++i) { - HashtableEntry* p = the_table()->bucket(i); - int count = 0; - for ( ; p != NULL; p = p->next()) { - count++; - } - summary.add((double)count); - } - st->print_cr("StringTable statistics:"); - st->print_cr("Number of buckets : %7d", summary.num()); - st->print_cr("Average bucket size : %7.0f", summary.avg()); - st->print_cr("Variance of bucket size : %7.0f", summary.variance()); - st->print_cr("Std. dev. of bucket size: %7.0f", summary.sd()); - st->print_cr("Maximum bucket size : %7.0f", summary.maximum()); + the_table()->dump_table(st, "StringTable"); } diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/code/codeCache.cpp --- a/hotspot/src/share/vm/code/codeCache.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/code/codeCache.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -622,6 +622,15 @@ return (address)_heap->high(); } +/** + * Returns the reverse free ratio. E.g., if 25% (1/4) of the code cache + * is free, reverse_free_ratio() returns 4. + */ +double CodeCache::reverse_free_ratio() { + double unallocated_capacity = (double)(CodeCache::unallocated_capacity() - CodeCacheMinimumFreeSpace); + double max_capacity = (double)CodeCache::max_capacity(); + return max_capacity / unallocated_capacity; +} void icache_init(); diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/code/codeCache.hpp --- a/hotspot/src/share/vm/code/codeCache.hpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/code/codeCache.hpp Wed Jun 05 00:37:11 2013 -0700 @@ -163,6 +163,7 @@ static size_t max_capacity() { return _heap->max_capacity(); } static size_t unallocated_capacity() { return _heap->unallocated_capacity(); } static bool needs_flushing() { return unallocated_capacity() < CodeCacheFlushingMinimumFreeSpace; } + static double reverse_free_ratio(); static bool needs_cache_clean() { return _needs_cache_clean; } static void set_needs_cache_clean(bool v) { _needs_cache_clean = v; } diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/adaptiveFreeList.cpp --- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/adaptiveFreeList.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/adaptiveFreeList.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -51,14 +51,6 @@ } template -AdaptiveFreeList::AdaptiveFreeList(Chunk* fc) : FreeList(fc), _hint(0) { - init_statistics(); -#ifndef PRODUCT - _allocation_stats.set_returned_bytes(size() * HeapWordSize); -#endif -} - -template void AdaptiveFreeList::initialize() { FreeList::initialize(); set_hint(0); diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/adaptiveFreeList.hpp --- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/adaptiveFreeList.hpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/adaptiveFreeList.hpp Wed Jun 05 00:37:11 2013 -0700 @@ -55,7 +55,6 @@ public: AdaptiveFreeList(); - AdaptiveFreeList(Chunk* fc); using FreeList::assert_proper_lock_protection; #ifdef ASSERT diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp --- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -153,8 +153,6 @@ _indexedFreeListParLocks[i] = new Mutex(Mutex::leaf - 1, // == ExpandHeap_lock - 1 "a freelist par lock", true); - if (_indexedFreeListParLocks[i] == NULL) - vm_exit_during_initialization("Could not allocate a par lock"); DEBUG_ONLY( _indexedFreeList[i].set_protecting_lock(_indexedFreeListParLocks[i]); ) @@ -285,6 +283,7 @@ _bt.verify_not_unallocated((HeapWord*)fc, fc->size()); _indexedFreeList[mr.word_size()].return_chunk_at_head(fc); } + coalBirth(mr.word_size()); } _promoInfo.reset(); _smallLinearAllocBlock._ptr = NULL; @@ -1762,7 +1761,7 @@ } ec->set_size(size); debug_only(ec->mangleFreed(size)); - if (size < SmallForDictionary) { + if (size < SmallForDictionary && ParallelGCThreads != 0) { lock = _indexedFreeListParLocks[size]; } MutexLockerEx x(lock, Mutex::_no_safepoint_check_flag); diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp --- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -3381,7 +3381,6 @@ assert_locked_or_safepoint(Heap_lock); bool result = _virtual_space.expand_by(bytes); if (result) { - HeapWord* old_end = _cmsSpace->end(); size_t new_word_size = heap_word_size(_virtual_space.committed_size()); MemRegion mr(_cmsSpace->bottom(), new_word_size); diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.hpp --- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.hpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.hpp Wed Jun 05 00:37:11 2013 -0700 @@ -485,10 +485,6 @@ assert(!span.is_empty(), "Empty span could spell trouble"); } - void do_object(oop obj) { - assert(false, "not to be invoked"); - } - bool do_object_b(oop obj); }; @@ -1536,9 +1532,6 @@ _bit_map(bit_map), _par_scan_closure(cl) { } - void do_object(oop obj) { - guarantee(false, "Call do_object_b(oop, MemRegion) instead"); - } bool do_object_b(oop obj) { guarantee(false, "Call do_object_b(oop, MemRegion) form instead"); return false; diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/gc_implementation/g1/concurrentMark.hpp --- a/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.hpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.hpp Wed Jun 05 00:37:11 2013 -0700 @@ -44,9 +44,6 @@ public: G1CMIsAliveClosure(G1CollectedHeap* g1) : _g1(g1) { } - void do_object(oop obj) { - ShouldNotCallThis(); - } bool do_object_b(oop obj); }; diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp --- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -5090,7 +5090,6 @@ G1CollectedHeap* _g1; public: G1AlwaysAliveClosure(G1CollectedHeap* g1) : _g1(g1) {} - void do_object(oop p) { assert(false, "Do not call."); } bool do_object_b(oop p) { if (p != NULL) { return true; diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp --- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp Wed Jun 05 00:37:11 2013 -0700 @@ -165,7 +165,6 @@ G1CollectedHeap* _g1; public: G1STWIsAliveClosure(G1CollectedHeap* g1) : _g1(g1) {} - void do_object(oop p) { assert(false, "Do not call."); } bool do_object_b(oop p); }; diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp --- a/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -242,11 +242,13 @@ PerRegionTable* cur = _free_list; size_t res = 0; while (cur != NULL) { - res += sizeof(PerRegionTable); + res += cur->mem_size(); cur = cur->next(); } return res; } + + static void test_fl_mem_size(); }; PerRegionTable* PerRegionTable::_free_list = NULL; @@ -1149,6 +1151,19 @@ } #ifndef PRODUCT +void PerRegionTable::test_fl_mem_size() { + PerRegionTable* dummy = alloc(NULL); + free(dummy); + guarantee(dummy->mem_size() == fl_mem_size(), "fl_mem_size() does not return the correct element size"); + // try to reset the state + _free_list = NULL; + delete dummy; +} + +void HeapRegionRemSet::test_prt() { + PerRegionTable::test_fl_mem_size(); +} + void HeapRegionRemSet::test() { os::sleep(Thread::current(), (jlong)5000, false); G1CollectedHeap* g1h = G1CollectedHeap::heap(); diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.hpp --- a/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.hpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.hpp Wed Jun 05 00:37:11 2013 -0700 @@ -338,6 +338,7 @@ // Run unit tests. #ifndef PRODUCT + static void test_prt(); static void test(); #endif }; diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/gc_implementation/parallelScavenge/parMarkBitMap.cpp --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/parMarkBitMap.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/parMarkBitMap.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 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 @@ -54,18 +54,18 @@ const size_t raw_bytes = words * sizeof(idx_t); const size_t page_sz = os::page_size_for_region(raw_bytes, raw_bytes, 10); const size_t granularity = os::vm_allocation_granularity(); - const size_t bytes = align_size_up(raw_bytes, MAX2(page_sz, granularity)); + _reserved_byte_size = align_size_up(raw_bytes, MAX2(page_sz, granularity)); const size_t rs_align = page_sz == (size_t) os::vm_page_size() ? 0 : MAX2(page_sz, granularity); - ReservedSpace rs(bytes, rs_align, rs_align > 0); + ReservedSpace rs(_reserved_byte_size, rs_align, rs_align > 0); os::trace_page_sizes("par bitmap", raw_bytes, raw_bytes, page_sz, rs.base(), rs.size()); MemTracker::record_virtual_memory_type((address)rs.base(), mtGC); _virtual_space = new PSVirtualSpace(rs, page_sz); - if (_virtual_space != NULL && _virtual_space->expand_by(bytes)) { + if (_virtual_space != NULL && _virtual_space->expand_by(_reserved_byte_size)) { _region_start = covered_region.start(); _region_size = covered_region.word_size(); idx_t* map = (idx_t*)_virtual_space->reserved_low_addr(); diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/gc_implementation/parallelScavenge/parMarkBitMap.hpp --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/parMarkBitMap.hpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/parMarkBitMap.hpp Wed Jun 05 00:37:11 2013 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 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 @@ -131,6 +131,8 @@ inline size_t region_size() const; inline size_t size() const; + size_t reserved_byte_size() const { return _reserved_byte_size; } + // Convert a heap address to/from a bit index. inline idx_t addr_to_bit(HeapWord* addr) const; inline HeapWord* bit_to_addr(idx_t bit) const; @@ -176,10 +178,11 @@ BitMap _beg_bits; BitMap _end_bits; PSVirtualSpace* _virtual_space; + size_t _reserved_byte_size; }; inline ParMarkBitMap::ParMarkBitMap(): - _beg_bits(), _end_bits(), _region_start(NULL), _region_size(0), _virtual_space(NULL) + _beg_bits(), _end_bits(), _region_start(NULL), _region_size(0), _virtual_space(NULL), _reserved_byte_size(0) { } inline void ParMarkBitMap::clear_range(idx_t beg, idx_t end) diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/gc_implementation/parallelScavenge/psMarkSweep.cpp --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psMarkSweep.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psMarkSweep.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -580,7 +580,6 @@ // This should be moved to the shared markSweep code! class PSAlwaysTrueClosure: public BoolObjectClosure { public: - void do_object(oop p) { ShouldNotReachHere(); } bool do_object_b(oop p) { return true; } }; static PSAlwaysTrueClosure always_true; diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -356,6 +356,7 @@ _region_start = 0; _region_vspace = 0; + _reserved_byte_size = 0; _region_data = 0; _region_count = 0; } @@ -382,11 +383,11 @@ const size_t raw_bytes = count * element_size; const size_t page_sz = os::page_size_for_region(raw_bytes, raw_bytes, 10); const size_t granularity = os::vm_allocation_granularity(); - const size_t bytes = align_size_up(raw_bytes, MAX2(page_sz, granularity)); + _reserved_byte_size = align_size_up(raw_bytes, MAX2(page_sz, granularity)); const size_t rs_align = page_sz == (size_t) os::vm_page_size() ? 0 : MAX2(page_sz, granularity); - ReservedSpace rs(bytes, rs_align, rs_align > 0); + ReservedSpace rs(_reserved_byte_size, rs_align, rs_align > 0); os::trace_page_sizes("par compact", raw_bytes, raw_bytes, page_sz, rs.base(), rs.size()); @@ -394,7 +395,7 @@ PSVirtualSpace* vspace = new PSVirtualSpace(rs, page_sz); if (vspace != 0) { - if (vspace->expand_by(bytes)) { + if (vspace->expand_by(_reserved_byte_size)) { return vspace; } delete vspace; @@ -781,7 +782,6 @@ PSParallelCompact::IsAliveClosure PSParallelCompact::_is_alive_closure; -void PSParallelCompact::IsAliveClosure::do_object(oop p) { ShouldNotReachHere(); } bool PSParallelCompact::IsAliveClosure::do_object_b(oop p) { return mark_bitmap()->is_marked(p); } void PSParallelCompact::KeepAliveClosure::do_oop(oop* p) { PSParallelCompact::KeepAliveClosure::do_oop_work(p); } @@ -841,14 +841,18 @@ initialize_dead_wood_limiter(); if (!_mark_bitmap.initialize(mr)) { - vm_shutdown_during_initialization("Unable to allocate bit map for " - "parallel garbage collection for the requested heap size."); + vm_shutdown_during_initialization( + err_msg("Unable to allocate " SIZE_FORMAT "KB bitmaps for parallel " + "garbage collection for the requested " SIZE_FORMAT "KB heap.", + _mark_bitmap.reserved_byte_size()/K, mr.byte_size()/K)); return false; } if (!_summary_data.initialize(mr)) { - vm_shutdown_during_initialization("Unable to allocate tables for " - "parallel garbage collection for the requested heap size."); + vm_shutdown_during_initialization( + err_msg("Unable to allocate " SIZE_FORMAT "KB card tables for parallel " + "garbage collection for the requested " SIZE_FORMAT "KB heap.", + _summary_data.reserved_byte_size()/K, mr.byte_size()/K)); return false; } @@ -2413,7 +2417,6 @@ // This should be moved to the shared markSweep code! class PSAlwaysTrueClosure: public BoolObjectClosure { public: - void do_object(oop p) { ShouldNotReachHere(); } bool do_object_b(oop p) { return true; } }; static PSAlwaysTrueClosure always_true; diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.hpp --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.hpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.hpp Wed Jun 05 00:37:11 2013 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 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 @@ -347,6 +347,7 @@ bool initialize(MemRegion covered_region); size_t region_count() const { return _region_count; } + size_t reserved_byte_size() const { return _reserved_byte_size; } // Convert region indices to/from RegionData pointers. inline RegionData* region(size_t region_idx) const; @@ -420,6 +421,7 @@ #endif // #ifdef ASSERT PSVirtualSpace* _region_vspace; + size_t _reserved_byte_size; RegionData* _region_data; size_t _region_count; }; @@ -784,7 +786,6 @@ // class IsAliveClosure: public BoolObjectClosure { public: - virtual void do_object(oop p); virtual bool do_object_b(oop p); }; diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -70,9 +70,6 @@ // Define before use class PSIsAliveClosure: public BoolObjectClosure { public: - void do_object(oop p) { - assert(false, "Do not call."); - } bool do_object_b(oop p) { return (!PSScavenge::is_obj_in_young((HeapWord*) p)) || p->is_forwarded(); } diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/gc_implementation/shared/markSweep.cpp --- a/hotspot/src/share/vm/gc_implementation/shared/markSweep.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/gc_implementation/shared/markSweep.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -166,7 +166,6 @@ MarkSweep::IsAliveClosure MarkSweep::is_alive; -void MarkSweep::IsAliveClosure::do_object(oop p) { ShouldNotReachHere(); } bool MarkSweep::IsAliveClosure::do_object_b(oop p) { return p->is_gc_marked(); } MarkSweep::KeepAliveClosure MarkSweep::keep_alive; diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/gc_implementation/shared/markSweep.hpp --- a/hotspot/src/share/vm/gc_implementation/shared/markSweep.hpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/gc_implementation/shared/markSweep.hpp Wed Jun 05 00:37:11 2013 -0700 @@ -88,7 +88,6 @@ // Used for java/lang/ref handling class IsAliveClosure: public BoolObjectClosure { public: - virtual void do_object(oop p); virtual bool do_object_b(oop p); }; diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/memory/defNewGeneration.cpp --- a/hotspot/src/share/vm/memory/defNewGeneration.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/memory/defNewGeneration.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -50,9 +50,6 @@ DefNewGeneration::IsAliveClosure::IsAliveClosure(Generation* g) : _g(g) { assert(g->level() == 0, "Optimized for youngest gen."); } -void DefNewGeneration::IsAliveClosure::do_object(oop p) { - assert(false, "Do not call."); -} bool DefNewGeneration::IsAliveClosure::do_object_b(oop p) { return (HeapWord*)p >= _g->reserved().end() || p->is_forwarded(); } diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/memory/defNewGeneration.hpp --- a/hotspot/src/share/vm/memory/defNewGeneration.hpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/memory/defNewGeneration.hpp Wed Jun 05 00:37:11 2013 -0700 @@ -150,7 +150,6 @@ Generation* _g; public: IsAliveClosure(Generation* g); - void do_object(oop p); bool do_object_b(oop p); }; diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/memory/freeList.cpp --- a/hotspot/src/share/vm/memory/freeList.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/memory/freeList.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -55,17 +55,6 @@ } template -FreeList::FreeList(Chunk* fc) : - _head(fc), _tail(fc) -#ifdef ASSERT - , _protecting_lock(NULL) -#endif -{ - _size = fc->size(); - _count = 1; -} - -template void FreeList::link_head(Chunk* v) { assert_proper_lock_protection(); set_head(v); diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/memory/freeList.hpp --- a/hotspot/src/share/vm/memory/freeList.hpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/memory/freeList.hpp Wed Jun 05 00:37:11 2013 -0700 @@ -80,8 +80,6 @@ // Constructor // Construct a list without any entries. FreeList(); - // Construct a list with "fc" as the first (and lone) entry in the list. - FreeList(Chunk_t* fc); // Do initialization void initialize(); @@ -177,9 +175,6 @@ // found. Return NULL if "fc" is not found. bool verify_chunk_in_free_list(Chunk_t* fc) const; - // Stats verification -// void verify_stats() const { ShouldNotReachHere(); }; - // Printing support static void print_labels_on(outputStream* st, const char* c); void print_on(outputStream* st, const char* c = NULL) const; diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/memory/iterator.hpp --- a/hotspot/src/share/vm/memory/iterator.hpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/memory/iterator.hpp Wed Jun 05 00:37:11 2013 -0700 @@ -158,7 +158,7 @@ }; -class BoolObjectClosure : public ObjectClosure { +class BoolObjectClosure : public Closure { public: virtual bool do_object_b(oop obj) = 0; }; diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/memory/metaspace.cpp --- a/hotspot/src/share/vm/memory/metaspace.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/memory/metaspace.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -562,6 +562,9 @@ // protects allocations and contains. Mutex* const _lock; + // Type of metadata allocated. + Metaspace::MetadataType _mdtype; + // Chunk related size size_t _medium_chunk_bunch; @@ -606,6 +609,7 @@ return (BlockFreelist*) &_block_freelists; } + Metaspace::MetadataType mdtype() { return _mdtype; } VirtualSpaceList* vs_list() const { return _vs_list; } Metachunk* current_chunk() const { return _current_chunk; } @@ -626,7 +630,8 @@ void initialize(); public: - SpaceManager(Mutex* lock, + SpaceManager(Metaspace::MetadataType mdtype, + Mutex* lock, VirtualSpaceList* vs_list); ~SpaceManager(); @@ -2032,9 +2037,11 @@ } } -SpaceManager::SpaceManager(Mutex* lock, +SpaceManager::SpaceManager(Metaspace::MetadataType mdtype, + Mutex* lock, VirtualSpaceList* vs_list) : _vs_list(vs_list), + _mdtype(mdtype), _allocated_blocks_words(0), _allocated_chunks_words(0), _allocated_chunks_count(0), @@ -2050,27 +2057,27 @@ _allocated_chunks_words = _allocated_chunks_words + words; _allocated_chunks_count++; // Global total of capacity in allocated Metachunks - MetaspaceAux::inc_capacity(words); + MetaspaceAux::inc_capacity(mdtype(), words); // Global total of allocated Metablocks. // used_words_slow() includes the overhead in each // Metachunk so include it in the used when the // Metachunk is first added (so only added once per // Metachunk). - MetaspaceAux::inc_used(Metachunk::overhead()); + MetaspaceAux::inc_used(mdtype(), Metachunk::overhead()); } void SpaceManager::inc_used_metrics(size_t words) { // Add to the per SpaceManager total Atomic::add_ptr(words, &_allocated_blocks_words); // Add to the global total - MetaspaceAux::inc_used(words); + MetaspaceAux::inc_used(mdtype(), words); } void SpaceManager::dec_total_from_size_metrics() { - MetaspaceAux::dec_capacity(allocated_chunks_words()); - MetaspaceAux::dec_used(allocated_blocks_words()); + MetaspaceAux::dec_capacity(mdtype(), allocated_chunks_words()); + MetaspaceAux::dec_used(mdtype(), allocated_blocks_words()); // Also deduct the overhead per Metachunk - MetaspaceAux::dec_used(allocated_chunks_count() * Metachunk::overhead()); + MetaspaceAux::dec_used(mdtype(), allocated_chunks_count() * Metachunk::overhead()); } void SpaceManager::initialize() { @@ -2470,8 +2477,8 @@ // MetaspaceAux -size_t MetaspaceAux::_allocated_capacity_words = 0; -size_t MetaspaceAux::_allocated_used_words = 0; +size_t MetaspaceAux::_allocated_capacity_words[] = {0, 0}; +size_t MetaspaceAux::_allocated_used_words[] = {0, 0}; size_t MetaspaceAux::free_bytes() { size_t result = 0; @@ -2484,40 +2491,40 @@ return result; } -void MetaspaceAux::dec_capacity(size_t words) { +void MetaspaceAux::dec_capacity(Metaspace::MetadataType mdtype, size_t words) { assert_lock_strong(SpaceManager::expand_lock()); - assert(words <= _allocated_capacity_words, + assert(words <= allocated_capacity_words(mdtype), err_msg("About to decrement below 0: words " SIZE_FORMAT - " is greater than _allocated_capacity_words " SIZE_FORMAT, - words, _allocated_capacity_words)); - _allocated_capacity_words = _allocated_capacity_words - words; + " is greater than _allocated_capacity_words[%u] " SIZE_FORMAT, + words, mdtype, allocated_capacity_words(mdtype))); + _allocated_capacity_words[mdtype] -= words; } -void MetaspaceAux::inc_capacity(size_t words) { +void MetaspaceAux::inc_capacity(Metaspace::MetadataType mdtype, size_t words) { assert_lock_strong(SpaceManager::expand_lock()); // Needs to be atomic - _allocated_capacity_words = _allocated_capacity_words + words; + _allocated_capacity_words[mdtype] += words; } -void MetaspaceAux::dec_used(size_t words) { - assert(words <= _allocated_used_words, +void MetaspaceAux::dec_used(Metaspace::MetadataType mdtype, size_t words) { + assert(words <= allocated_used_words(mdtype), err_msg("About to decrement below 0: words " SIZE_FORMAT - " is greater than _allocated_used_words " SIZE_FORMAT, - words, _allocated_used_words)); + " is greater than _allocated_used_words[%u] " SIZE_FORMAT, + words, mdtype, allocated_used_words(mdtype))); // For CMS deallocation of the Metaspaces occurs during the // sweep which is a concurrent phase. Protection by the expand_lock() // is not enough since allocation is on a per Metaspace basis // and protected by the Metaspace lock. jlong minus_words = (jlong) - (jlong) words; - Atomic::add_ptr(minus_words, &_allocated_used_words); + Atomic::add_ptr(minus_words, &_allocated_used_words[mdtype]); } -void MetaspaceAux::inc_used(size_t words) { +void MetaspaceAux::inc_used(Metaspace::MetadataType mdtype, size_t words) { // _allocated_used_words tracks allocations for // each piece of metadata. Those allocations are // generally done concurrently by different application // threads so must be done atomically. - Atomic::add_ptr(words, &_allocated_used_words); + Atomic::add_ptr(words, &_allocated_used_words[mdtype]); } size_t MetaspaceAux::used_bytes_slow(Metaspace::MetadataType mdtype) { @@ -2619,21 +2626,19 @@ SIZE_FORMAT "K, used " SIZE_FORMAT "K," " reserved " SIZE_FORMAT "K", allocated_capacity_bytes()/K, allocated_used_bytes()/K, reserved_in_bytes()/K); -#if 0 -// The calls to capacity_bytes_slow() and used_bytes_slow() cause -// lock ordering assertion failures with some collectors. Do -// not include this code until the lock ordering is fixed. - if (PrintGCDetails && Verbose) { - out->print_cr(" data space " - SIZE_FORMAT "K, used " SIZE_FORMAT "K," - " reserved " SIZE_FORMAT "K", - capacity_bytes_slow(nct)/K, used_bytes_slow(nct)/K, reserved_in_bytes(nct)/K); - out->print_cr(" class space " - SIZE_FORMAT "K, used " SIZE_FORMAT "K," - " reserved " SIZE_FORMAT "K", - capacity_bytes_slow(ct)/K, used_bytes_slow(ct)/K, reserved_in_bytes(ct)/K); - } -#endif + + out->print_cr(" data space " + SIZE_FORMAT "K, used " SIZE_FORMAT "K," + " reserved " SIZE_FORMAT "K", + allocated_capacity_bytes(nct)/K, + allocated_used_bytes(nct)/K, + reserved_in_bytes(nct)/K); + out->print_cr(" class space " + SIZE_FORMAT "K, used " SIZE_FORMAT "K," + " reserved " SIZE_FORMAT "K", + allocated_capacity_bytes(ct)/K, + allocated_used_bytes(ct)/K, + reserved_in_bytes(ct)/K); } // Print information for class space and data space separately. @@ -2717,24 +2722,42 @@ void MetaspaceAux::verify_capacity() { #ifdef ASSERT size_t running_sum_capacity_bytes = allocated_capacity_bytes(); - // For purposes of the running sum of used, verify against capacity + // For purposes of the running sum of capacity, verify against capacity size_t capacity_in_use_bytes = capacity_bytes_slow(); assert(running_sum_capacity_bytes == capacity_in_use_bytes, err_msg("allocated_capacity_words() * BytesPerWord " SIZE_FORMAT " capacity_bytes_slow()" SIZE_FORMAT, running_sum_capacity_bytes, capacity_in_use_bytes)); + for (Metaspace::MetadataType i = Metaspace::ClassType; + i < Metaspace:: MetadataTypeCount; + i = (Metaspace::MetadataType)(i + 1)) { + size_t capacity_in_use_bytes = capacity_bytes_slow(i); + assert(allocated_capacity_bytes(i) == capacity_in_use_bytes, + err_msg("allocated_capacity_bytes(%u) " SIZE_FORMAT + " capacity_bytes_slow(%u)" SIZE_FORMAT, + i, allocated_capacity_bytes(i), i, capacity_in_use_bytes)); + } #endif } void MetaspaceAux::verify_used() { #ifdef ASSERT size_t running_sum_used_bytes = allocated_used_bytes(); - // For purposes of the running sum of used, verify against capacity + // For purposes of the running sum of used, verify against used size_t used_in_use_bytes = used_bytes_slow(); assert(allocated_used_bytes() == used_in_use_bytes, err_msg("allocated_used_bytes() " SIZE_FORMAT - " used_bytes_slow()()" SIZE_FORMAT, + " used_bytes_slow()" SIZE_FORMAT, allocated_used_bytes(), used_in_use_bytes)); + for (Metaspace::MetadataType i = Metaspace::ClassType; + i < Metaspace:: MetadataTypeCount; + i = (Metaspace::MetadataType)(i + 1)) { + size_t used_in_use_bytes = used_bytes_slow(i); + assert(allocated_used_bytes(i) == used_in_use_bytes, + err_msg("allocated_used_bytes(%u) " SIZE_FORMAT + " used_bytes_slow(%u)" SIZE_FORMAT, + i, allocated_used_bytes(i), i, used_in_use_bytes)); + } #endif } @@ -2835,7 +2858,7 @@ assert(space_list() != NULL, "Metadata VirtualSpaceList has not been initialized"); - _vsm = new SpaceManager(lock, space_list()); + _vsm = new SpaceManager(Metaspace::NonClassType, lock, space_list()); if (_vsm == NULL) { return; } @@ -2849,7 +2872,7 @@ "Class VirtualSpaceList has not been initialized"); // Allocate SpaceManager for classes. - _class_vsm = new SpaceManager(lock, class_space_list()); + _class_vsm = new SpaceManager(Metaspace::ClassType, lock, class_space_list()); if (_class_vsm == NULL) { return; } diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/memory/metaspace.hpp --- a/hotspot/src/share/vm/memory/metaspace.hpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/memory/metaspace.hpp Wed Jun 05 00:37:11 2013 -0700 @@ -86,7 +86,10 @@ friend class MetaspaceAux; public: - enum MetadataType {ClassType, NonClassType}; + enum MetadataType {ClassType = 0, + NonClassType = ClassType + 1, + MetadataTypeCount = ClassType + 2 + }; enum MetaspaceType { StandardMetaspaceType, BootMetaspaceType, @@ -184,20 +187,22 @@ public: // Running sum of space in all Metachunks that has been // allocated to a Metaspace. This is used instead of - // iterating over all the classloaders - static size_t _allocated_capacity_words; + // iterating over all the classloaders. One for each + // type of Metadata + static size_t _allocated_capacity_words[Metaspace:: MetadataTypeCount]; // Running sum of space in all Metachunks that have - // are being used for metadata. - static size_t _allocated_used_words; + // are being used for metadata. One for each + // type of Metadata. + static size_t _allocated_used_words[Metaspace:: MetadataTypeCount]; public: // Decrement and increment _allocated_capacity_words - static void dec_capacity(size_t words); - static void inc_capacity(size_t words); + static void dec_capacity(Metaspace::MetadataType type, size_t words); + static void inc_capacity(Metaspace::MetadataType type, size_t words); // Decrement and increment _allocated_used_words - static void dec_used(size_t words); - static void inc_used(size_t words); + static void dec_used(Metaspace::MetadataType type, size_t words); + static void inc_used(Metaspace::MetadataType type, size_t words); // Total of space allocated to metadata in all Metaspaces. // This sums the space used in each Metachunk by @@ -211,18 +216,32 @@ static size_t free_chunks_total(); static size_t free_chunks_total_in_bytes(); + static size_t allocated_capacity_words(Metaspace::MetadataType mdtype) { + return _allocated_capacity_words[mdtype]; + } static size_t allocated_capacity_words() { - return _allocated_capacity_words; + return _allocated_capacity_words[Metaspace::ClassType] + + _allocated_capacity_words[Metaspace::NonClassType]; + } + static size_t allocated_capacity_bytes(Metaspace::MetadataType mdtype) { + return allocated_capacity_words(mdtype) * BytesPerWord; } static size_t allocated_capacity_bytes() { - return _allocated_capacity_words * BytesPerWord; + return allocated_capacity_words() * BytesPerWord; } + static size_t allocated_used_words(Metaspace::MetadataType mdtype) { + return _allocated_used_words[mdtype]; + } static size_t allocated_used_words() { - return _allocated_used_words; + return _allocated_used_words[Metaspace::ClassType] + + _allocated_used_words[Metaspace::NonClassType]; + } + static size_t allocated_used_bytes(Metaspace::MetadataType mdtype) { + return allocated_used_words(mdtype) * BytesPerWord; } static size_t allocated_used_bytes() { - return _allocated_used_words * BytesPerWord; + return allocated_used_words() * BytesPerWord; } static size_t free_bytes(); diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/memory/referenceProcessor.cpp --- a/hotspot/src/share/vm/memory/referenceProcessor.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/memory/referenceProcessor.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -252,7 +252,6 @@ class AlwaysAliveClosure: public BoolObjectClosure { public: virtual bool do_object_b(oop obj) { return true; } - virtual void do_object(oop obj) { assert(false, "Don't call"); } }; class CountHandleClosure: public OopClosure { diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/memory/sharedHeap.cpp --- a/hotspot/src/share/vm/memory/sharedHeap.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/memory/sharedHeap.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -212,7 +212,6 @@ class AlwaysTrueClosure: public BoolObjectClosure { public: - void do_object(oop p) { ShouldNotReachHere(); } bool do_object_b(oop p) { return true; } }; static AlwaysTrueClosure always_true; diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/opto/loopnode.hpp --- a/hotspot/src/share/vm/opto/loopnode.hpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/opto/loopnode.hpp Wed Jun 05 00:37:11 2013 -0700 @@ -965,7 +965,7 @@ // Has use internal to the vector set (ie. not in a phi at the loop head) bool has_use_internal_to_set( Node* n, VectorSet& vset, IdealLoopTree *loop ); // clone "n" for uses that are outside of loop - void clone_for_use_outside_loop( IdealLoopTree *loop, Node* n, Node_List& worklist ); + int clone_for_use_outside_loop( IdealLoopTree *loop, Node* n, Node_List& worklist ); // clone "n" for special uses that are in the not_peeled region void clone_for_special_use_inside_loop( IdealLoopTree *loop, Node* n, VectorSet& not_peel, Node_List& sink_list, Node_List& worklist ); diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/opto/loopopts.cpp --- a/hotspot/src/share/vm/opto/loopopts.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/opto/loopopts.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -1939,8 +1939,8 @@ //------------------------------ clone_for_use_outside_loop ------------------------------------- // clone "n" for uses that are outside of loop -void PhaseIdealLoop::clone_for_use_outside_loop( IdealLoopTree *loop, Node* n, Node_List& worklist ) { - +int PhaseIdealLoop::clone_for_use_outside_loop( IdealLoopTree *loop, Node* n, Node_List& worklist ) { + int cloned = 0; assert(worklist.size() == 0, "should be empty"); for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) { Node* use = n->fast_out(j); @@ -1960,6 +1960,7 @@ // clone "n" and insert it between the inputs of "n" and the use outside the loop Node* n_clone = n->clone(); _igvn.replace_input_of(use, j, n_clone); + cloned++; Node* use_c; if (!use->is_Phi()) { use_c = has_ctrl(use) ? get_ctrl(use) : use->in(0); @@ -1977,6 +1978,7 @@ } #endif } + return cloned; } @@ -2495,6 +2497,7 @@ // Evacuate nodes in peel region into the not_peeled region if possible uint new_phi_cnt = 0; + uint cloned_for_outside_use = 0; for (i = 0; i < peel_list.size();) { Node* n = peel_list.at(i); #if !defined(PRODUCT) @@ -2513,8 +2516,7 @@ // if not pinned and not a load (which maybe anti-dependent on a store) // and not a CMove (Matcher expects only bool->cmove). if ( n->in(0) == NULL && !n->is_Load() && !n->is_CMove() ) { - clone_for_use_outside_loop( loop, n, worklist ); - + cloned_for_outside_use += clone_for_use_outside_loop( loop, n, worklist ); sink_list.push(n); peel >>= n->_idx; // delete n from peel set. not_peel <<= n->_idx; // add n to not_peel set. @@ -2551,6 +2553,12 @@ // Inhibit more partial peeling on this loop assert(!head->is_partial_peel_loop(), "not partial peeled"); head->mark_partial_peel_failed(); + if (cloned_for_outside_use > 0) { + // Terminate this round of loop opts because + // the graph outside this loop was changed. + C->set_major_progress(); + return true; + } return false; } diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/prims/jni.cpp --- a/hotspot/src/share/vm/prims/jni.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/prims/jni.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -5015,6 +5015,9 @@ #ifndef PRODUCT #include "gc_interface/collectedHeap.hpp" +#if INCLUDE_ALL_GCS +#include "gc_implementation/g1/heapRegionRemSet.hpp" +#endif #include "utilities/quickSort.hpp" #if INCLUDE_VM_STRUCTS #include "runtime/vmStructs.hpp" @@ -5035,6 +5038,9 @@ #if INCLUDE_VM_STRUCTS run_unit_test(VMStructs::test()); #endif +#if INCLUDE_ALL_GCS + run_unit_test(HeapRegionRemSet::test_prt()); +#endif tty->print_cr("All internal VM tests passed"); } } diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/prims/jvmtiExport.cpp --- a/hotspot/src/share/vm/prims/jvmtiExport.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/prims/jvmtiExport.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -1624,15 +1624,19 @@ } } + assert(sig_type != '[', "array should have sig_type == 'L'"); + bool handle_created = false; + // convert oop to JNI handle. - if (sig_type == 'L' || sig_type == '[') { + if (sig_type == 'L') { + handle_created = true; value->l = (jobject)JNIHandles::make_local(thread, (oop)value->l); } post_field_modification(thread, method, location, field_klass, object, field, sig_type, value); // Destroy the JNI handle allocated above. - if (sig_type == 'L') { + if (handle_created) { JNIHandles::destroy_local(value->l); } } diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/runtime/advancedThresholdPolicy.cpp --- a/hotspot/src/share/vm/runtime/advancedThresholdPolicy.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/runtime/advancedThresholdPolicy.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -68,7 +68,7 @@ } #endif - + set_increase_threshold_at_ratio(); set_start_time(os::javaTimeMillis()); } @@ -205,6 +205,17 @@ double queue_size = CompileBroker::queue_size(level); int comp_count = compiler_count(level); double k = queue_size / (feedback_k * comp_count) + 1; + + // Increase C1 compile threshold when the code cache is filled more + // than specified by IncreaseFirstTierCompileThresholdAt percentage. + // The main intention is to keep enough free space for C2 compiled code + // to achieve peak performance if the code cache is under stress. + if ((TieredStopAtLevel == CompLevel_full_optimization) && (level != CompLevel_full_optimization)) { + double current_reverse_free_ratio = CodeCache::reverse_free_ratio(); + if (current_reverse_free_ratio > _increase_threshold_at_ratio) { + k *= exp(current_reverse_free_ratio - _increase_threshold_at_ratio); + } + } return k; } diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/runtime/advancedThresholdPolicy.hpp --- a/hotspot/src/share/vm/runtime/advancedThresholdPolicy.hpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/runtime/advancedThresholdPolicy.hpp Wed Jun 05 00:37:11 2013 -0700 @@ -201,9 +201,12 @@ // Is method profiled enough? bool is_method_profiled(Method* method); + double _increase_threshold_at_ratio; + protected: void print_specific(EventType type, methodHandle mh, methodHandle imh, int bci, CompLevel level); + void set_increase_threshold_at_ratio() { _increase_threshold_at_ratio = 100 / (100 - (double)IncreaseFirstTierCompileThresholdAt); } void set_start_time(jlong t) { _start_time = t; } jlong start_time() const { return _start_time; } diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/runtime/arguments.cpp --- a/hotspot/src/share/vm/runtime/arguments.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/runtime/arguments.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -2629,6 +2629,16 @@ return JNI_EINVAL; } FLAG_SET_CMDLINE(uintx, ReservedCodeCacheSize, (uintx)long_ReservedCodeCacheSize); + //-XX:IncreaseFirstTierCompileThresholdAt= + } else if (match_option(option, "-XX:IncreaseFirstTierCompileThresholdAt=", &tail)) { + uintx uint_IncreaseFirstTierCompileThresholdAt = 0; + if (!parse_uintx(tail, &uint_IncreaseFirstTierCompileThresholdAt, 0) || uint_IncreaseFirstTierCompileThresholdAt > 99) { + jio_fprintf(defaultStream::error_stream(), + "Invalid value for IncreaseFirstTierCompileThresholdAt: %s. Should be between 0 and 99.\n", + option->optionString); + return JNI_EINVAL; + } + FLAG_SET_CMDLINE(uintx, IncreaseFirstTierCompileThresholdAt, (uintx)uint_IncreaseFirstTierCompileThresholdAt); // -green } else if (match_option(option, "-green", &tail)) { jio_fprintf(defaultStream::error_stream(), diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/runtime/globals.hpp --- a/hotspot/src/share/vm/runtime/globals.hpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/runtime/globals.hpp Wed Jun 05 00:37:11 2013 -0700 @@ -3436,6 +3436,10 @@ "Start profiling in interpreter if the counters exceed tier 3" \ "thresholds by the specified percentage") \ \ + product(uintx, IncreaseFirstTierCompileThresholdAt, 50, \ + "Increase the compile threshold for C1 compilation if the code" \ + "cache is filled by the specified percentage.") \ + \ product(intx, TieredRateUpdateMinTime, 1, \ "Minimum rate sampling interval (in milliseconds)") \ \ diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/runtime/jniHandles.cpp --- a/hotspot/src/share/vm/runtime/jniHandles.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/runtime/jniHandles.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -188,7 +188,6 @@ class AlwaysAliveClosure: public BoolObjectClosure { public: bool do_object_b(oop obj) { return true; } - void do_object(oop obj) { assert(false, "Don't call"); } }; class CountHandleClosure: public OopClosure { diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/utilities/debug.cpp --- a/hotspot/src/share/vm/utilities/debug.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/utilities/debug.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -665,152 +665,4 @@ tty->print_cr(" ndebug() - undo debug"); } -#if 0 - -// BobV's command parser for debugging on windows when nothing else works. - -enum CommandID { - CMDID_HELP, - CMDID_QUIT, - CMDID_HSFIND, - CMDID_PSS, - CMDID_PS, - CMDID_PSF, - CMDID_FINDM, - CMDID_FINDNM, - CMDID_PP, - CMDID_BPT, - CMDID_EXIT, - CMDID_VERIFY, - CMDID_THREADS, - CMDID_ILLEGAL = 99 -}; - -struct CommandParser { - char *name; - CommandID code; - char *description; -}; - -struct CommandParser CommandList[] = { - (char *)"help", CMDID_HELP, " Dump this list", - (char *)"quit", CMDID_QUIT, " Return from this routine", - (char *)"hsfind", CMDID_HSFIND, "Perform an hsfind on an address", - (char *)"ps", CMDID_PS, " Print Current Thread Stack Trace", - (char *)"pss", CMDID_PSS, " Print All Thread Stack Trace", - (char *)"psf", CMDID_PSF, " Print All Stack Frames", - (char *)"findm", CMDID_FINDM, " Find a Method* from a PC", - (char *)"findnm", CMDID_FINDNM, "Find an nmethod from a PC", - (char *)"pp", CMDID_PP, " Find out something about a pointer", - (char *)"break", CMDID_BPT, " Execute a breakpoint", - (char *)"exitvm", CMDID_EXIT, "Exit the VM", - (char *)"verify", CMDID_VERIFY, "Perform a Heap Verify", - (char *)"thread", CMDID_THREADS, "Dump Info on all Threads", - (char *)0, CMDID_ILLEGAL -}; - - -// get_debug_command() -// -// Read a command from standard input. -// This is useful when you have a debugger -// which doesn't support calling into functions. -// -void get_debug_command() -{ - ssize_t count; - int i,j; - bool gotcommand; - intptr_t addr; - char buffer[256]; - nmethod *nm; - Method* m; - - tty->print_cr("You have entered the diagnostic command interpreter"); - tty->print("The supported commands are:\n"); - for ( i=0; ; i++ ) { - if ( CommandList[i].code == CMDID_ILLEGAL ) - break; - tty->print_cr(" %s \n", CommandList[i].name ); - } - - while ( 1 ) { - gotcommand = false; - tty->print("Please enter a command: "); - count = scanf("%s", buffer) ; - if ( count >=0 ) { - for ( i=0; ; i++ ) { - if ( CommandList[i].code == CMDID_ILLEGAL ) { - if (!gotcommand) tty->print("Invalid command, please try again\n"); - break; - } - if ( strcmp(buffer, CommandList[i].name) == 0 ) { - gotcommand = true; - switch ( CommandList[i].code ) { - case CMDID_PS: - ps(); - break; - case CMDID_PSS: - pss(); - break; - case CMDID_PSF: - psf(); - break; - case CMDID_FINDM: - tty->print("Please enter the hex addr to pass to findm: "); - scanf("%I64X", &addr); - m = (Method*)findm(addr); - tty->print("findm(0x%I64X) returned 0x%I64X\n", addr, m); - break; - case CMDID_FINDNM: - tty->print("Please enter the hex addr to pass to findnm: "); - scanf("%I64X", &addr); - nm = (nmethod*)findnm(addr); - tty->print("findnm(0x%I64X) returned 0x%I64X\n", addr, nm); - break; - case CMDID_PP: - tty->print("Please enter the hex addr to pass to pp: "); - scanf("%I64X", &addr); - pp((void*)addr); - break; - case CMDID_EXIT: - exit(0); - case CMDID_HELP: - tty->print("Here are the supported commands: "); - for ( j=0; ; j++ ) { - if ( CommandList[j].code == CMDID_ILLEGAL ) - break; - tty->print_cr(" %s -- %s\n", CommandList[j].name, - CommandList[j].description ); - } - break; - case CMDID_QUIT: - return; - break; - case CMDID_BPT: - BREAKPOINT; - break; - case CMDID_VERIFY: - verify();; - break; - case CMDID_THREADS: - threads();; - break; - case CMDID_HSFIND: - tty->print("Please enter the hex addr to pass to hsfind: "); - scanf("%I64X", &addr); - tty->print("Calling hsfind(0x%I64X)\n", addr); - hsfind(addr); - break; - default: - case CMDID_ILLEGAL: - break; - } - } - } - } - } -} -#endif - #endif // !PRODUCT diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/utilities/hashtable.cpp --- a/hotspot/src/share/vm/utilities/hashtable.cpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/utilities/hashtable.cpp Wed Jun 05 00:37:11 2013 -0700 @@ -33,6 +33,7 @@ #include "utilities/dtrace.hpp" #include "utilities/hashtable.hpp" #include "utilities/hashtable.inline.hpp" +#include "utilities/numberSeq.hpp" // This is a generic hashtable, designed to be used for the symbol @@ -237,6 +238,57 @@ } } +template int Hashtable::literal_size(Symbol *symbol) { + return symbol->size() * HeapWordSize; +} + +template int Hashtable::literal_size(oop oop) { + // NOTE: this would over-count if (pre-JDK8) java_lang_Class::has_offset_field() is true, + // and the String.value array is shared by several Strings. However, starting from JDK8, + // the String.value array is not shared anymore. + assert(oop != NULL && oop->klass() == SystemDictionary::String_klass(), "only strings are supported"); + return (oop->size() + java_lang_String::value(oop)->size()) * HeapWordSize; +} + +// Dump footprint and bucket length statistics +// +// Note: if you create a new subclass of Hashtable, you will need to +// add a new function Hashtable::literal_size(MyNewType lit) + +template void Hashtable::dump_table(outputStream* st, const char *table_name) { + NumberSeq summary; + int literal_bytes = 0; + for (int i = 0; i < this->table_size(); ++i) { + int count = 0; + for (HashtableEntry* e = bucket(i); + e != NULL; e = e->next()) { + count++; + literal_bytes += literal_size(e->literal()); + } + summary.add((double)count); + } + double num_buckets = summary.num(); + double num_entries = summary.sum(); + + int bucket_bytes = (int)num_buckets * sizeof(bucket(0)); + int entry_bytes = (int)num_entries * sizeof(HashtableEntry); + int total_bytes = literal_bytes + bucket_bytes + entry_bytes; + + double bucket_avg = (num_buckets <= 0) ? 0 : (bucket_bytes / num_buckets); + double entry_avg = (num_entries <= 0) ? 0 : (entry_bytes / num_entries); + double literal_avg = (num_entries <= 0) ? 0 : (literal_bytes / num_entries); + + st->print_cr("%s statistics:", table_name); + st->print_cr("Number of buckets : %9d = %9d bytes, avg %7.3f", (int)num_buckets, bucket_bytes, bucket_avg); + st->print_cr("Number of entries : %9d = %9d bytes, avg %7.3f", (int)num_entries, entry_bytes, entry_avg); + st->print_cr("Number of literals : %9d = %9d bytes, avg %7.3f", (int)num_entries, literal_bytes, literal_avg); + st->print_cr("Total footprint : %9s = %9d bytes", "", total_bytes); + st->print_cr("Average bucket size : %9.3f", summary.avg()); + st->print_cr("Variance of bucket size : %9.3f", summary.variance()); + st->print_cr("Std. dev. of bucket size: %9.3f", summary.sd()); + st->print_cr("Maximum bucket size : %9d", (int)summary.maximum()); +} + // Dump the hash table buckets. diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/src/share/vm/utilities/hashtable.hpp --- a/hotspot/src/share/vm/utilities/hashtable.hpp Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/src/share/vm/utilities/hashtable.hpp Wed Jun 05 00:37:11 2013 -0700 @@ -282,6 +282,19 @@ static bool use_alternate_hashcode() { return _seed != 0; } static jint seed() { return _seed; } + static int literal_size(Symbol *symbol); + static int literal_size(oop oop); + + // The following two are currently not used, but are needed anyway because some + // C++ compilers (MacOS and Solaris) force the instantiation of + // Hashtable::dump_table() even though we never call this function + // in the VM code. + static int literal_size(ConstantPool *cp) {Unimplemented(); return 0;} + static int literal_size(Klass *k) {Unimplemented(); return 0;} + +public: + void dump_table(outputStream* st, const char *table_name); + private: static jint _seed; }; diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/test/compiler/8010927/Test8010927.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hotspot/test/compiler/8010927/Test8010927.java Wed Jun 05 00:37:11 2013 -0700 @@ -0,0 +1,153 @@ +/* + * Copyright (c) 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. + */ + +/* + * @test + * @bug 8010927 + * @summary Kitchensink crashed with SIGSEGV, Problematic frame: v ~StubRoutines::checkcast_arraycopy + * @library /testlibrary/whitebox /testlibrary + * @build Test8010927 + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. -Xmx64m -XX:NewSize=20971520 -XX:MaxNewSize=32m -XX:-UseTLAB -XX:-UseParNewGC -XX:-UseAdaptiveSizePolicy Test8010927 + */ + +import sun.hotspot.WhiteBox; +import java.lang.reflect.Field; +import sun.misc.Unsafe; + +/** + * The test creates uncommitted space between oldgen and young gen + * by specifying MaxNewSize bigger than NewSize. + * NewSize = 20971520 = (512*4K) * 10 for 4k pages + * Then it tries to execute arraycopy() with elements type check + * to the array at the end of survive space near unused space. + */ + +public class Test8010927 { + + private static final Unsafe U; + + static { + try { + Field unsafe = Unsafe.class.getDeclaredField("theUnsafe"); + unsafe.setAccessible(true); + U = (Unsafe) unsafe.get(null); + } catch (Exception e) { + throw new Error(e); + } + } + + public static Object[] o; + + public static final boolean debug = Boolean.getBoolean("debug"); + + // 2 different obect arrays but same element types + static Test8010927[] masterA; + static Object[] masterB; + static final Test8010927 elem = new Test8010927(); + static final WhiteBox wb = WhiteBox.getWhiteBox(); + + static final int obj_header_size = U.ARRAY_OBJECT_BASE_OFFSET; + static final int heap_oop_size = wb.getHeapOopSize(); + static final int card_size = 512; + static final int one_card = (card_size - obj_header_size)/heap_oop_size; + + static final int surv_size = 2112 * 1024; + + // The size is big to not fit into survive space. + static final Object[] cache = new Object[(surv_size / card_size)]; + + public static void main(String[] args) { + masterA = new Test8010927[one_card]; + masterB = new Object[one_card]; + for (int i = 0; i < one_card; ++i) { + masterA[i] = elem; + masterB[i] = elem; + } + + // Move cache[] to the old gen. + long low_limit = wb.getObjectAddress(cache); + System.gc(); + // Move 'cache' to oldgen. + long upper_limit = wb.getObjectAddress(cache); + if ((low_limit - upper_limit) > 0) { // substaction works with unsigned values + // OldGen is placed before youngger for ParallelOldGC. + upper_limit = low_limit + 21000000l; // +20971520 + } + // Each A[one_card] size is 512 bytes, + // it will take about 40000 allocations to trigger GC. + // cache[] has 8192 elements so GC should happen + // each 5th iteration. + for(long l = 0; l < 20; l++) { + fill_heap(); + if (debug) { + System.out.println("test oop_disjoint_arraycopy"); + } + testA_arraycopy(); + if (debug) { + System.out.println("test checkcast_arraycopy"); + } + testB_arraycopy(); + // Execute arraycopy to the topmost array in young gen + if (debug) { + int top_index = get_top_address(low_limit, upper_limit); + if (top_index >= 0) { + long addr = wb.getObjectAddress(cache[top_index]); + System.out.println("top_addr: 0x" + Long.toHexString(addr) + ", 0x" + Long.toHexString(addr + 512)); + } + } + } + } + static void fill_heap() { + for (int i = 0; i < cache.length; ++i) { + o = new Test8010927[one_card]; + System.arraycopy(masterA, 0, o, 0, masterA.length); + cache[i] = o; + } + for (long j = 0; j < 256; ++j) { + o = new Long[10000]; // to trigger GC + } + } + static void testA_arraycopy() { + for (int i = 0; i < cache.length; ++i) { + System.arraycopy(masterA, 0, cache[i], 0, masterA.length); + } + } + static void testB_arraycopy() { + for (int i = 0; i < cache.length; ++i) { + System.arraycopy(masterB, 0, cache[i], 0, masterB.length); + } + } + static int get_top_address(long min, long max) { + int index = -1; + long addr = min; + for (int i = 0; i < cache.length; ++i) { + long test = wb.getObjectAddress(cache[i]); + if (((test - addr) > 0) && ((max - test) > 0)) { // substaction works with unsigned values + addr = test; + index = i; + } + } + return index; + } +} diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/test/runtime/7158804/Test7158804.sh --- a/hotspot/test/runtime/7158804/Test7158804.sh Mon Jun 03 16:37:13 2013 +0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# - -## -## @test Test7158804.sh -## @bug 7158804 -## @summary Improve config file parsing -## @run shell Test7158804.sh -## -if [ "${TESTSRC}" = "" ] -then - TESTSRC=${PWD} - echo "TESTSRC not set. Using "${TESTSRC}" as default" -fi -echo "TESTSRC=${TESTSRC}" -## Adding common setup Variables for running shell tests. -. ${TESTSRC}/../../test_env.sh - -rm -f .hotspotrc -echo -XX:+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >.hotspotrc -${TESTJAVA}/bin/java ${TESTVMOPTS} -XX:+IgnoreUnrecognizedVMOptions -XX:Flags=.hotspotrc -version -if [ $? -ne 0 ] -then - echo "Test Failed" - exit 1 -fi -rm -f .hotspotrc -exit 0 diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/test/runtime/8003985/Test8003985.java --- a/hotspot/test/runtime/8003985/Test8003985.java Mon Jun 03 16:37:13 2013 +0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,302 +0,0 @@ -/* - * Copyright (c) 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. - */ - -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.lang.Class; -import java.lang.String; -import java.lang.System; -import java.lang.management.ManagementFactory; -import java.lang.management.RuntimeMXBean; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CyclicBarrier; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import sun.misc.Unsafe; -import sun.misc.Contended; - -/* - * @test - * @bug 8003985 - * @summary Support Contended Annotation - JEP 142 - * - * @run main/othervm -XX:-RestrictContended Test8003985 - */ -public class Test8003985 { - - private static final Unsafe U; - private static int ADDRESS_SIZE; - private static int HEADER_SIZE; - - static { - // steal Unsafe - try { - Field unsafe = Unsafe.class.getDeclaredField("theUnsafe"); - unsafe.setAccessible(true); - U = (Unsafe) unsafe.get(null); - } catch (NoSuchFieldException | IllegalAccessException e) { - throw new IllegalStateException(e); - } - - // When running with CompressedOops on 64-bit platform, the address size - // reported by Unsafe is still 8, while the real reference fields are 4 bytes long. - // Try to guess the reference field size with this naive trick. - try { - long off1 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj1")); - long off2 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj2")); - ADDRESS_SIZE = (int) Math.abs(off2 - off1); - HEADER_SIZE = (int) Math.min(off1, off2); - } catch (NoSuchFieldException e) { - ADDRESS_SIZE = -1; - } - } - - static class CompressedOopsClass { - public Object obj1; - public Object obj2; - } - - public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception { - Field f1 = klass.getDeclaredField(field1); - Field f2 = klass.getDeclaredField(field2); - - if (isStatic(f1) != isStatic(f2)) { - return true; // these guys are in naturally disjoint locations - } - - int diff = offset(f1) - offset(f2); - if (diff < 0) { - // f1 is first - return (offset(f2) - (offset(f1) + getSize(f1))) > 64; - } else { - // f2 is first - return (offset(f1) - (offset(f2) + getSize(f2))) > 64; - } - } - - public static boolean isPadded(Class klass, String field1) throws Exception { - Field f1 = klass.getDeclaredField(field1); - - if (isStatic(f1)) { - return offset(f1) > 128 + 64; - } - - return offset(f1) > 64; - } - - public static boolean sameLayout(Class klass1, Class klass2) throws Exception { - for (Field f1 : klass1.getDeclaredFields()) { - Field f2 = klass2.getDeclaredField(f1.getName()); - if (offset(f1) != offset(f2)) { - return false; - } - } - - for (Field f2 : klass1.getDeclaredFields()) { - Field f1 = klass2.getDeclaredField(f2.getName()); - if (offset(f1) != offset(f2)) { - return false; - } - } - - return true; - } - - public static boolean isStatic(Field field) { - return Modifier.isStatic(field.getModifiers()); - } - - public static int offset(Field field) { - if (isStatic(field)) { - return (int) U.staticFieldOffset(field); - } else { - return (int) U.objectFieldOffset(field); - } - } - - public static int getSize(Field field) { - Class type = field.getType(); - if (type == byte.class) { return 1; } - if (type == boolean.class) { return 1; } - if (type == short.class) { return 2; } - if (type == char.class) { return 2; } - if (type == int.class) { return 4; } - if (type == float.class) { return 4; } - if (type == long.class) { return 8; } - if (type == double.class) { return 8; } - return ADDRESS_SIZE; - } - - public static void main(String[] args) throws Exception { - boolean endResult = true; - - // --------------- INSTANCE FIELDS --------------------- - - if (arePaddedPairwise(Test1.class, "int1", "int2") || - isPadded(Test1.class, "int1") || - isPadded(Test1.class, "int2")) { - System.err.println("Test1 failed"); - endResult &= false; - } - - if (!arePaddedPairwise(Test2.class, "int1", "int2") || - !isPadded(Test2.class, "int1") || - isPadded(Test2.class, "int2")) { - System.err.println("Test2 failed"); - endResult &= false; - } - - if (!arePaddedPairwise(Test3.class, "int1", "int2") || - !isPadded(Test3.class, "int1") || - !isPadded(Test3.class, "int2")) { - System.err.println("Test3 failed"); - endResult &= false; - } - - if (arePaddedPairwise(Test4.class, "int1", "int2") || - !isPadded(Test4.class, "int1") || - !isPadded(Test4.class, "int2")) { - System.err.println("Test4 failed"); - endResult &= false; - } - - if (!arePaddedPairwise(Test5.class, "int1", "int2") || - !isPadded(Test5.class, "int1") || - !isPadded(Test5.class, "int2")) { - System.err.println("Test5 failed"); - endResult &= false; - } - - if (!arePaddedPairwise(Test6.class, "int1", "int2") || - !isPadded(Test6.class, "int1") || - !isPadded(Test6.class, "int2")) { - System.err.println("Test6 failed"); - endResult &= false; - } - - if (arePaddedPairwise(Test7.class, "int1", "int2") || - !isPadded(Test7.class, "int1") || - !isPadded(Test7.class, "int2")) { - System.err.println("Test7 failed"); - endResult &= false; - } - - if (!arePaddedPairwise(Test8.class, "int1", "int2") || - !isPadded(Test8.class, "int1") || - !isPadded(Test8.class, "int2")) { - System.err.println("Test8 failed"); - endResult &= false; - } - - if (!arePaddedPairwise(Test9.class, "int1", "int2") || - !isPadded(Test9.class, "int1") || - !isPadded(Test9.class, "int2")) { - System.err.println("Test9 failed"); - endResult &= false; - } - - if (!sameLayout(Test4.class, Test7.class)) { - System.err.println("Test4 and Test7 have different layouts"); - endResult &= false; - } - - if (!sameLayout(Test5.class, Test6.class)) { - System.err.println("Test5 and Test6 have different layouts"); - endResult &= false; - } - - if (!sameLayout(Test8.class, Test9.class)) { - System.err.println("Test8 and Test9 have different layouts"); - endResult &= false; - } - - System.out.println(endResult ? "Test PASSES" : "Test FAILS"); - if (!endResult) { - throw new Error("Test failed"); - } - } - - // ----------------------------------- INSTANCE FIELDS ----------------------------------------- - - // naturally packed - public static class Test1 { - private int int1; - private int int2; - } - - // int1 is padded - public static class Test2 { - @Contended private int int1; - private int int2; - } - - // both fields are padded - public static class Test3 { - @Contended private int int1; - @Contended private int int2; - } - - // fields are padded in the singular group - public static class Test4 { - @Contended("sameGroup") private int int1; - @Contended("sameGroup") private int int2; - } - - // fields are padded in disjoint groups - public static class Test5 { - @Contended("diffGroup1") private int int1; - @Contended("diffGroup2") private int int2; - } - - // fields are padded in disjoint groups - public static class Test6 { - @Contended private int int1; - @Contended("diffGroup2") private int int2; - } - - // fields are padded in the singular group - @Contended - public static class Test7 { - private int int1; - private int int2; - } - - // all fields are padded as the group, and one field is padded specifically - @Contended - public static class Test8 { - @Contended private int int1; - private int int2; - } - - // all fields are padded as the group, and one field is padded specifically - @Contended - public static class Test9 { - @Contended("group") private int int1; - private int int2; - } - -} - diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/test/runtime/CommandLine/ConfigFileParsing.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hotspot/test/runtime/CommandLine/ConfigFileParsing.java Wed Jun 05 00:37:11 2013 -0700 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 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. + */ + +/* + * @test ConfigFileParsing + * @bug 7158804 + * @summary Improve config file parsing + * @library /testlibrary + */ + +import java.io.PrintWriter; +import com.oracle.java.testlibrary.*; + +public class ConfigFileParsing { + public static void main(String[] args) throws Exception { + String testFileName = ".hotspotrc"; + + // Create really long invalid option + String reallyLongInvalidOption = ""; + for (int i=0; i<5000; i++) + reallyLongInvalidOption+='a'; + + // Populate the options file with really long string + PrintWriter pw = new PrintWriter(testFileName); + pw.println("-XX:+" + reallyLongInvalidOption); + pw.close(); + + // start VM + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-XX:+IgnoreUnrecognizedVMOptions", "-XX:Flags=.hotspotrc", "-version"); + + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(0); + } +} diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/test/runtime/RedefineObject/TestRedefineObject.java --- a/hotspot/test/runtime/RedefineObject/TestRedefineObject.java Mon Jun 03 16:37:13 2013 +0400 +++ b/hotspot/test/runtime/RedefineObject/TestRedefineObject.java Wed Jun 05 00:37:11 2013 -0700 @@ -32,10 +32,10 @@ * @library /testlibrary * @build Agent * @run main ClassFileInstaller Agent - * @run main Test + * @run main TestRedefineObject * @run main/othervm -javaagent:agent.jar Agent */ -public class Test { +public class TestRedefineObject { public static void main(String[] args) throws Exception { PrintWriter pw = new PrintWriter("MANIFEST.MF"); diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/test/runtime/contended/Basic.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hotspot/test/runtime/contended/Basic.java Wed Jun 05 00:37:11 2013 -0700 @@ -0,0 +1,302 @@ +/* + * Copyright (c) 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. + */ + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.lang.Class; +import java.lang.String; +import java.lang.System; +import java.lang.management.ManagementFactory; +import java.lang.management.RuntimeMXBean; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CyclicBarrier; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import sun.misc.Unsafe; +import sun.misc.Contended; + +/* + * @test + * @bug 8003985 + * @summary Support Contended Annotation - JEP 142 + * + * @run main/othervm -XX:-RestrictContended Basic + */ +public class Basic { + + private static final Unsafe U; + private static int ADDRESS_SIZE; + private static int HEADER_SIZE; + + static { + // steal Unsafe + try { + Field unsafe = Unsafe.class.getDeclaredField("theUnsafe"); + unsafe.setAccessible(true); + U = (Unsafe) unsafe.get(null); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new IllegalStateException(e); + } + + // When running with CompressedOops on 64-bit platform, the address size + // reported by Unsafe is still 8, while the real reference fields are 4 bytes long. + // Try to guess the reference field size with this naive trick. + try { + long off1 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj1")); + long off2 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj2")); + ADDRESS_SIZE = (int) Math.abs(off2 - off1); + HEADER_SIZE = (int) Math.min(off1, off2); + } catch (NoSuchFieldException e) { + ADDRESS_SIZE = -1; + } + } + + static class CompressedOopsClass { + public Object obj1; + public Object obj2; + } + + public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception { + Field f1 = klass.getDeclaredField(field1); + Field f2 = klass.getDeclaredField(field2); + + if (isStatic(f1) != isStatic(f2)) { + return true; // these guys are in naturally disjoint locations + } + + int diff = offset(f1) - offset(f2); + if (diff < 0) { + // f1 is first + return (offset(f2) - (offset(f1) + getSize(f1))) > 64; + } else { + // f2 is first + return (offset(f1) - (offset(f2) + getSize(f2))) > 64; + } + } + + public static boolean isPadded(Class klass, String field1) throws Exception { + Field f1 = klass.getDeclaredField(field1); + + if (isStatic(f1)) { + return offset(f1) > 128 + 64; + } + + return offset(f1) > 64; + } + + public static boolean sameLayout(Class klass1, Class klass2) throws Exception { + for (Field f1 : klass1.getDeclaredFields()) { + Field f2 = klass2.getDeclaredField(f1.getName()); + if (offset(f1) != offset(f2)) { + return false; + } + } + + for (Field f2 : klass1.getDeclaredFields()) { + Field f1 = klass2.getDeclaredField(f2.getName()); + if (offset(f1) != offset(f2)) { + return false; + } + } + + return true; + } + + public static boolean isStatic(Field field) { + return Modifier.isStatic(field.getModifiers()); + } + + public static int offset(Field field) { + if (isStatic(field)) { + return (int) U.staticFieldOffset(field); + } else { + return (int) U.objectFieldOffset(field); + } + } + + public static int getSize(Field field) { + Class type = field.getType(); + if (type == byte.class) { return 1; } + if (type == boolean.class) { return 1; } + if (type == short.class) { return 2; } + if (type == char.class) { return 2; } + if (type == int.class) { return 4; } + if (type == float.class) { return 4; } + if (type == long.class) { return 8; } + if (type == double.class) { return 8; } + return ADDRESS_SIZE; + } + + public static void main(String[] args) throws Exception { + boolean endResult = true; + + // --------------- INSTANCE FIELDS --------------------- + + if (arePaddedPairwise(Test1.class, "int1", "int2") || + isPadded(Test1.class, "int1") || + isPadded(Test1.class, "int2")) { + System.err.println("Test1 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(Test2.class, "int1", "int2") || + !isPadded(Test2.class, "int1") || + isPadded(Test2.class, "int2")) { + System.err.println("Test2 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(Test3.class, "int1", "int2") || + !isPadded(Test3.class, "int1") || + !isPadded(Test3.class, "int2")) { + System.err.println("Test3 failed"); + endResult &= false; + } + + if (arePaddedPairwise(Test4.class, "int1", "int2") || + !isPadded(Test4.class, "int1") || + !isPadded(Test4.class, "int2")) { + System.err.println("Test4 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(Test5.class, "int1", "int2") || + !isPadded(Test5.class, "int1") || + !isPadded(Test5.class, "int2")) { + System.err.println("Test5 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(Test6.class, "int1", "int2") || + !isPadded(Test6.class, "int1") || + !isPadded(Test6.class, "int2")) { + System.err.println("Test6 failed"); + endResult &= false; + } + + if (arePaddedPairwise(Test7.class, "int1", "int2") || + !isPadded(Test7.class, "int1") || + !isPadded(Test7.class, "int2")) { + System.err.println("Test7 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(Test8.class, "int1", "int2") || + !isPadded(Test8.class, "int1") || + !isPadded(Test8.class, "int2")) { + System.err.println("Test8 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(Test9.class, "int1", "int2") || + !isPadded(Test9.class, "int1") || + !isPadded(Test9.class, "int2")) { + System.err.println("Test9 failed"); + endResult &= false; + } + + if (!sameLayout(Test4.class, Test7.class)) { + System.err.println("Test4 and Test7 have different layouts"); + endResult &= false; + } + + if (!sameLayout(Test5.class, Test6.class)) { + System.err.println("Test5 and Test6 have different layouts"); + endResult &= false; + } + + if (!sameLayout(Test8.class, Test9.class)) { + System.err.println("Test8 and Test9 have different layouts"); + endResult &= false; + } + + System.out.println(endResult ? "Test PASSES" : "Test FAILS"); + if (!endResult) { + throw new Error("Test failed"); + } + } + + // ----------------------------------- INSTANCE FIELDS ----------------------------------------- + + // naturally packed + public static class Test1 { + private int int1; + private int int2; + } + + // int1 is padded + public static class Test2 { + @Contended private int int1; + private int int2; + } + + // both fields are padded + public static class Test3 { + @Contended private int int1; + @Contended private int int2; + } + + // fields are padded in the singular group + public static class Test4 { + @Contended("sameGroup") private int int1; + @Contended("sameGroup") private int int2; + } + + // fields are padded in disjoint groups + public static class Test5 { + @Contended("diffGroup1") private int int1; + @Contended("diffGroup2") private int int2; + } + + // fields are padded in disjoint groups + public static class Test6 { + @Contended private int int1; + @Contended("diffGroup2") private int int2; + } + + // fields are padded in the singular group + @Contended + public static class Test7 { + private int int1; + private int int2; + } + + // all fields are padded as the group, and one field is padded specifically + @Contended + public static class Test8 { + @Contended private int int1; + private int int2; + } + + // all fields are padded as the group, and one field is padded specifically + @Contended + public static class Test9 { + @Contended("group") private int int1; + private int int2; + } + +} + diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/test/runtime/contended/DefaultValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hotspot/test/runtime/contended/DefaultValue.java Wed Jun 05 00:37:11 2013 -0700 @@ -0,0 +1,185 @@ +/* + * Copyright (c) 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. + */ + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.lang.Class; +import java.lang.String; +import java.lang.System; +import java.lang.management.ManagementFactory; +import java.lang.management.RuntimeMXBean; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CyclicBarrier; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import sun.misc.Unsafe; +import sun.misc.Contended; + +/* + * @test + * @bug 8014509 + * @summary \@Contended: explicit default value behaves differently from the implicit value + * + * @run main/othervm -XX:-RestrictContended DefaultValue + */ +public class DefaultValue { + + private static final Unsafe U; + private static int ADDRESS_SIZE; + private static int HEADER_SIZE; + + static { + // steal Unsafe + try { + Field unsafe = Unsafe.class.getDeclaredField("theUnsafe"); + unsafe.setAccessible(true); + U = (Unsafe) unsafe.get(null); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new IllegalStateException(e); + } + + // When running with CompressedOops on 64-bit platform, the address size + // reported by Unsafe is still 8, while the real reference fields are 4 bytes long. + // Try to guess the reference field size with this naive trick. + try { + long off1 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj1")); + long off2 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj2")); + ADDRESS_SIZE = (int) Math.abs(off2 - off1); + HEADER_SIZE = (int) Math.min(off1, off2); + } catch (NoSuchFieldException e) { + ADDRESS_SIZE = -1; + } + } + + static class CompressedOopsClass { + public Object obj1; + public Object obj2; + } + + public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception { + Field f1 = klass.getField(field1); + Field f2 = klass.getField(field2); + + int diff = offset(f1) - offset(f2); + if (diff < 0) { + // f1 is first + return (offset(f2) - (offset(f1) + getSize(f1))) > 64; + } else { + // f2 is first + return (offset(f1) - (offset(f2) + getSize(f2))) > 64; + } + } + + public static boolean sameLayout(Class klass1, Class klass2) throws Exception { + for (Field f1 : klass1.getDeclaredFields()) { + Field f2 = klass2.getDeclaredField(f1.getName()); + if (offset(f1) != offset(f2)) { + return false; + } + } + + for (Field f2 : klass1.getDeclaredFields()) { + Field f1 = klass2.getDeclaredField(f2.getName()); + if (offset(f1) != offset(f2)) { + return false; + } + } + + return true; + } + + public static boolean isStatic(Field field) { + return Modifier.isStatic(field.getModifiers()); + } + + public static int offset(Field field) { + if (isStatic(field)) { + return (int) U.staticFieldOffset(field); + } else { + return (int) U.objectFieldOffset(field); + } + } + + public static int getSize(Field field) { + Class type = field.getType(); + if (type == byte.class) { return 1; } + if (type == boolean.class) { return 1; } + if (type == short.class) { return 2; } + if (type == char.class) { return 2; } + if (type == int.class) { return 4; } + if (type == float.class) { return 4; } + if (type == long.class) { return 8; } + if (type == double.class) { return 8; } + return ADDRESS_SIZE; + } + + public static void main(String[] args) throws Exception { + boolean endResult = true; + + if (!arePaddedPairwise(R1.class, "int1", "int2")) { + System.err.println("R1 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(R2.class, "int1", "int2")) { + System.err.println("R2 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(R3.class, "int1", "int2")) { + System.err.println("R3 failed"); + endResult &= false; + } + + System.out.println(endResult ? "Test PASSES" : "Test FAILS"); + if (!endResult) { + throw new Error("Test failed"); + } + } + + public static class R1 { + @Contended + public int int1; + @Contended + public int int2; + } + + public static class R2 { + @Contended("") + public int int1; + @Contended("") + public int int2; + } + + public static class R3 { + @Contended() + public int int1; + @Contended() + public int int2; + } + +} + diff -r 14a0ae3ca973 -r 1bbdae29327c hotspot/test/runtime/contended/Inheritance1.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hotspot/test/runtime/contended/Inheritance1.java Wed Jun 05 00:37:11 2013 -0700 @@ -0,0 +1,248 @@ +/* + * Copyright (c) 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. + */ + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.lang.Class; +import java.lang.String; +import java.lang.System; +import java.lang.management.ManagementFactory; +import java.lang.management.RuntimeMXBean; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CyclicBarrier; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import sun.misc.Unsafe; +import sun.misc.Contended; + +/* + * @test + * @bug 8012939 + * @summary \@Contended doesn't work correctly with inheritance + * + * @run main/othervm -XX:-RestrictContended Inheritance1 + */ +public class Inheritance1 { + + private static final Unsafe U; + private static int ADDRESS_SIZE; + private static int HEADER_SIZE; + + static { + // steal Unsafe + try { + Field unsafe = Unsafe.class.getDeclaredField("theUnsafe"); + unsafe.setAccessible(true); + U = (Unsafe) unsafe.get(null); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new IllegalStateException(e); + } + + // When running with CompressedOops on 64-bit platform, the address size + // reported by Unsafe is still 8, while the real reference fields are 4 bytes long. + // Try to guess the reference field size with this naive trick. + try { + long off1 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj1")); + long off2 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj2")); + ADDRESS_SIZE = (int) Math.abs(off2 - off1); + HEADER_SIZE = (int) Math.min(off1, off2); + } catch (NoSuchFieldException e) { + ADDRESS_SIZE = -1; + } + } + + static class CompressedOopsClass { + public Object obj1; + public Object obj2; + } + + public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception { + Field f1 = klass.getField(field1); + Field f2 = klass.getField(field2); + + int diff = offset(f1) - offset(f2); + if (diff < 0) { + // f1 is first + return (offset(f2) - (offset(f1) + getSize(f1))) > 64; + } else { + // f2 is first + return (offset(f1) - (offset(f2) + getSize(f2))) > 64; + } + } + + public static boolean sameLayout(Class klass1, Class klass2) throws Exception { + for (Field f1 : klass1.getDeclaredFields()) { + Field f2 = klass2.getDeclaredField(f1.getName()); + if (offset(f1) != offset(f2)) { + return false; + } + } + + for (Field f2 : klass1.getDeclaredFields()) { + Field f1 = klass2.getDeclaredField(f2.getName()); + if (offset(f1) != offset(f2)) { + return false; + } + } + + return true; + } + + public static boolean isStatic(Field field) { + return Modifier.isStatic(field.getModifiers()); + } + + public static int offset(Field field) { + if (isStatic(field)) { + return (int) U.staticFieldOffset(field); + } else { + return (int) U.objectFieldOffset(field); + } + } + + public static int getSize(Field field) { + Class type = field.getType(); + if (type == byte.class) { return 1; } + if (type == boolean.class) { return 1; } + if (type == short.class) { return 2; } + if (type == char.class) { return 2; } + if (type == int.class) { return 4; } + if (type == float.class) { return 4; } + if (type == long.class) { return 8; } + if (type == double.class) { return 8; } + return ADDRESS_SIZE; + } + + public static void main(String[] args) throws Exception { + boolean endResult = true; + + // --------------- INSTANCE FIELDS --------------------- + + if (!arePaddedPairwise(A2_R1.class, "int1", "int2")) { + System.err.println("A2_R1 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(A3_R1.class, "int1", "int2")) { + System.err.println("A3_R1 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(A1_R2.class, "int1", "int2")) { + System.err.println("A1_R2 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(A2_R2.class, "int1", "int2")) { + System.err.println("A2_R2 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(A3_R2.class, "int1", "int2")) { + System.err.println("A3_R2 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(A1_R3.class, "int1", "int2")) { + System.err.println("A1_R3 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(A2_R3.class, "int1", "int2")) { + System.err.println("A2_R3 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(A3_R3.class, "int1", "int2")) { + System.err.println("A3_R3 failed"); + endResult &= false; + } + + System.out.println(endResult ? "Test PASSES" : "Test FAILS"); + if (!endResult) { + throw new Error("Test failed"); + } + } + + public static class R1 { + public int int1; + } + + public static class R2 { + @Contended + public int int1; + } + + @Contended + public static class R3 { + public int int1; + } + + public static class A1_R1 extends R1 { + public int int2; + } + + public static class A2_R1 extends R1 { + @Contended + public int int2; + } + + @Contended + public static class A3_R1 extends R1 { + public int int2; + } + + public static class A1_R2 extends R2 { + public int int2; + } + + public static class A2_R2 extends R2 { + @Contended + public int int2; + } + + @Contended + public static class A3_R2 extends R2 { + public int int2; + } + + public static class A1_R3 extends R3 { + public int int2; + } + + public static class A2_R3 extends R3 { + @Contended + public int int2; + } + + @Contended + public static class A3_R3 extends R3 { + public int int2; + } + + +} + diff -r 14a0ae3ca973 -r 1bbdae29327c jaxp/.hgtags --- a/jaxp/.hgtags Mon Jun 03 16:37:13 2013 +0400 +++ b/jaxp/.hgtags Wed Jun 05 00:37:11 2013 -0700 @@ -212,3 +212,4 @@ 7122f7bb0fcc8a39e5254402119b2ee3fa0ad313 jdk8-b88 893d2ba8bbea3a8d090e51d8eaea285b390789ea jdk8-b89 668acc0e1034bc1bec6d02be92e0dd4a63d0667e jdk8-b90 +e3065fb07877c7e96e8b93416fe2ab9a4c9eb2a5 jdk8-b91 diff -r 14a0ae3ca973 -r 1bbdae29327c jaxp/src/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java --- a/jaxp/src/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java Mon Jun 03 16:37:13 2013 +0400 +++ b/jaxp/src/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java Wed Jun 05 00:37:11 2013 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2006, 2013 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. */ /* diff -r 14a0ae3ca973 -r 1bbdae29327c jaxws/.hgtags --- a/jaxws/.hgtags Mon Jun 03 16:37:13 2013 +0400 +++ b/jaxws/.hgtags Wed Jun 05 00:37:11 2013 -0700 @@ -212,3 +212,4 @@ 24fa5452e5d4e9df8b85196283275a6ca4b4adb4 jdk8-b88 88838e08e4ef6a254867c8126070a1975683108d jdk8-b89 3e5b9ea5ac35ea7096da484e24a863cf4552179f jdk8-b90 +0bb1a9fa56b037d072efdaae5f5b73a0f23c966c jdk8-b91 diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/.hgtags --- a/jdk/.hgtags Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/.hgtags Wed Jun 05 00:37:11 2013 -0700 @@ -212,3 +212,5 @@ 8dbb4b159e04de3c447c9242c70505e71f8624c7 jdk8-b88 845025546e35519fbb8970e79fc2a834063a5e19 jdk8-b89 c63eda8f63008a4398d2c22ac8d72f7fef6f9238 jdk8-b90 +169451cf0cc53bde5af24f9820ea3f35ec4b4df4 jdk8-b91 +a2a2a91075ad85becbe10a39d7fd04ef9bea8df5 jdk8-b92 diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/make/sun/awt/FILES_c_unix.gmk --- a/jdk/make/sun/awt/FILES_c_unix.gmk Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/make/sun/awt/FILES_c_unix.gmk Wed Jun 05 00:37:11 2013 -0700 @@ -171,3 +171,13 @@ GLXSurfaceData.c \ AccelGlyphCache.c \ CUPSfuncs.c + +ifeq ($(PLATFORM), macosx) +FILES_NO_MOTIF_objc = \ + AWTFont.m \ + AWTStrike.m \ + CCharToGlyphMapper.m \ + CGGlyphImages.m \ + CGGlyphOutlines.m \ + CoreTextSupport.m +endif # PLATFORM diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/make/sun/awt/FILES_export_unix.gmk --- a/jdk/make/sun/awt/FILES_export_unix.gmk Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/make/sun/awt/FILES_export_unix.gmk Wed Jun 05 00:37:11 2013 -0700 @@ -187,3 +187,14 @@ java/awt/dnd/DnDConstants.java \ sun/awt/CausedFocusEvent.java +ifeq ($(PLATFORM), macosx) +ifeq ($(HEADLESS), true) +FILES_export += \ + sun/awt/SunHints.java \ + sun/font/CCharToGlyphMapper.java \ + sun/font/CFont.java \ + sun/font/CFontManager.java \ + sun/font/CStrike.java \ + sun/font/CStrikeDisposer.java +endif # HEADLESS +endif # PLATFORM diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/make/sun/awt/mawt.gmk --- a/jdk/make/sun/awt/mawt.gmk Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/make/sun/awt/mawt.gmk Wed Jun 05 00:37:11 2013 -0700 @@ -43,6 +43,10 @@ # compiled based on the motif version. FILES_c = $(FILES_NO_MOTIF_c) +ifeq ($(PLATFORM), macosx) +FILES_objc = $(FILES_NO_MOTIF_objc) +endif # PLATFORM + ifeq ($(PLATFORM), solaris) ifneq ($(ARCH), amd64) FILES_reorder += reorder-$(ARCH) @@ -97,6 +101,10 @@ vpath %.cpp $(SHARE_SRC)/native/$(PKGDIR)/image vpath %.c $(PLATFORM_SRC)/native/$(PKGDIR)/robot_child +ifeq ($(PLATFORM), macosx) +vpath %.m $(call NativeSrcDirList,,native/sun/font) +endif # PLATFORM + # # Libraries to link in. # @@ -192,13 +200,21 @@ $(EVENT_MODEL) ifeq ($(PLATFORM), macosx) -CPPFLAGS += -I$(CUPS_HEADERS_PATH) +CPPFLAGS += -I$(CUPS_HEADERS_PATH) \ + $(call NativeSrcDirList,-I,native/sun/awt) \ + $(call NativeSrcDirList,-I,native/sun/font) ifndef HEADLESS CPPFLAGS += -I$(MOTIF_DIR)/include \ -I$(OPENWIN_HOME)/include LDFLAGS += -L$(MOTIF_LIB) -L$(OPENWIN_LIB) - +else +LDFLAGS += -framework Accelerate \ + -framework ApplicationServices \ + -framework Cocoa \ + -F/System/Library/Frameworks/JavaVM.framework/Frameworks \ + -framework JavaNativeFoundation \ + -framework JavaRuntimeSupport endif # !HEADLESS endif # PLATFORM diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/makefiles/CompileNativeLibraries.gmk --- a/jdk/makefiles/CompileNativeLibraries.gmk Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/makefiles/CompileNativeLibraries.gmk Wed Jun 05 00:37:11 2013 -0700 @@ -2314,6 +2314,10 @@ $(JDK_TOPDIR)/src/solaris/native/sun/java2d/opengl \ $(JDK_TOPDIR)/src/solaris/native/sun/java2d/x11 +ifeq ($(OPENJDK_TARGET_OS),macosx) + LIBAWT_HEADLESS_DIRS+=$(JDK_TOPDIR)/src/macosx/native/sun/font +endif + LIBAWT_HEADLESS_CFLAGS:=-DHEADLESS=true \ -DX11_PATH=\"$(X11_PATH)\" -DPACKAGE_PATH=\"$(PACKAGE_PATH)\" \ $(CUPS_CFLAGS) \ @@ -2328,6 +2332,12 @@ -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/jdga \ $(foreach dir,$(LIBAWT_HEADLESS_DIRS),-I$(dir)) +ifeq ($(OPENJDK_TARGET_OS),macosx) + LIBAWT_HEADLESS_CFLAGS+=\ + -F/System/Library/Frameworks/JavaVM.framework/Frameworks \ + -F/System/Library/Frameworks/ApplicationServices.framework/Frameworks +endif + LIBAWT_HEADLESS_FILES:=\ awt_Font.c \ HeadlessToolkit.c \ @@ -2356,6 +2366,16 @@ AccelGlyphCache.c \ CUPSfuncs.c +ifeq ($(OPENJDK_TARGET_OS),macosx) + LIBAWT_HEADLESS_FILES+=\ + AWTFont.m \ + AWTStrike.m \ + CCharToGlyphMapper.m \ + CGGlyphImages.m \ + CGGlyphOutlines.m \ + CoreTextSupport.m +endif + LIBAWT_HEADLESS_REORDER:= ifeq ($(OPENJDK_TARGET_OS), solaris) ifneq ($(OPENJDK_TARGET_CPU), x86_64) @@ -2382,7 +2402,13 @@ REORDER:=$(LIBAWT_HEADLESS_REORDER), \ LDFLAGS_SUFFIX_linux:=-ljvm -lawt -lm $(LIBDL) -ljava,\ LDFLAGS_SUFFIX_solaris:=$(LIBDL) -ljvm -lawt -lm -ljava $(LIBCXX) -lc,\ - LDFLAGS_SUFFIX_macosx:=-ljvm $(LIBCXX) -lawt $(LIBDL) -ljava,\ + LDFLAGS_SUFFIX_macosx:=-ljvm $(LIBCXX) -lawt $(LIBDL) -ljava \ + -framework Accelerate \ + -framework ApplicationServices \ + -framework Cocoa \ + -F/System/Library/Frameworks/JavaVM.framework/Frameworks \ + -framework JavaNativeFoundation \ + -framework JavaRuntimeSupport,\ OBJECT_DIR:=$(JDK_OUTPUTDIR)/objs/libawt_headless,\ DEBUG_SYMBOLS:=$(DEBUG_ALL_BINARIES))) diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java --- a/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java Wed Jun 05 00:37:11 2013 -0700 @@ -36,6 +36,7 @@ import javax.print.*; import javax.print.attribute.PrintRequestAttributeSet; import javax.print.attribute.HashPrintRequestAttributeSet; +import javax.print.attribute.standard.PageRanges; import sun.java2d.*; import sun.print.*; @@ -173,6 +174,19 @@ if (nsPrintInfo != null) { fNSPrintInfo = nsPrintInfo.getValue(); } + + PageRanges pageRangesAttr = (PageRanges)attributes.get(PageRanges.class); + if (isSupportedValue(pageRangesAttr, attributes)) { + SunPageSelection rangeSelect = (SunPageSelection)attributes.get(SunPageSelection.class); + // If rangeSelect is not null, we are using AWT's print dialog that has + // All, Selection, and Range radio buttons + if (rangeSelect == null || rangeSelect == SunPageSelection.RANGE) { + int[][] range = pageRangesAttr.getMembers(); + // setPageRange will set firstPage and lastPage as called in getFirstPage + // and getLastPage + setPageRange(range[0][0] - 1, range[0][1] - 1); + } + } } volatile boolean onEventThread; @@ -225,7 +239,6 @@ * the end of the document. Note that firstPage * and lastPage are 0 based page indices. */ - int numPages = mDocument.getNumberOfPages(); int firstPage = getFirstPage(); int lastPage = getLastPage(); @@ -242,42 +255,53 @@ userCancelled = false; } - if (EventQueue.isDispatchThread()) { - // This is an AWT EventQueue, and this print rendering loop needs to block it. - - onEventThread = true; + //Add support for PageRange + PageRanges pr = (attributes == null) ? null + : (PageRanges)attributes.get(PageRanges.class); + int[][] prMembers = (pr == null) ? new int[0][0] : pr.getMembers(); + int loopi = 0; + do { + if (EventQueue.isDispatchThread()) { + // This is an AWT EventQueue, and this print rendering loop needs to block it. - printingLoop = AccessController.doPrivileged(new PrivilegedAction() { - @Override - public SecondaryLoop run() { - return Toolkit.getDefaultToolkit() - .getSystemEventQueue() - .createSecondaryLoop(); - } - }); + onEventThread = true; + + printingLoop = AccessController.doPrivileged(new PrivilegedAction() { + @Override + public SecondaryLoop run() { + return Toolkit.getDefaultToolkit() + .getSystemEventQueue() + .createSecondaryLoop(); + } + }); - try { - // Fire off the print rendering loop on the AppKit thread, and don't have - // it wait and block this thread. - if (printLoop(false, firstPage, lastPage)) { - // Start a secondary loop on EDT until printing operation is finished or cancelled - printingLoop.enter(); + try { + // Fire off the print rendering loop on the AppKit thread, and don't have + // it wait and block this thread. + if (printLoop(false, firstPage, lastPage)) { + // Start a secondary loop on EDT until printing operation is finished or cancelled + printingLoop.enter(); + } + } catch (Exception e) { + e.printStackTrace(); } - } catch (Exception e) { - e.printStackTrace(); + } else { + // Fire off the print rendering loop on the AppKit, and block this thread + // until it is done. + // But don't actually block... we need to come back here! + onEventThread = false; + + try { + printLoop(true, firstPage, lastPage); + } catch (Exception e) { + e.printStackTrace(); + } } - } else { - // Fire off the print rendering loop on the AppKit, and block this thread - // until it is done. - // But don't actually block... we need to come back here! - onEventThread = false; - - try { - printLoop(true, firstPage, lastPage); - } catch (Exception e) { - e.printStackTrace(); + if (++loopi < prMembers.length) { + firstPage = prMembers[loopi][0]-1; + lastPage = prMembers[loopi][1] -1; } - } + } while (loopi < prMembers.length); } finally { synchronized (this) { // NOTE: Native code shouldn't allow exceptions out while diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/src/macosx/native/sun/font/AWTFont.m --- a/jdk/src/macosx/native/sun/font/AWTFont.m Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/src/macosx/native/sun/font/AWTFont.m Wed Jun 05 00:37:11 2013 -0700 @@ -395,6 +395,7 @@ #pragma mark --- Miscellaneous JNI --- +#ifndef HEADLESS /* * Class: sun_awt_PlatformFont * Method: initIDs @@ -416,3 +417,4 @@ (JNIEnv *env, jclass cls) { } +#endif diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/src/share/classes/com/sun/jndi/toolkit/ctx/Continuation.java --- a/jdk/src/share/classes/com/sun/jndi/toolkit/ctx/Continuation.java Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/src/share/classes/com/sun/jndi/toolkit/ctx/Continuation.java Wed Jun 05 00:37:11 2013 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -90,14 +90,16 @@ * Constructs a new instance of Continuation. * @param top The name of the object that is to be resolved/operated upon. * This becomes the Continuation's 'starter' and is used to - * calculate the "resolved name" when filling in a NamingException. + * calculate the "resolved name" when filling in a NamingException. * @param environment The environment used by the caller. It is used - * when setting the "environment" of a CannotProceedException. + * when setting the "environment" of a CannotProceedException. */ + @SuppressWarnings("unchecked") // For Hashtable clone: environment.clone() public Continuation(Name top, Hashtable environment) { super(); starter = top; - this.environment = environment; + this.environment = (Hashtable) + ((environment == null) ? null : environment.clone()); } /** diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/src/share/classes/com/sun/jndi/toolkit/dir/LazySearchEnumerationImpl.java --- a/jdk/src/share/classes/com/sun/jndi/toolkit/dir/LazySearchEnumerationImpl.java Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/src/share/classes/com/sun/jndi/toolkit/dir/LazySearchEnumerationImpl.java Wed Jun 05 00:37:11 2013 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -69,6 +69,7 @@ } } + @SuppressWarnings("unchecked") // For Hashtable clone: env.clone() public LazySearchEnumerationImpl(NamingEnumeration candidates, AttrFilter filter, SearchControls cons, Context ctx, Hashtable env, boolean useFactory) @@ -76,7 +77,8 @@ this.candidates = candidates; this.filter = filter; - this.env = env; + this.env = (Hashtable) + ((env == null) ? null : env.clone()); this.context = ctx; this.useFactory = useFactory; diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/src/share/classes/com/sun/jndi/toolkit/url/GenericURLContext.java --- a/jdk/src/share/classes/com/sun/jndi/toolkit/url/GenericURLContext.java Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/src/share/classes/com/sun/jndi/toolkit/url/GenericURLContext.java Wed Jun 05 00:37:11 2013 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -53,7 +53,8 @@ @SuppressWarnings("unchecked") // Expect Hashtable public GenericURLContext(Hashtable env) { // context that is not tied to any specific URL - myEnv = (Hashtable)env; // copied on write + myEnv = + (Hashtable)(env == null ? null : env.clone()); } public void close() throws NamingException { @@ -488,22 +489,19 @@ return result; } - @SuppressWarnings("unchecked") // clone() public Object removeFromEnvironment(String propName) throws NamingException { if (myEnv == null) { return null; } - myEnv = (Hashtable)myEnv.clone(); return myEnv.remove(propName); } - @SuppressWarnings("unchecked") // clone() public Object addToEnvironment(String propName, Object propVal) throws NamingException { - myEnv = (myEnv == null) - ? new Hashtable(11, 0.75f) - : (Hashtable)myEnv.clone(); + if (myEnv == null) { + myEnv = new Hashtable(11, 0.75f); + } return myEnv.put(propName, propVal); } diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/src/share/classes/java/io/FileInputStream.java --- a/jdk/src/share/classes/java/io/FileInputStream.java Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/src/share/classes/java/io/FileInputStream.java Wed Jun 05 00:37:11 2013 -0700 @@ -240,13 +240,15 @@ * *

The skip method may, for a variety of * reasons, end up skipping over some smaller number of bytes, - * possibly 0. If n is negative, an - * IOException is thrown, even though the skip - * method of the {@link InputStream} superclass does nothing in this case. - * The actual number of bytes skipped is returned. + * possibly 0. If n is negative, the method + * will try to skip backwards. In case the backing file does not support + * backward skip at its current position, an IOException is + * thrown. The actual number of bytes skipped is returned. If it skips + * forwards, it returns a positive value. If it skips backwards, it + * returns a negative value. * - *

This method may skip more bytes than are remaining in the backing - * file. This produces no exception and the number of bytes skipped + *

This method may skip more bytes than what are remaining in the + * backing file. This produces no exception and the number of bytes skipped * may include some number of bytes that were beyond the EOF of the * backing file. Attempting to read from the stream after skipping past * the end will result in -1 indicating the end of the file. @@ -261,9 +263,10 @@ /** * Returns an estimate of the number of remaining bytes that can be read (or * skipped over) from this input stream without blocking by the next - * invocation of a method for this input stream. The next invocation might be - * the same thread or another thread. A single read or skip of this - * many bytes will not block, but may read or skip fewer bytes. + * invocation of a method for this input stream. Returns 0 when the file + * position is beyond EOF. The next invocation might be the same thread + * or another thread. A single read or skip of this many bytes will not + * block, but may read or skip fewer bytes. * *

In some cases, a non-blocking read (or skip) may appear to be * blocked when it is merely slow, for example when reading large diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/src/share/classes/java/io/InputStream.java --- a/jdk/src/share/classes/java/io/InputStream.java Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/src/share/classes/java/io/InputStream.java Wed Jun 05 00:37:11 2013 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 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 @@ -193,8 +193,10 @@ * up skipping over some smaller number of bytes, possibly 0. * This may result from any of a number of conditions; reaching end of file * before n bytes have been skipped is only one possibility. - * The actual number of bytes skipped is returned. If n is - * negative, no bytes are skipped. + * The actual number of bytes skipped is returned. If {@code n} is + * negative, the {@code skip} method for class {@code InputStream} always + * returns 0, and no bytes are skipped. Subclasses may handle the negative + * value differently. * *

The skip method of this class creates a * byte array and then repeatedly reads into it until n bytes diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/src/share/classes/java/lang/Class.java --- a/jdk/src/share/classes/java/lang/Class.java Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/src/share/classes/java/lang/Class.java Wed Jun 05 00:37:11 2013 -0700 @@ -28,6 +28,7 @@ import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Array; import java.lang.reflect.GenericArrayType; +import java.lang.reflect.GenericDeclaration; import java.lang.reflect.Member; import java.lang.reflect.Field; import java.lang.reflect.Executable; @@ -115,9 +116,9 @@ * @since JDK1.0 */ public final class Class implements java.io.Serializable, - java.lang.reflect.GenericDeclaration, - java.lang.reflect.Type, - java.lang.reflect.AnnotatedElement { + GenericDeclaration, + Type, + AnnotatedElement { private static final int ANNOTATION= 0x00002000; private static final int ENUM = 0x00004000; private static final int SYNTHETIC = 0x00001000; @@ -3182,7 +3183,7 @@ */ @Override public boolean isAnnotationPresent(Class annotationClass) { - return AnnotatedElement.super.isAnnotationPresent(annotationClass); + return GenericDeclaration.super.isAnnotationPresent(annotationClass); } /** diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/src/share/classes/java/lang/String.java --- a/jdk/src/share/classes/java/lang/String.java Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/src/share/classes/java/lang/String.java Wed Jun 05 00:37:11 2013 -0700 @@ -1010,13 +1010,14 @@ private boolean nonSyncContentEquals(AbstractStringBuilder sb) { char v1[] = value; char v2[] = sb.getValue(); - int i = 0; - int n = value.length; - while (n-- != 0) { + int n = v1.length; + if (n != sb.length()) { + return false; + } + for (int i = 0; i < n; i++) { if (v1[i] != v2[i]) { return false; } - i++; } return true; } @@ -1038,8 +1039,6 @@ * @since 1.5 */ public boolean contentEquals(CharSequence cs) { - if (value.length != cs.length()) - return false; // Argument is a StringBuffer, StringBuilder if (cs instanceof AbstractStringBuilder) { if (cs instanceof StringBuffer) { @@ -1055,12 +1054,14 @@ return true; // Argument is a generic CharSequence char v1[] = value; - int i = 0; - int n = value.length; - while (n-- != 0) { - if (v1[i] != cs.charAt(i)) + int n = v1.length; + if (n != cs.length()) { + return false; + } + for (int i = 0; i < n; i++) { + if (v1[i] != cs.charAt(i)) { return false; - i++; + } } return true; } diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/src/share/classes/java/lang/StringBuffer.java --- a/jdk/src/share/classes/java/lang/StringBuffer.java Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/src/share/classes/java/lang/StringBuffer.java Wed Jun 05 00:37:11 2013 -0700 @@ -335,10 +335,8 @@ * @since 1.5 */ @Override - public StringBuffer append(CharSequence s) { - // Note, synchronization achieved via invocations of other StringBuffer methods after - // narrowing of s to specific type - // Ditto for toStringCache clearing + public synchronized StringBuffer append(CharSequence s) { + toStringCache = null; super.append(s); return this; } diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/src/share/classes/java/lang/Thread.java --- a/jdk/src/share/classes/java/lang/Thread.java Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/src/share/classes/java/lang/Thread.java Wed Jun 05 00:37:11 2013 -0700 @@ -145,10 +145,10 @@ registerNatives(); } - private char name[]; - private int priority; - private Thread threadQ; - private long eetop; + private volatile char name[]; + private int priority; + private Thread threadQ; + private long eetop; /* Whether or not to single_step this thread. */ private boolean single_step; @@ -1135,7 +1135,7 @@ * @see #getName * @see #checkAccess() */ - public final void setName(String name) { + public final synchronized void setName(String name) { checkAccess(); this.name = name.toCharArray(); if (threadStatus != 0) { @@ -1150,7 +1150,7 @@ * @see #setName(String) */ public final String getName() { - return String.valueOf(name); + return new String(name, true); } /** diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/src/share/classes/java/lang/ref/Reference.java --- a/jdk/src/share/classes/java/lang/ref/Reference.java Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/src/share/classes/java/lang/ref/Reference.java Wed Jun 05 00:37:11 2013 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -138,8 +138,23 @@ pending = r.discovered; r.discovered = null; } else { + // The waiting on the lock may cause an OOME because it may try to allocate + // exception objects, so also catch OOME here to avoid silent exit of the + // reference handler thread. + // + // Explicitly define the order of the two exceptions we catch here + // when waiting for the lock. + // + // We do not want to try to potentially load the InterruptedException class + // (which would be done if this was its first use, and InterruptedException + // were checked first) in this situation. + // + // This may lead to the VM not ever trying to load the InterruptedException + // class again. try { - lock.wait(); + try { + lock.wait(); + } catch (OutOfMemoryError x) { } } catch (InterruptedException x) { } continue; } diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/src/share/classes/java/lang/reflect/GenericDeclaration.java --- a/jdk/src/share/classes/java/lang/reflect/GenericDeclaration.java Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/src/share/classes/java/lang/reflect/GenericDeclaration.java Wed Jun 05 00:37:11 2013 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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 @@ -30,7 +30,7 @@ * * @since 1.5 */ -public interface GenericDeclaration { +public interface GenericDeclaration extends AnnotatedElement { /** * Returns an array of {@code TypeVariable} objects that * represent the type variables declared by the generic diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/src/share/classes/java/nio/charset/Charset-X-Coder.java.template --- a/jdk/src/share/classes/java/nio/charset/Charset-X-Coder.java.template Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/src/share/classes/java/nio/charset/Charset-X-Coder.java.template Wed Jun 05 00:37:11 2013 -0700 @@ -34,6 +34,7 @@ import java.nio.BufferUnderflowException; import java.lang.ref.WeakReference; import java.nio.charset.CoderMalfunctionError; // javadoc +import java.util.Arrays; /** @@ -244,7 +245,12 @@ * which is never null and is never empty */ public final $replType$ replacement() { +#if[decoder] return replacement; +#end[decoder] +#if[encoder] + return Arrays.copyOf(replacement, replacement.$replLength$); +#end[encoder] } /** @@ -280,12 +286,15 @@ throw new IllegalArgumentException("Empty replacement"); if (len > max$ItypesPerOtype$) throw new IllegalArgumentException("Replacement too long"); +#if[decoder] + this.replacement = newReplacement; +#end[decoder] #if[encoder] if (!isLegalReplacement(newReplacement)) throw new IllegalArgumentException("Illegal replacement"); + this.replacement = Arrays.copyOf(newReplacement, newReplacement.$replLength$); #end[encoder] - this.replacement = newReplacement; - implReplaceWith(newReplacement); + implReplaceWith(this.replacement); return this; } diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/src/share/classes/java/nio/file/FileTreeIterator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/src/share/classes/java/nio/file/FileTreeIterator.java Wed Jun 05 00:37:11 2013 -0700 @@ -0,0 +1,124 @@ +/* + * Copyright (c) 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. 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.nio.file; + +import java.io.Closeable; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.util.Arrays; +import java.util.Iterator; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.nio.file.FileTreeWalker.Event; + +/** + * An {@code Iterator to iterate over the nodes of a file tree. + * + *

{@code
+ *     try (FileTreeIterator iterator = new FileTreeIterator(start, maxDepth, options)) {
+ *         while (iterator.hasNext()) {
+ *             Event ev = iterator.next();
+ *             Path path = ev.file();
+ *             BasicFileAttributes attrs = ev.attributes();
+ *         }
+ *     }
+ * }
+ */ + +class FileTreeIterator implements Iterator, Closeable { + private final FileTreeWalker walker; + private Event next; + + /** + * Creates a new iterator to walk the file tree starting at the given file. + * + * @throws IllegalArgumentException + * if {@code maxDepth} is negative + * @throws IOException + * if an I/O errors occurs opening the starting file + * @throws SecurityException + * if the security manager denies access to the starting file + * @throws NullPointerException + * if {@code start} or {@code options} is {@ocde null} or + * the options array contains a {@code null} element + */ + FileTreeIterator(Path start, int maxDepth, FileVisitOption... options) + throws IOException + { + this.walker = new FileTreeWalker(Arrays.asList(options), maxDepth); + this.next = walker.walk(start); + assert next.type() == FileTreeWalker.EventType.ENTRY || + next.type() == FileTreeWalker.EventType.START_DIRECTORY; + + // IOException if there a problem accessing the starting file + IOException ioe = next.ioeException(); + if (ioe != null) + throw ioe; + } + + private void fetchNextIfNeeded() { + if (next == null) { + FileTreeWalker.Event ev = walker.next(); + while (ev != null) { + IOException ioe = ev.ioeException(); + if (ioe != null) + throw new UncheckedIOException(ioe); + + // END_DIRECTORY events are ignored + if (ev.type() != FileTreeWalker.EventType.END_DIRECTORY) { + next = ev; + return; + } + ev = walker.next(); + } + } + } + + @Override + public boolean hasNext() { + if (!walker.isOpen()) + throw new IllegalStateException(); + fetchNextIfNeeded(); + return next != null; + } + + @Override + public Event next() { + if (!walker.isOpen()) + throw new IllegalStateException(); + fetchNextIfNeeded(); + if (next == null) + throw new NoSuchElementException(); + Event result = next; + next = null; + return result; + } + + @Override + public void close() { + walker.close(); + } +} diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/src/share/classes/java/nio/file/FileTreeWalker.java --- a/jdk/src/share/classes/java/nio/file/FileTreeWalker.java Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/src/share/classes/java/nio/file/FileTreeWalker.java Wed Jun 05 00:37:11 2013 -0700 @@ -29,8 +29,8 @@ import java.io.Closeable; import java.io.IOException; import java.util.ArrayDeque; +import java.util.Collection; import java.util.Iterator; -import java.util.Set; import sun.nio.fs.BasicFileAttributesHolder; /** @@ -164,8 +164,17 @@ /** * Creates a {@code FileTreeWalker}. + * + * @throws IllegalArgumentException + * if {@code maxDepth} is negative + * @throws ClassCastException + * if (@code options} contains an element that is not a + * {@code FileVisitOption} + * @throws NullPointerException + * if {@code options} is {@ocde null} or the options + * array contains a {@code null} element */ - FileTreeWalker(Set options, int maxDepth) { + FileTreeWalker(Collection options, int maxDepth) { boolean fl = false; for (FileVisitOption option: options) { // will throw NPE if options contains null @@ -175,6 +184,9 @@ throw new AssertionError("Should not get here"); } } + if (maxDepth < 0) + throw new IllegalArgumentException("'maxDepth' is negative"); + this.followLinks = fl; this.linkOptions = (fl) ? new LinkOption[0] : new LinkOption[] { LinkOption.NOFOLLOW_LINKS }; diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/src/share/classes/java/nio/file/Files.java --- a/jdk/src/share/classes/java/nio/file/Files.java Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/src/share/classes/java/nio/file/Files.java Wed Jun 05 00:37:11 2013 -0700 @@ -25,10 +25,13 @@ package java.nio.file; +import java.nio.ByteBuffer; import java.nio.file.attribute.*; import java.nio.file.spi.FileSystemProvider; import java.nio.file.spi.FileTypeDetector; +import java.nio.channels.FileChannel; import java.nio.channels.SeekableByteChannel; +import java.io.Closeable; import java.io.InputStream; import java.io.OutputStream; import java.io.Reader; @@ -38,7 +41,13 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.IOException; +import java.io.UncheckedIOException; import java.util.*; +import java.util.function.BiPredicate; +import java.util.stream.CloseableStream; +import java.util.stream.DelegatingStream; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; import java.security.AccessController; import java.security.PrivilegedAction; import java.nio.charset.Charset; @@ -2587,9 +2596,6 @@ FileVisitor visitor) throws IOException { - if (maxDepth < 0) - throw new IllegalArgumentException("'maxDepth' is negative"); - /** * Create a FileTreeWalker to walk the file tree, invoking the visitor * for each event. @@ -2941,40 +2947,6 @@ } /** - * Read all the bytes from an input stream. The {@code initialSize} - * parameter indicates the initial size of the byte[] to allocate. - */ - private static byte[] read(InputStream source, int initialSize) - throws IOException - { - int capacity = initialSize; - byte[] buf = new byte[capacity]; - int nread = 0; - int rem = buf.length; - int n; - // read to EOF which may read more or less than initialSize (eg: file - // is truncated while we are reading) - while ((n = source.read(buf, nread, rem)) > 0) { - nread += n; - rem -= n; - assert rem >= 0; - if (rem == 0) { - // need larger buffer - int newCapacity = capacity << 1; - if (newCapacity < 0) { - if (capacity == Integer.MAX_VALUE) - throw new OutOfMemoryError("Required array size too large"); - newCapacity = Integer.MAX_VALUE; - } - rem = newCapacity - capacity; - buf = Arrays.copyOf(buf, newCapacity); - capacity = newCapacity; - } - } - return (capacity == nread) ? buf : Arrays.copyOf(buf, nread); - } - - /** * Read all the bytes from a file. The method ensures that the file is * closed when all bytes have been read or an I/O error, or other runtime * exception, is thrown. @@ -2999,12 +2971,22 @@ * method is invoked to check read access to the file. */ public static byte[] readAllBytes(Path path) throws IOException { - long size = size(path); - if (size > (long)Integer.MAX_VALUE) - throw new OutOfMemoryError("Required array size too large"); + try (FileChannel fc = FileChannel.open(path)) { + long size = fc.size(); + if (size > (long)Integer.MAX_VALUE) + throw new OutOfMemoryError("Required array size too large"); - try (InputStream in = newInputStream(path)) { - return read(in, (int)size); + byte[] arr = new byte[(int)size]; + ByteBuffer bb = ByteBuffer.wrap(arr); + while (bb.hasRemaining()) { + if (fc.read(bb) < 0) { + // truncated + break; + } + } + + int nread = bb.position(); + return (nread == size) ? arr : Arrays.copyOf(arr, nread); } } @@ -3177,4 +3159,336 @@ } return path; } + + // -- Stream APIs -- + + /** + * Implementation of CloseableStream + */ + private static class DelegatingCloseableStream extends DelegatingStream + implements CloseableStream + { + private final Closeable closeable; + + DelegatingCloseableStream(Closeable c, Stream delegate) { + super(delegate); + this.closeable = c; + } + + public void close() { + try { + closeable.close(); + } catch (IOException ex) { + throw new UncheckedIOException(ex); + } + } + } + + /** + * Return a lazily populated {@code CloseableStream}, the elements of + * which are the entries in the directory. The listing is not recursive. + * + *

The elements of the stream are {@link Path} objects that are + * obtained as if by {@link Path#resolve(Path) resolving} the name of the + * directory entry against {@code dir}. Some file systems maintain special + * links to the directory itself and the directory's parent directory. + * Entries representing these links are not included. + * + *

The stream is weakly consistent. It is thread safe but does + * not freeze the directory while iterating, so it may (or may not) + * reflect updates to the directory that occur after returning from this + * method. + * + *

When not using the try-with-resources construct, then the stream's + * {@link CloseableStream#close close} method should be invoked after the + * operation is completed so as to free any resources held for the open + * directory. Operating on a closed stream behaves as if the end of stream + * has been reached. Due to read-ahead, one or more elements may be + * returned after the stream has been closed. + * + *

If an {@link IOException} is thrown when accessing the directory + * after this method has returned, it is wrapped in an {@link + * UncheckedIOException} which will be thrown from the method that caused + * the access to take place. + * + * @param dir The path to the directory + * + * @return The {@code CloseableStream} describing the content of the + * directory + * + * @throws NotDirectoryException + * if the file could not otherwise be opened because it is not + * a directory (optional specific exception) + * @throws IOException + * if an I/O error occurs when opening the directory + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkRead(String) checkRead} + * method is invoked to check read access to the directory. + * + * @see #newDirectoryStream(Path) + * @since 1.8 + */ + public static CloseableStream list(Path dir) throws IOException { + DirectoryStream ds = Files.newDirectoryStream(dir); + final Iterator delegate = ds.iterator(); + + // Re-wrap DirectoryIteratorException to UncheckedIOException + Iterator it = new Iterator() { + public boolean hasNext() { + try { + return delegate.hasNext(); + } catch (DirectoryIteratorException e) { + throw new UncheckedIOException(e.getCause()); + } + } + public Path next() { + try { + return delegate.next(); + } catch (DirectoryIteratorException e) { + throw new UncheckedIOException(e.getCause()); + } + } + }; + + return new DelegatingCloseableStream<>(ds, + StreamSupport.stream(Spliterators.spliteratorUnknownSize(it, + Spliterator.DISTINCT))); + } + + /** + * Return a {@code CloseableStream} that is lazily populated with {@code + * Path} by walking the file tree rooted at a given starting file. The + * file tree is traversed depth-first, the elements in the stream + * are {@link Path} objects that are obtained as if by {@link + * Path#resolve(Path) resolving} the relative path against {@code start}. + * + *

The {@code stream} walks the file tree as elements are consumed. + * The {@code CloseableStream} returned is guaranteed to have at least one + * element, the starting file itself. For each file visited, the stream + * attempts to read its {@link BasicFileAttributes}. If the file is a + * directory and can be opened successfully, entries in the directory, and + * their descendants will follow the directory in the stream as + * they are encountered. When all entries have been visited, then the + * directory is closed. The file tree walk then continues at the next + * sibling of the directory. + * + *

The stream is weakly consistent. It does not freeze the + * file tree while iterating, so it may (or may not) reflect updates to + * the file tree that occur after returned from this method. + * + *

By default, symbolic links are not automatically followed by this + * method. If the {@code options} parameter contains the {@link + * FileVisitOption#FOLLOW_LINKS FOLLOW_LINKS} option then symbolic links are + * followed. When following links, and the attributes of the target cannot + * be read, then this method attempts to get the {@code BasicFileAttributes} + * of the link. + * + *

If the {@code options} parameter contains the {@link + * FileVisitOption#FOLLOW_LINKS FOLLOW_LINKS} option then the stream keeps + * track of directories visited so that cycles can be detected. A cycle + * arises when there is an entry in a directory that is an ancestor of the + * directory. Cycle detection is done by recording the {@link + * java.nio.file.attribute.BasicFileAttributes#fileKey file-key} of directories, + * or if file keys are not available, by invoking the {@link #isSameFile + * isSameFile} method to test if a directory is the same file as an + * ancestor. When a cycle is detected it is treated as an I/O error with + * an instance of {@link FileSystemLoopException}. + * + *

The {@code maxDepth} parameter is the maximum number of levels of + * directories to visit. A value of {@code 0} means that only the starting + * file is visited, unless denied by the security manager. A value of + * {@link Integer#MAX_VALUE MAX_VALUE} may be used to indicate that all + * levels should be visited. + * + *

When a security manager is installed and it denies access to a file + * (or directory), then it is ignored and not included in the stream. + * + *

When not using the try-with-resources construct, then the stream's + * {@link CloseableStream#close close} method should be invoked after the + * operation is completed so as to free any resources held for the open + * directory. Operate the stream after it is closed will throw an + * {@link java.lang.IllegalStateException}. + * + *

If an {@link IOException} is thrown when accessing the directory + * after this method has returned, it is wrapped in an {@link + * UncheckedIOException} which will be thrown from the method that caused + * the access to take place. + * + * @param start + * the starting file + * @param maxDepth + * the maximum number of directory levels to visit + * @param options + * options to configure the traversal + * + * @return the {@link CloseableStream} of {@link Path} + * + * @throws IllegalArgumentException + * if the {@code maxDepth} parameter is negative + * @throws SecurityException + * If the security manager denies access to the starting file. + * In the case of the default provider, the {@link + * SecurityManager#checkRead(String) checkRead} method is invoked + * to check read access to the directory. + * @throws IOException + * if an I/O error is thrown when accessing the starting file. + * @since 1.8 + */ + public static CloseableStream walk(Path start, int maxDepth, + FileVisitOption... options) + throws IOException + { + FileTreeIterator iterator = new FileTreeIterator(start, maxDepth, options); + return new DelegatingCloseableStream<>(iterator, + StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.DISTINCT)) + .map(entry -> entry.file())); + } + + /** + * Return a {@code CloseableStream} that is lazily populated with {@code + * Path} by walking the file tree rooted at a given starting file. The + * file tree is traversed depth-first, the elements in the stream + * are {@link Path} objects that are obtained as if by {@link + * Path#resolve(Path) resolving} the relative path against {@code start}. + * + *

This method works as if invoking it were equivalent to evaluating the + * expression: + *

+     * walk(start, Integer.MAX_VALUE, options)
+     * 
+ * In other words, it visits all levels of the file tree. + * + * @param start + * the starting file + * @param options + * options to configure the traversal + * + * @return the {@link CloseableStream} of {@link Path} + * + * @throws SecurityException + * If the security manager denies access to the starting file. + * In the case of the default provider, the {@link + * SecurityManager#checkRead(String) checkRead} method is invoked + * to check read access to the directory. + * @throws IOException + * if an I/O error is thrown when accessing the starting file. + * + * @see #walk(Path, int, FileVisitOption...) + * @since 1.8 + */ + public static CloseableStream walk(Path start, + FileVisitOption... options) + throws IOException + { + return walk(start, Integer.MAX_VALUE, options); + } + + /** + * Return a {@code CloseableStream} that is lazily populated with {@code + * Path} by searching for files in a file tree rooted at a given starting + * file. + * + *

This method walks the file tree in exactly the manner specified by + * the {@link #walk walk} method. For each file encountered, the given + * {@link BiPredicate} is invoked with its {@link Path} and {@link + * BasicFileAttributes}. The {@code Path} object is obtained as if by + * {@link Path#resolve(Path) resolving} the relative path against {@code + * start} and is only included in the returned {@link CloseableStream} if + * the {@code BiPredicate} returns true. Compare to calling {@link + * java.util.stream.Stream#filter filter} on the {@code Stream} + * returned by {@code walk} method, this method may be more efficient by + * avoiding redundant retrieval of the {@code BasicFileAttributes}. + * + *

If an {@link IOException} is thrown when accessing the directory + * after returned from this method, it is wrapped in an {@link + * UncheckedIOException} which will be thrown from the method that caused + * the access to take place. + * + * @param start + * the starting file + * @param maxDepth + * the maximum number of directory levels to search + * @param matcher + * the function used to decide whether a file should be included + * in the returned stream + * @param options + * options to configure the traversal + * + * @return the {@link CloseableStream} of {@link Path} + * + * @throws IllegalArgumentException + * if the {@code maxDepth} parameter is negative + * @throws SecurityException + * If the security manager denies access to the starting file. + * In the case of the default provider, the {@link + * SecurityManager#checkRead(String) checkRead} method is invoked + * to check read access to the directory. + * @throws IOException + * if an I/O error is thrown when accessing the starting file. + * + * @see #walk(Path, int, FileVisitOption...) + * @since 1.8 + */ + public static CloseableStream find(Path start, + int maxDepth, + BiPredicate matcher, + FileVisitOption... options) + throws IOException + { + FileTreeIterator iterator = new FileTreeIterator(start, maxDepth, options); + return new DelegatingCloseableStream<>(iterator, + StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.DISTINCT)) + .filter(entry -> matcher.test(entry.file(), entry.attributes())) + .map(entry -> entry.file())); + } + + /** + * Read all lines from a file as a {@code CloseableStream}. Unlike {@link + * #readAllLines(Path, Charset) readAllLines}, this method does not read + * all lines into a {@code List}, but instead populates lazily as the stream + * is consumed. + * + *

Bytes from the file are decoded into characters using the specified + * charset and the same line terminators as specified by {@code + * readAllLines} are supported. + * + *

After this method returns, then any subsequent I/O exception that + * occurs while reading from the file or when a malformed or unmappable byte + * sequence is read, is wrapped in an {@link UncheckedIOException} that will + * be thrown form the + * {@link java.util.stream.Stream} method that caused the read to take + * place. In case an {@code IOException} is thrown when closing the file, + * it is also wrapped as an {@code UncheckedIOException}. + * + *

When not using the try-with-resources construct, then stream's + * {@link CloseableStream#close close} method should be invoked after + * operation is completed so as to free any resources held for the open + * file. + * + * @param path + * the path to the file + * @param cs + * the charset to use for decoding + * + * @return the lines from the file as a {@code CloseableStream} + * + * @throws IOException + * if an I/O error occurs opening the file + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkRead(String) checkRead} + * method is invoked to check read access to the file. + * + * @see #readAllLines(Path, Charset) + * @see #newBufferedReader(Path, Charset) + * @see java.io.BufferedReader#lines() + * @since 1.8 + */ + public static CloseableStream lines(Path path, Charset cs) + throws IOException + { + BufferedReader br = Files.newBufferedReader(path, cs); + return new DelegatingCloseableStream<>(br, br.lines()); + } } diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/src/share/classes/java/text/DateFormatSymbols.java --- a/jdk/src/share/classes/java/text/DateFormatSymbols.java Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/src/share/classes/java/text/DateFormatSymbols.java Wed Jun 05 00:37:11 2013 -0700 @@ -59,7 +59,7 @@ * DateFormatSymbols is a public class for encapsulating * localizable date-time formatting data, such as the names of the * months, the names of the days of the week, and the time zone data. - * DateFormat and SimpleDateFormat both use + * SimpleDateFormat uses * DateFormatSymbols to encapsulate this information. * *

diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/src/share/classes/java/util/Arrays.java --- a/jdk/src/share/classes/java/util/Arrays.java Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/src/share/classes/java/util/Arrays.java Wed Jun 05 00:37:11 2013 -0700 @@ -40,7 +40,6 @@ import java.util.stream.LongStream; import java.util.stream.Stream; import java.util.stream.StreamSupport; -import static java.util.ArraysParallelSortHelpers.*; /** * This class contains various methods for manipulating arrays (such as @@ -70,17 +69,62 @@ public class Arrays { /** - * The minimum array length below which the sorting algorithm will not - * further partition the sorting task. + * 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. */ - // reasonable default so that we don't overcreate tasks - private static final int MIN_ARRAY_SORT_GRAN = 256; + private static final int MIN_ARRAY_SORT_GRAN = 1 << 13; // Suppresses default constructor, ensuring non-instantiability. private Arrays() {} + /** + * A comparator that implements the natural ordering of a group of + * mutually comparable elements. May be used when a supplied + * comparator is null. To simplify code-sharing within underlying + * implementations, the compare method only declares type Object + * for its second argument. + * + * Arrays class implementor's note: It is an empirical matter + * whether ComparableTimSort offers any performance benefit over + * TimSort used with this comparator. If not, you are better off + * deleting or bypassing ComparableTimSort. There is currently no + * empirical case for separating them for parallel sorting, so all + * public Object parallelSort methods use the same comparator + * based implementation. + */ + static final class NaturalOrder implements Comparator { + @SuppressWarnings("unchecked") + public int compare(Object first, Object second) { + return ((Comparable)first).compareTo(second); + } + static final NaturalOrder INSTANCE = new NaturalOrder(); + } + + /** + * Checks that {@code fromIndex} and {@code toIndex} are in + * the range and throws an exception if they aren't. + */ + private 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 of primitive type 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). */ /** @@ -95,7 +139,7 @@ * @param a the array to be sorted */ public static void sort(int[] a) { - DualPivotQuicksort.sort(a); + DualPivotQuicksort.sort(a, 0, a.length - 1, null, 0, 0); } /** @@ -120,7 +164,7 @@ */ public static void sort(int[] a, int fromIndex, int toIndex) { rangeCheck(a.length, fromIndex, toIndex); - DualPivotQuicksort.sort(a, fromIndex, toIndex - 1); + DualPivotQuicksort.sort(a, fromIndex, toIndex - 1, null, 0, 0); } /** @@ -135,7 +179,7 @@ * @param a the array to be sorted */ public static void sort(long[] a) { - DualPivotQuicksort.sort(a); + DualPivotQuicksort.sort(a, 0, a.length - 1, null, 0, 0); } /** @@ -160,7 +204,7 @@ */ public static void sort(long[] a, int fromIndex, int toIndex) { rangeCheck(a.length, fromIndex, toIndex); - DualPivotQuicksort.sort(a, fromIndex, toIndex - 1); + DualPivotQuicksort.sort(a, fromIndex, toIndex - 1, null, 0, 0); } /** @@ -175,7 +219,7 @@ * @param a the array to be sorted */ public static void sort(short[] a) { - DualPivotQuicksort.sort(a); + DualPivotQuicksort.sort(a, 0, a.length - 1, null, 0, 0); } /** @@ -200,7 +244,7 @@ */ public static void sort(short[] a, int fromIndex, int toIndex) { rangeCheck(a.length, fromIndex, toIndex); - DualPivotQuicksort.sort(a, fromIndex, toIndex - 1); + DualPivotQuicksort.sort(a, fromIndex, toIndex - 1, null, 0, 0); } /** @@ -215,7 +259,7 @@ * @param a the array to be sorted */ public static void sort(char[] a) { - DualPivotQuicksort.sort(a); + DualPivotQuicksort.sort(a, 0, a.length - 1, null, 0, 0); } /** @@ -240,7 +284,7 @@ */ public static void sort(char[] a, int fromIndex, int toIndex) { rangeCheck(a.length, fromIndex, toIndex); - DualPivotQuicksort.sort(a, fromIndex, toIndex - 1); + DualPivotQuicksort.sort(a, fromIndex, toIndex - 1, null, 0, 0); } /** @@ -255,7 +299,7 @@ * @param a the array to be sorted */ public static void sort(byte[] a) { - DualPivotQuicksort.sort(a); + DualPivotQuicksort.sort(a, 0, a.length - 1); } /** @@ -303,7 +347,7 @@ * @param a the array to be sorted */ public static void sort(float[] a) { - DualPivotQuicksort.sort(a); + DualPivotQuicksort.sort(a, 0, a.length - 1, null, 0, 0); } /** @@ -336,7 +380,7 @@ */ public static void sort(float[] a, int fromIndex, int toIndex) { rangeCheck(a.length, fromIndex, toIndex); - DualPivotQuicksort.sort(a, fromIndex, toIndex - 1); + DualPivotQuicksort.sort(a, fromIndex, toIndex - 1, null, 0, 0); } /** @@ -359,7 +403,7 @@ * @param a the array to be sorted */ public static void sort(double[] a) { - DualPivotQuicksort.sort(a); + DualPivotQuicksort.sort(a, 0, a.length - 1, null, 0, 0); } /** @@ -392,7 +436,742 @@ */ public static void sort(double[] a, int fromIndex, int toIndex) { rangeCheck(a.length, fromIndex, toIndex); - DualPivotQuicksort.sort(a, fromIndex, toIndex - 1); + 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. + * + *

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. + * + *

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. + * + *

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. + * + *

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(); + } + + /** + * Sorts the specified array of objects into ascending order, according + * to the {@linkplain Comparable natural ordering} of its elements. + * All elements in the array must implement the {@link Comparable} + * interface. Furthermore, all elements in the array must be + * mutually comparable (that is, {@code e1.compareTo(e2)} must + * not throw a {@code ClassCastException} for any elements {@code e1} + * and {@code e2} in the array). + * + *

This sort is guaranteed to be stable: equal elements will + * not be reordered as a result of the sort. + * + * @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(Object[]) 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(Object[]) 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 + * + * @throws ClassCastException if the array contains elements that are not + * mutually comparable (for example, strings and integers) + * @throws IllegalArgumentException (optional) if the natural + * ordering of the array elements is found to violate the + * {@link Comparable} contract + * + * @since 1.8 + */ + @SuppressWarnings("unchecked") + public static > void parallelSort(T[] a) { + int n = a.length, p, g; + if (n <= MIN_ARRAY_SORT_GRAN || + (p = ForkJoinPool.getCommonPoolParallelism()) == 1) + TimSort.sort(a, 0, n, NaturalOrder.INSTANCE, null, 0, 0); + else + new ArraysParallelSortHelpers.FJObject.Sorter + (null, a, + (T[])Array.newInstance(a.getClass().getComponentType(), n), + 0, n, 0, ((g = n / (p << 2)) <= MIN_ARRAY_SORT_GRAN) ? + MIN_ARRAY_SORT_GRAN : g, NaturalOrder.INSTANCE).invoke(); + } + + /** + * Sorts the specified range of the specified array of objects into + * ascending order, according to the + * {@linkplain Comparable natural ordering} of its + * elements. The range to be sorted extends from index + * {@code fromIndex}, inclusive, to index {@code toIndex}, exclusive. + * (If {@code fromIndex==toIndex}, the range to be sorted is empty.) All + * elements in this range must implement the {@link Comparable} + * interface. Furthermore, all elements in this range must be mutually + * comparable (that is, {@code e1.compareTo(e2)} must not throw a + * {@code ClassCastException} for any elements {@code e1} and + * {@code e2} in the array). + * + *

This sort is guaranteed to be stable: equal elements will + * not be reordered as a result of the sort. + * + * @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(Object[]) 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(Object[]) 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} or + * (optional) if the natural ordering of the array elements is + * found to violate the {@link Comparable} contract + * @throws ArrayIndexOutOfBoundsException if {@code fromIndex < 0} or + * {@code toIndex > a.length} + * @throws ClassCastException if the array contains elements that are + * not mutually comparable (for example, strings and + * integers). + * + * @since 1.8 + */ + @SuppressWarnings("unchecked") + public static > + void parallelSort(T[] 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) + TimSort.sort(a, fromIndex, toIndex, NaturalOrder.INSTANCE, null, 0, 0); + else + new ArraysParallelSortHelpers.FJObject.Sorter + (null, a, + (T[])Array.newInstance(a.getClass().getComponentType(), n), + fromIndex, n, 0, ((g = n / (p << 2)) <= MIN_ARRAY_SORT_GRAN) ? + MIN_ARRAY_SORT_GRAN : g, NaturalOrder.INSTANCE).invoke(); + } + + /** + * Sorts the specified array of objects according to the order induced by + * the specified comparator. All elements in the array must be + * mutually comparable by the specified comparator (that is, + * {@code c.compare(e1, e2)} must not throw a {@code ClassCastException} + * for any elements {@code e1} and {@code e2} in the array). + * + *

This sort is guaranteed to be stable: equal elements will + * not be reordered as a result of the sort. + * + * @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(Object[]) 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(Object[]) 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 + * @param cmp the comparator to determine the order of the array. A + * {@code null} value indicates that the elements' + * {@linkplain Comparable natural ordering} should be used. + * @throws ClassCastException if the array contains elements that are + * not mutually comparable using the specified comparator + * @throws IllegalArgumentException (optional) if the comparator is + * found to violate the {@link java.util.Comparator} contract + * + * @since 1.8 + */ + @SuppressWarnings("unchecked") + public static void parallelSort(T[] a, Comparator cmp) { + if (cmp == null) + cmp = NaturalOrder.INSTANCE; + int n = a.length, p, g; + if (n <= MIN_ARRAY_SORT_GRAN || + (p = ForkJoinPool.getCommonPoolParallelism()) == 1) + TimSort.sort(a, 0, n, cmp, null, 0, 0); + else + new ArraysParallelSortHelpers.FJObject.Sorter + (null, a, + (T[])Array.newInstance(a.getClass().getComponentType(), n), + 0, n, 0, ((g = n / (p << 2)) <= MIN_ARRAY_SORT_GRAN) ? + MIN_ARRAY_SORT_GRAN : g, cmp).invoke(); + } + + /** + * Sorts the specified range of the specified array of objects according + * to the order induced by the specified comparator. The range to be + * sorted extends from index {@code fromIndex}, inclusive, to index + * {@code toIndex}, exclusive. (If {@code fromIndex==toIndex}, the + * range to be sorted is empty.) All elements in the range must be + * mutually comparable by the specified comparator (that is, + * {@code c.compare(e1, e2)} must not throw a {@code ClassCastException} + * for any elements {@code e1} and {@code e2} in the range). + * + *

This sort is guaranteed to be stable: equal elements will + * not be reordered as a result of the sort. + * + * @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(Object[]) 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(Object[]) 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 + * @param cmp the comparator to determine the order of the array. A + * {@code null} value indicates that the elements' + * {@linkplain Comparable natural ordering} should be used. + * @throws IllegalArgumentException if {@code fromIndex > toIndex} or + * (optional) if the natural ordering of the array elements is + * found to violate the {@link Comparable} contract + * @throws ArrayIndexOutOfBoundsException if {@code fromIndex < 0} or + * {@code toIndex > a.length} + * @throws ClassCastException if the array contains elements that are + * not mutually comparable (for example, strings and + * integers). + * + * @since 1.8 + */ + @SuppressWarnings("unchecked") + public static void parallelSort(T[] a, int fromIndex, int toIndex, + Comparator cmp) { + rangeCheck(a.length, fromIndex, toIndex); + if (cmp == null) + cmp = NaturalOrder.INSTANCE; + int n = toIndex - fromIndex, p, g; + if (n <= MIN_ARRAY_SORT_GRAN || + (p = ForkJoinPool.getCommonPoolParallelism()) == 1) + TimSort.sort(a, fromIndex, toIndex, cmp, null, 0, 0); + else + new ArraysParallelSortHelpers.FJObject.Sorter + (null, a, + (T[])Array.newInstance(a.getClass().getComponentType(), n), + fromIndex, n, 0, ((g = n / (p << 2)) <= MIN_ARRAY_SORT_GRAN) ? + MIN_ARRAY_SORT_GRAN : g, cmp).invoke(); } /* @@ -412,39 +1191,6 @@ "java.util.Arrays.useLegacyMergeSort")).booleanValue(); } - /* - * If this platform has an optimizing VM, check whether ComparableTimSort - * offers any performance benefit over TimSort in conjunction with a - * comparator that returns: - * {@code ((Comparable)first).compareTo(Second)}. - * If not, you are better off deleting ComparableTimSort to - * eliminate the code duplication. In other words, the commented - * out code below is the preferable implementation for sorting - * arrays of Comparables if it offers sufficient performance. - */ - -// /** -// * A comparator that implements the natural ordering of a group of -// * mutually comparable elements. Using this comparator saves us -// * from duplicating most of the code in this file (one version for -// * Comparables, one for explicit Comparators). -// */ -// private static final Comparator NATURAL_ORDER = -// new Comparator() { -// @SuppressWarnings("unchecked") -// public int compare(Object first, Object second) { -// return ((Comparable)first).compareTo(second); -// } -// }; -// -// public static void sort(Object[] a) { -// sort(a, 0, a.length, NATURAL_ORDER); -// } -// -// public static void sort(Object[] a, int fromIndex, int toIndex) { -// sort(a, fromIndex, toIndex, NATURAL_ORDER); -// } - /** * Sorts the specified array of objects into ascending order, according * to the {@linkplain Comparable natural ordering} of its elements. @@ -491,7 +1237,7 @@ if (LegacyMergeSort.userRequested) legacyMergeSort(a); else - ComparableTimSort.sort(a); + ComparableTimSort.sort(a, 0, a.length, null, 0, 0); } /** To be removed in a future release. */ @@ -553,16 +1299,16 @@ * integers). */ public static void sort(Object[] a, int fromIndex, int toIndex) { + rangeCheck(a.length, fromIndex, toIndex); if (LegacyMergeSort.userRequested) legacyMergeSort(a, fromIndex, toIndex); else - ComparableTimSort.sort(a, fromIndex, toIndex); + ComparableTimSort.sort(a, fromIndex, toIndex, null, 0, 0); } /** To be removed in a future release. */ private static void legacyMergeSort(Object[] a, int fromIndex, int toIndex) { - rangeCheck(a.length, fromIndex, toIndex); Object[] aux = copyOfRange(a, fromIndex, toIndex); mergeSort(aux, a, fromIndex, toIndex, -fromIndex); } @@ -676,10 +1422,12 @@ * found to violate the {@link Comparator} contract */ public static void sort(T[] a, Comparator c) { + if (c == null) + c = NaturalOrder.INSTANCE; if (LegacyMergeSort.userRequested) legacyMergeSort(a, c); else - TimSort.sort(a, c); + TimSort.sort(a, 0, a.length, c, null, 0, 0); } /** To be removed in a future release. */ @@ -744,16 +1492,18 @@ */ public static void sort(T[] a, int fromIndex, int toIndex, Comparator c) { + if (c == null) + c = NaturalOrder.INSTANCE; + rangeCheck(a.length, fromIndex, toIndex); if (LegacyMergeSort.userRequested) legacyMergeSort(a, fromIndex, toIndex, c); else - TimSort.sort(a, fromIndex, toIndex, c); + TimSort.sort(a, fromIndex, toIndex, c, null, 0, 0); } /** To be removed in a future release. */ private static void legacyMergeSort(T[] a, int fromIndex, int toIndex, Comparator c) { - rangeCheck(a.length, fromIndex, toIndex); T[] aux = copyOfRange(a, fromIndex, toIndex); if (c==null) mergeSort(aux, a, fromIndex, toIndex, -fromIndex); @@ -809,630 +1559,6 @@ } } - /* - * Parallel sorting of primitive type arrays. - */ - - /** - * Sorts the specified array into ascending numerical order. - * - *

Implementation note: 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. The algorithm requires a working space equal to the - * size of the original array. The {@link - * java.util.concurrent.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) { - parallelSort(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. - * - *

Implementation note: 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. The algorithm requires a working space equal to the - * size of the original array. The {@link - * java.util.concurrent.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 nelements = toIndex - fromIndex; - int gran = getSplitThreshold(nelements); - FJByte.Sorter task = new FJByte.Sorter(a, new byte[a.length], fromIndex, - nelements, gran); - task.invoke(); - } - - /** - * Sorts the specified array into ascending numerical order. - * - *

Implementation note: 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. The algorithm requires a working space equal to the - * size of the original array. The {@link - * java.util.concurrent.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) { - parallelSort(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. - * - *

Implementation note: 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. The algorithm requires a working space equal to the - * size of the original array. The {@link - * java.util.concurrent.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 nelements = toIndex - fromIndex; - int gran = getSplitThreshold(nelements); - FJChar.Sorter task = new FJChar.Sorter(a, new char[a.length], fromIndex, - nelements, gran); - task.invoke(); - } - - /** - * Sorts the specified array into ascending numerical order. - * - *

Implementation note: 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. The algorithm requires a working space equal to the - * size of the original array. The {@link - * java.util.concurrent.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) { - parallelSort(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. - * - *

Implementation note: 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. The algorithm requires a working space equal to the - * size of the original array. The {@link - * java.util.concurrent.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 nelements = toIndex - fromIndex; - int gran = getSplitThreshold(nelements); - FJShort.Sorter task = new FJShort.Sorter(a, new short[a.length], fromIndex, - nelements, gran); - task.invoke(); - } - - /** - * Sorts the specified array into ascending numerical order. - * - *

Implementation note: 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. The algorithm requires a working space equal to the - * size of the original array. The {@link - * java.util.concurrent.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) { - parallelSort(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. - * - *

Implementation note: 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. The algorithm requires a working space equal to the - * size of the original array. The {@link - * java.util.concurrent.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 nelements = toIndex - fromIndex; - int gran = getSplitThreshold(nelements); - FJInt.Sorter task = new FJInt.Sorter(a, new int[a.length], fromIndex, - nelements, gran); - task.invoke(); - } - - /** - * Sorts the specified array into ascending numerical order. - * - *

Implementation note: 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. The algorithm requires a working space equal to the - * size of the original array. The {@link - * java.util.concurrent.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) { - parallelSort(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. - * - *

Implementation note: 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. The algorithm requires a working space equal to the - * size of the original array. The {@link - * java.util.concurrent.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 nelements = toIndex - fromIndex; - int gran = getSplitThreshold(nelements); - FJLong.Sorter task = new FJLong.Sorter(a, new long[a.length], fromIndex, - nelements, gran); - task.invoke(); - } - - /** - * Sorts the specified array into ascending numerical order. - * - *

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. - * - *

Implementation note: 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. The algorithm requires a working space equal to the - * size of the original array. The {@link - * java.util.concurrent.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) { - parallelSort(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. - * - *

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. - * - *

Implementation note: 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. The algorithm requires a working space equal to the - * size of the original array. The {@link - * java.util.concurrent.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 nelements = toIndex - fromIndex; - int gran = getSplitThreshold(nelements); - FJFloat.Sorter task = new FJFloat.Sorter(a, new float[a.length], fromIndex, - nelements, gran); - task.invoke(); - } - - /** - * Sorts the specified array into ascending numerical order. - * - *

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. - * - *

Implementation note: 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. The algorithm requires a working space equal to the - * size of the original array. The {@link - * java.util.concurrent.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) { - parallelSort(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. - * - *

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. - * - *

Implementation note: 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. The algorithm requires a working space equal to the - * size of the original array. The {@link - * java.util.concurrent.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 nelements = toIndex - fromIndex; - int gran = getSplitThreshold(nelements); - FJDouble.Sorter task = new FJDouble.Sorter(a, new double[a.length], - fromIndex, nelements, gran); - task.invoke(); - } - - /* - * Parallel sorting of complex type arrays. - */ - - /** - * Sorts the specified array of objects into ascending order, according - * to the {@linkplain Comparable natural ordering} of its elements. - * All elements in the array must implement the {@link Comparable} - * interface. Furthermore, all elements in the array must be - * mutually comparable (that is, {@code e1.compareTo(e2)} must - * not throw a {@code ClassCastException} for any elements {@code e1} - * and {@code e2} in the array). - * - *

This sort is not guaranteed to be stable: equal elements - * may be reordered as a result of the sort. - * - *

Implementation note: 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(Object[]) - * Arrays.sort} method. The algorithm requires a working space equal to the - * size of the original array. The {@link - * java.util.concurrent.ForkJoinPool#commonPool() ForkJoin common pool} is - * used to execute any parallel tasks. - * - * @param a the array to be sorted - * - * @throws ClassCastException if the array contains elements that are not - * mutually comparable (for example, strings and integers) - * @throws IllegalArgumentException (optional) if the natural - * ordering of the array elements is found to violate the - * {@link Comparable} contract - * - * @since 1.8 - */ - public static > void parallelSort(T[] a) { - parallelSort(a, 0, a.length); - } - - /** - * Sorts the specified range of the specified array of objects into - * ascending order, according to the - * {@linkplain Comparable natural ordering} of its - * elements. The range to be sorted extends from index - * {@code fromIndex}, inclusive, to index {@code toIndex}, exclusive. - * (If {@code fromIndex==toIndex}, the range to be sorted is empty.) All - * elements in this range must implement the {@link Comparable} - * interface. Furthermore, all elements in this range must be mutually - * comparable (that is, {@code e1.compareTo(e2)} must not throw a - * {@code ClassCastException} for any elements {@code e1} and - * {@code e2} in the array). - * - *

This sort is not guaranteed to be stable: equal elements - * may be reordered as a result of the sort. - * - *

Implementation note: 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(Object[]) - * Arrays.sort} method. The algorithm requires a working space equal to the - * size of the original array. The {@link - * java.util.concurrent.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} or - * (optional) if the natural ordering of the array elements is - * found to violate the {@link Comparable} contract - * @throws ArrayIndexOutOfBoundsException if {@code fromIndex < 0} or - * {@code toIndex > a.length} - * @throws ClassCastException if the array contains elements that are - * not mutually comparable (for example, strings and - * integers). - * - * @since 1.8 - */ - public static > - void parallelSort(T[] a, int fromIndex, int toIndex) { - rangeCheck(a.length, fromIndex, toIndex); - int nelements = toIndex - fromIndex; - Class tc = a.getClass().getComponentType(); - @SuppressWarnings("unchecked") - T[] workspace = (T[])Array.newInstance(tc, a.length); - int gran = getSplitThreshold(nelements); - FJComparable.Sorter task = new FJComparable.Sorter<>(a, workspace, - fromIndex, - nelements, gran); - task.invoke(); - } - - /** - * Sorts the specified array of objects according to the order induced by - * the specified comparator. All elements in the array must be - * mutually comparable by the specified comparator (that is, - * {@code c.compare(e1, e2)} must not throw a {@code ClassCastException} - * for any elements {@code e1} and {@code e2} in the array). - * - *

This sort is not guaranteed to be stable: equal elements - * may be reordered as a result of the sort. - * - *

Implementation note: 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(Object[]) - * Arrays.sort} method. The algorithm requires a working space equal to the - * size of the original array. The {@link - * java.util.concurrent.ForkJoinPool#commonPool() ForkJoin common pool} is - * used to execute any parallel tasks. - * - * @param a the array to be sorted - * @param c the comparator to determine the order of the array. A - * {@code null} value indicates that the elements' - * {@linkplain Comparable natural ordering} should be used. - * @throws ClassCastException if the array contains elements that are - * not mutually comparable using the specified comparator - * @throws IllegalArgumentException (optional) if the comparator is - * found to violate the {@link java.util.Comparator} contract - * - * @since 1.8 - */ - public static void parallelSort(T[] a, Comparator c) { - parallelSort(a, 0, a.length, c); - } - - /** - * Sorts the specified range of the specified array of objects according - * to the order induced by the specified comparator. The range to be - * sorted extends from index {@code fromIndex}, inclusive, to index - * {@code toIndex}, exclusive. (If {@code fromIndex==toIndex}, the - * range to be sorted is empty.) All elements in the range must be - * mutually comparable by the specified comparator (that is, - * {@code c.compare(e1, e2)} must not throw a {@code ClassCastException} - * for any elements {@code e1} and {@code e2} in the range). - * - *

This sort is not guaranteed to be stable: equal elements - * may be reordered as a result of the sort. - * - *

Implementation note: 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(Object[]) - * Arrays.sort} method. The algorithm requires a working space equal to the - * size of the original array. The {@link - * java.util.concurrent.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 - * @param c the comparator to determine the order of the array. A - * {@code null} value indicates that the elements' - * {@linkplain Comparable natural ordering} should be used. - * @throws IllegalArgumentException if {@code fromIndex > toIndex} or - * (optional) if the natural ordering of the array elements is - * found to violate the {@link Comparable} contract - * @throws ArrayIndexOutOfBoundsException if {@code fromIndex < 0} or - * {@code toIndex > a.length} - * @throws ClassCastException if the array contains elements that are - * not mutually comparable (for example, strings and - * integers). - * - * @since 1.8 - */ - public static void parallelSort(T[] a, int fromIndex, int toIndex, - Comparator c) { - rangeCheck(a.length, fromIndex, toIndex); - int nelements = toIndex - fromIndex; - Class tc = a.getClass().getComponentType(); - @SuppressWarnings("unchecked") - T[] workspace = (T[])Array.newInstance(tc, a.length); - int gran = getSplitThreshold(nelements); - FJComparator.Sorter task = new FJComparator.Sorter<>(a, workspace, - fromIndex, - nelements, gran, c); - task.invoke(); - } - - /** - * Returns the size threshold for splitting into subtasks. - * By default, uses about 8 times as many tasks as threads - * - * @param n number of elements in the array to be processed - */ - private static int getSplitThreshold(int n) { - int p = java.util.concurrent.ForkJoinPool.getCommonPoolParallelism(); - int t = (p > 1) ? (1 + n / (p << 3)) : n; - return t < MIN_ARRAY_SORT_GRAN ? MIN_ARRAY_SORT_GRAN : t; - } - - /** - * Checks that {@code fromIndex} and {@code toIndex} are in - * the range and throws an appropriate exception, if they aren't. - */ - private static void rangeCheck(int length, int fromIndex, int toIndex) { - if (fromIndex > toIndex) { - throw new IllegalArgumentException( - "fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")"); - } - if (fromIndex < 0) { - throw new ArrayIndexOutOfBoundsException(fromIndex); - } - if (toIndex > length) { - throw new ArrayIndexOutOfBoundsException(toIndex); - } - } - // Searching /** diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/src/share/classes/java/util/ArraysParallelSortHelpers.java --- a/jdk/src/share/classes/java/util/ArraysParallelSortHelpers.java Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/src/share/classes/java/util/ArraysParallelSortHelpers.java Wed Jun 05 00:37:11 2013 -0700 @@ -25,6 +25,7 @@ package java.util; import java.util.concurrent.RecursiveAction; +import java.util.concurrent.CountedCompleter; /** * Helper utilities for the parallel sort methods in Arrays.parallelSort. @@ -44,1180 +45,966 @@ * c. merge them together * 3. merge together the two halves. * - * One reason for splitting in quarters is that this guarantees - * that the final sort is in the main array, not the workspace - * array. (workspace and main swap roles on each subsort step.) - * Leaf-level sorts use a Sequential quicksort, that in turn uses - * insertion sort if under threshold. Otherwise it uses median of - * three to pick pivot, and loops rather than recurses along left - * path. - * + * One reason for splitting in quarters is that this guarantees that + * the final sort is in the main array, not the workspace array. + * (workspace and main swap roles on each subsort step.) Leaf-level + * sorts use the associated sequential sort. * - * Merger classes perform merging for Sorter. If big enough, splits Left - * partition in half; finds the greatest point in Right partition - * less than the beginning of the second half of Left via binary - * search; and then, in parallel, merges left half of Left with - * elements of Right up to split point, and merges right half of - * Left with elements of R past split point. At leaf, it just - * sequentially merges. This is all messy to code; sadly we need - * distinct versions for each type. + * Merger classes perform merging for Sorter. They are structured + * such that if the underlying sort is stable (as is true for + * TimSort), then so is the full sort. If big enough, they split the + * largest of the two partitions in half, find the greatest point in + * smaller partition less than the beginning of the second half of + * larger via binary search; and then merge in parallel the two + * partitions. In part to ensure tasks are triggered in + * stability-preserving order, the current CountedCompleter design + * requires some little tasks to serve as place holders for triggering + * completion tasks. These classes (EmptyCompleter and Relay) don't + * 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.) */ /*package*/ class ArraysParallelSortHelpers { - // RFE: we should only need a working array as large as the subarray - // to be sorted, but the logic assumes that indices in the two - // arrays always line-up + /* + * Style note: The task classes have a lot of parameters, that are + * stored as task fields and copied to local variables and used in + * compute() methods, We pack these into as few lines as possible, + * and hoist consistency checks among them before main loops, to + * reduce distraction. + */ - /** byte support class */ - static final class FJByte { - static final class Sorter extends RecursiveAction { - static final long serialVersionUID = 749471161188027634L; - final byte[] a; // array to be sorted. - final byte[] w; // workspace for merge - final int origin; // origin of the part of array we deal with - final int n; // Number of elements in (sub)arrays. - final int gran; // split control + /** + * A placeholder task for Sorters, used for the lowest + * quartile task, that does not need to maintain array state. + */ + static final class EmptyCompleter extends CountedCompleter { + static final long serialVersionUID = 2446542900576103244L; + EmptyCompleter(CountedCompleter p) { super(p); } + public final void compute() { } + } - Sorter(byte[] a, byte[] w, int origin, int n, int gran) { - this.a = a; - this.w = w; - this.origin = origin; - this.n = n; - this.gran = gran; - } + /** + * A trigger for secondary merge of two merges + */ + static final class Relay extends CountedCompleter { + static final long serialVersionUID = 2446542900576103244L; + final CountedCompleter task; + Relay(CountedCompleter task) { + super(null, 1); + this.task = task; + } + public final void compute() { } + public final void onCompletion(CountedCompleter t) { + task.compute(); + } + } - public void compute() { - final int l = origin; - final int g = gran; - final int n = this.n; - final byte[] a = this.a; - final byte[] w = this.w; - if (n > g) { - int h = n >>> 1; // half - int q = n >>> 2; // lower quarter index - int u = h + q; // upper quarter - FJSubSorter ls = new FJSubSorter(new Sorter(a, w, l, q, g), - new Sorter(a, w, l+q, h-q, g), - new Merger(a, w, l, q, - l+q, h-q, l, g, null)); - FJSubSorter rs = new FJSubSorter(new Sorter(a, w, l+h, q, g), - new Sorter(a, w, l+u, n-u, g), - new Merger(a, w, l+h, q, - l+u, n-u, l+h, g, null)); - rs.fork(); - ls.compute(); - if (rs.tryUnfork()) rs.compute(); else rs.join(); - new Merger(w, a, l, h, - l+h, n-h, l, g, null).compute(); - } else { - DualPivotQuicksort.sort(a, l, l+n-1); //skip rangeCheck + /** Object + Comparator support class */ + static final class FJObject { + static final class Sorter extends CountedCompleter { + static final long serialVersionUID = 2446542900576103244L; + final T[] a, w; + final int base, size, wbase, gran; + Comparator comparator; + Sorter(CountedCompleter par, T[] a, T[] w, int base, int size, + int wbase, int gran, + Comparator comparator) { + super(par); + this.a = a; this.w = w; this.base = base; this.size = size; + this.wbase = wbase; this.gran = gran; + this.comparator = comparator; + } + public final void compute() { + CountedCompleter s = this; + Comparator c = this.comparator; + T[] 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, c)); + 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();; + 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(); + s = new EmptyCompleter(bc); + n = q; } + TimSort.sort(a, b, b + n, c, w, wb, n); + s.tryComplete(); } } - static final class Merger extends RecursiveAction { - static final long serialVersionUID = -9090258248781844470L; - final byte[] a; - final byte[] w; - final int lo; - final int ln; - final int ro; - final int rn; - final int wo; - final int gran; - final Merger next; + static final class Merger extends CountedCompleter { + static final long serialVersionUID = 2446542900576103244L; + final T[] a, w; // main and workspace arrays + final int lbase, lsize, rbase, rsize, wbase, gran; + Comparator comparator; + Merger(CountedCompleter par, T[] a, T[] w, + int lbase, int lsize, int rbase, + int rsize, int wbase, int gran, + Comparator comparator) { + 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; + this.comparator = comparator; + } - Merger(byte[] a, byte[] w, int lo, int ln, int ro, int rn, int wo, - int gran, Merger next) { - this.a = a; - this.w = w; - this.lo = lo; - this.ln = ln; - this.ro = ro; - this.rn = rn; - this.wo = wo; - this.gran = gran; - this.next = next; + public final void compute() { + Comparator c = this.comparator; + T[] 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 || + c == null) + throw new IllegalStateException(); // hoist checks + for (int lh, rh;;) { // split larger, find point in smaller + if (ln >= rn) { + if (ln <= g) + break; + rh = rn; + T split = a[(lh = ln >>> 1) + lb]; + for (int lo = 0; lo < rh; ) { + int rm = (lo + rh) >>> 1; + if (c.compare(split, a[rm + rb]) <= 0) + rh = rm; + else + lo = rm + 1; + } + } + else { + if (rn <= g) + break; + lh = ln; + T split = a[(rh = rn >>> 1) + rb]; + for (int lo = 0; lo < lh; ) { + int lm = (lo + lh) >>> 1; + if (c.compare(split, a[lm + lb]) <= 0) + 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, c); + rn = rh; + ln = lh; + addToPendingCount(1); + m.fork(); + } + + int lf = lb + ln, rf = rb + rn; // index bounds + while (lb < lf && rb < rf) { + T t, al, ar; + if (c.compare((al = a[lb]), (ar = a[rb])) <= 0) { + 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(); } - public void compute() { - final byte[] a = this.a; - final byte[] w = this.w; - Merger rights = null; - int nleft = ln; - int nright = rn; - while (nleft > gran) { - int lh = nleft >>> 1; - int splitIndex = lo + lh; - byte split = a[splitIndex]; - int rl = 0; - int rh = nright; - while (rl < rh) { - int mid = (rl + rh) >>> 1; - if (split <= a[ro + mid]) - rh = mid; - else - rl = mid + 1; + } + } // FJObject + + /** byte support class */ + static final class FJByte { + static final class Sorter extends CountedCompleter { + 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 { + 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; + } } - (rights = new Merger(a, w, splitIndex, nleft-lh, ro+rh, - nright-rh, wo+lh+rh, gran, rights)).fork(); - nleft = lh; - nright = rh; + 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 l = lo; - int lFence = l + nleft; - int r = ro; - int rFence = r + nright; - int k = wo; - while (l < lFence && r < rFence) { - byte al = a[l]; - byte ar = a[r]; - byte t; - if (al <= ar) {++l; t=al;} else {++r; t = ar;} + 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; } - while (l < lFence) - w[k++] = a[l++]; - while (r < rFence) - w[k++] = a[r++]; - while (rights != null) { - if (rights.tryUnfork()) - rights.compute(); - else - rights.join(); - rights = rights.next; - } + 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 RecursiveAction { - static final long serialVersionUID = 8723376019074596641L; - final char[] a; // array to be sorted. - final char[] w; // workspace for merge - final int origin; // origin of the part of array we deal with - final int n; // Number of elements in (sub)arrays. - final int gran; // split control - - Sorter(char[] a, char[] w, int origin, int n, int gran) { - this.a = a; - this.w = w; - this.origin = origin; - this.n = n; - this.gran = gran; + static final class Sorter extends CountedCompleter { + 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 void compute() { - final int l = origin; - final int g = gran; - final int n = this.n; - final char[] a = this.a; - final char[] w = this.w; - if (n > g) { - int h = n >>> 1; // half - int q = n >>> 2; // lower quarter index - int u = h + q; // upper quarter - FJSubSorter ls = new FJSubSorter(new Sorter(a, w, l, q, g), - new Sorter(a, w, l+q, h-q, g), - new Merger(a, w, l, q, - l+q, h-q, l, g, null)); - FJSubSorter rs = new FJSubSorter(new Sorter(a, w, l + h, q, g), - new Sorter(a, w, l+u, n-u, g), - new Merger(a, w, l+h, q, - l+u, n-u, l+h, g, null)); - rs.fork(); - ls.compute(); - if (rs.tryUnfork()) rs.compute(); else rs.join(); - new Merger(w, a, l, h, l + h, n - h, l, g, null).compute(); - } else { - DualPivotQuicksort.sort(a, l, l+n-1); // skip rangeCheck + 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 RecursiveAction { - static final long serialVersionUID = -1383975444621698926L; - final char[] a; - final char[] w; - final int lo; - final int ln; - final int ro; - final int rn; - final int wo; - final int gran; - final Merger next; - - Merger(char[] a, char[] w, int lo, int ln, int ro, int rn, int wo, - int gran, Merger next) { - this.a = a; - this.w = w; - this.lo = lo; - this.ln = ln; - this.ro = ro; - this.rn = rn; - this.wo = wo; - this.gran = gran; - this.next = next; + static final class Merger extends CountedCompleter { + 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 void compute() { - final char[] a = this.a; - final char[] w = this.w; - Merger rights = null; - int nleft = ln; - int nright = rn; - while (nleft > gran) { - int lh = nleft >>> 1; - int splitIndex = lo + lh; - char split = a[splitIndex]; - int rl = 0; - int rh = nright; - while (rl < rh) { - int mid = (rl + rh) >>> 1; - if (split <= a[ro + mid]) - rh = mid; - else - rl = mid + 1; + 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; + } } - (rights = new Merger(a, w, splitIndex, nleft-lh, ro+rh, - nright-rh, wo+lh+rh, gran, rights)).fork(); - nleft = lh; - nright = rh; + 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 l = lo; - int lFence = l + nleft; - int r = ro; - int rFence = r + nright; - int k = wo; - while (l < lFence && r < rFence) { - char al = a[l]; - char ar = a[r]; - char t; - if (al <= ar) {++l; t=al;} else {++r; t = ar;} + 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; } - while (l < lFence) - w[k++] = a[l++]; - while (r < rFence) - w[k++] = a[r++]; - while (rights != null) { - if (rights.tryUnfork()) - rights.compute(); - else - rights.join(); - rights = rights.next; - } + 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 RecursiveAction { - static final long serialVersionUID = -7886754793730583084L; - final short[] a; // array to be sorted. - final short[] w; // workspace for merge - final int origin; // origin of the part of array we deal with - final int n; // Number of elements in (sub)arrays. - final int gran; // split control - - Sorter(short[] a, short[] w, int origin, int n, int gran) { - this.a = a; - this.w = w; - this.origin = origin; - this.n = n; - this.gran = gran; + static final class Sorter extends CountedCompleter { + 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 void compute() { - final int l = origin; - final int g = gran; - final int n = this.n; - final short[] a = this.a; - final short[] w = this.w; - if (n > g) { - int h = n >>> 1; // half - int q = n >>> 2; // lower quarter index - int u = h + q; // upper quarter - FJSubSorter ls = new FJSubSorter(new Sorter(a, w, l, q, g), - new Sorter(a, w, l+q, h-q, g), - new Merger(a, w, l, q, - l+q, h-q, l, g, null)); - FJSubSorter rs = new FJSubSorter(new Sorter(a, w, l + h, q, g), - new Sorter(a, w, l+u, n-u, g), - new Merger(a, w, l+h, q, - l+u, n-u, l+h, g, null)); - rs.fork(); - ls.compute(); - if (rs.tryUnfork()) rs.compute(); else rs.join(); - new Merger(w, a, l, h, l + h, n - h, l, g, null).compute(); - } else { - DualPivotQuicksort.sort(a, l, l+n-1); // skip rangeCheck + 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 RecursiveAction { - static final long serialVersionUID = 3895749408536700048L; - final short[] a; - final short[] w; - final int lo; - final int ln; - final int ro; - final int rn; - final int wo; - final int gran; - final Merger next; - - Merger(short[] a, short[] w, int lo, int ln, int ro, int rn, int wo, - int gran, Merger next) { - this.a = a; - this.w = w; - this.lo = lo; - this.ln = ln; - this.ro = ro; - this.rn = rn; - this.wo = wo; - this.gran = gran; - this.next = next; + static final class Merger extends CountedCompleter { + 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 void compute() { - final short[] a = this.a; - final short[] w = this.w; - Merger rights = null; - int nleft = ln; - int nright = rn; - while (nleft > gran) { - int lh = nleft >>> 1; - int splitIndex = lo + lh; - short split = a[splitIndex]; - int rl = 0; - int rh = nright; - while (rl < rh) { - int mid = (rl + rh) >>> 1; - if (split <= a[ro + mid]) - rh = mid; - else - rl = mid + 1; + 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; + } } - (rights = new Merger(a, w, splitIndex, nleft-lh, ro+rh, - nright-rh, wo+lh+rh, gran, rights)).fork(); - nleft = lh; - nright = rh; + 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 l = lo; - int lFence = l + nleft; - int r = ro; - int rFence = r + nright; - int k = wo; - while (l < lFence && r < rFence) { - short al = a[l]; - short ar = a[r]; - short t; - if (al <= ar) {++l; t=al;} else {++r; t = ar;} + 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; } - while (l < lFence) - w[k++] = a[l++]; - while (r < rFence) - w[k++] = a[r++]; - while (rights != null) { - if (rights.tryUnfork()) - rights.compute(); - else - rights.join(); - rights = rights.next; - } + 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 RecursiveAction { - static final long serialVersionUID = 4263311808957292729L; - final int[] a; // array to be sorted. - final int[] w; // workspace for merge - final int origin; // origin of the part of array we deal with - final int n; // Number of elements in (sub)arrays. - final int gran; // split control - - Sorter(int[] a, int[] w, int origin, int n, int gran) { - this.a = a; - this.w = w; - this.origin = origin; - this.n = n; - this.gran = gran; + static final class Sorter extends CountedCompleter { + 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 void compute() { - final int l = origin; - final int g = gran; - final int n = this.n; - final int[] a = this.a; - final int[] w = this.w; - if (n > g) { - int h = n >>> 1; // half - int q = n >>> 2; // lower quarter index - int u = h + q; // upper quarter - FJSubSorter ls = new FJSubSorter(new Sorter(a, w, l, q, g), - new Sorter(a, w, l+q, h-q, g), - new Merger(a, w, l, q, - l+q, h-q, l, g, null)); - FJSubSorter rs = new FJSubSorter(new Sorter(a, w, l + h, q, g), - new Sorter(a, w, l+u, n-u, g), - new Merger(a, w, l+h, q, - l+u, n-u, l+h, g, null)); - rs.fork(); - ls.compute(); - if (rs.tryUnfork()) rs.compute(); else rs.join(); - new Merger(w, a, l, h, l + h, n - h, l, g, null).compute(); - } else { - DualPivotQuicksort.sort(a, l, l+n-1); // skip rangeCheck + 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 RecursiveAction { - static final long serialVersionUID = -8727507284219982792L; - final int[] a; - final int[] w; - final int lo; - final int ln; - final int ro; - final int rn; - final int wo; - final int gran; - final Merger next; - - Merger(int[] a, int[] w, int lo, int ln, int ro, int rn, int wo, - int gran, Merger next) { - this.a = a; - this.w = w; - this.lo = lo; - this.ln = ln; - this.ro = ro; - this.rn = rn; - this.wo = wo; - this.gran = gran; - this.next = next; + static final class Merger extends CountedCompleter { + 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 void compute() { - final int[] a = this.a; - final int[] w = this.w; - Merger rights = null; - int nleft = ln; - int nright = rn; - while (nleft > gran) { - int lh = nleft >>> 1; - int splitIndex = lo + lh; - int split = a[splitIndex]; - int rl = 0; - int rh = nright; - while (rl < rh) { - int mid = (rl + rh) >>> 1; - if (split <= a[ro + mid]) - rh = mid; - else - rl = mid + 1; + 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; + } } - (rights = new Merger(a, w, splitIndex, nleft-lh, ro+rh, - nright-rh, wo+lh+rh, gran, rights)).fork(); - nleft = lh; - nright = rh; + 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 l = lo; - int lFence = l + nleft; - int r = ro; - int rFence = r + nright; - int k = wo; - while (l < lFence && r < rFence) { - int al = a[l]; - int ar = a[r]; - int t; - if (al <= ar) {++l; t=al;} else {++r; t = ar;} + 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; } - while (l < lFence) - w[k++] = a[l++]; - while (r < rFence) - w[k++] = a[r++]; - while (rights != null) { - if (rights.tryUnfork()) - rights.compute(); - else - rights.join(); - rights = rights.next; - } + 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 RecursiveAction { - static final long serialVersionUID = 6553695007444392455L; - final long[] a; // array to be sorted. - final long[] w; // workspace for merge - final int origin; // origin of the part of array we deal with - final int n; // Number of elements in (sub)arrays. - final int gran; // split control - - Sorter(long[] a, long[] w, int origin, int n, int gran) { - this.a = a; - this.w = w; - this.origin = origin; - this.n = n; - this.gran = gran; + static final class Sorter extends CountedCompleter { + 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 void compute() { - final int l = origin; - final int g = gran; - final int n = this.n; - final long[] a = this.a; - final long[] w = this.w; - if (n > g) { - int h = n >>> 1; // half - int q = n >>> 2; // lower quarter index - int u = h + q; // upper quarter - FJSubSorter ls = new FJSubSorter(new Sorter(a, w, l, q, g), - new Sorter(a, w, l+q, h-q, g), - new Merger(a, w, l, q, - l+q, h-q, l, g, null)); - FJSubSorter rs = new FJSubSorter(new Sorter(a, w, l + h, q, g), - new Sorter(a, w, l+u, n-u, g), - new Merger(a, w, l+h, q, - l+u, n-u, l+h, g, null)); - rs.fork(); - ls.compute(); - if (rs.tryUnfork()) rs.compute(); else rs.join(); - new Merger(w, a, l, h, l + h, n - h, l, g, null).compute(); - } else { - DualPivotQuicksort.sort(a, l, l+n-1); // skip rangeCheck + 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 RecursiveAction { - static final long serialVersionUID = 8843567516333283861L; - final long[] a; - final long[] w; - final int lo; - final int ln; - final int ro; - final int rn; - final int wo; - final int gran; - final Merger next; - - Merger(long[] a, long[] w, int lo, int ln, int ro, int rn, int wo, - int gran, Merger next) { - this.a = a; - this.w = w; - this.lo = lo; - this.ln = ln; - this.ro = ro; - this.rn = rn; - this.wo = wo; - this.gran = gran; - this.next = next; + static final class Merger extends CountedCompleter { + 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 void compute() { - final long[] a = this.a; - final long[] w = this.w; - Merger rights = null; - int nleft = ln; - int nright = rn; - while (nleft > gran) { - int lh = nleft >>> 1; - int splitIndex = lo + lh; - long split = a[splitIndex]; - int rl = 0; - int rh = nright; - while (rl < rh) { - int mid = (rl + rh) >>> 1; - if (split <= a[ro + mid]) - rh = mid; - else - rl = mid + 1; + 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; + } } - (rights = new Merger(a, w, splitIndex, nleft-lh, ro+rh, - nright-rh, wo+lh+rh, gran, rights)).fork(); - nleft = lh; - nright = rh; + 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 l = lo; - int lFence = l + nleft; - int r = ro; - int rFence = r + nright; - int k = wo; - while (l < lFence && r < rFence) { - long al = a[l]; - long ar = a[r]; - long t; - if (al <= ar) {++l; t=al;} else {++r; t = ar;} + 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; } - while (l < lFence) - w[k++] = a[l++]; - while (r < rFence) - w[k++] = a[r++]; - while (rights != null) { - if (rights.tryUnfork()) - rights.compute(); - else - rights.join(); - rights = rights.next; - } + 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 RecursiveAction { - static final long serialVersionUID = 1602600178202763377L; - final float[] a; // array to be sorted. - final float[] w; // workspace for merge - final int origin; // origin of the part of array we deal with - final int n; // Number of elements in (sub)arrays. - final int gran; // split control - - Sorter(float[] a, float[] w, int origin, int n, int gran) { - this.a = a; - this.w = w; - this.origin = origin; - this.n = n; - this.gran = gran; + static final class Sorter extends CountedCompleter { + 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 void compute() { - final int l = origin; - final int g = gran; - final int n = this.n; - final float[] a = this.a; - final float[] w = this.w; - if (n > g) { - int h = n >>> 1; // half - int q = n >>> 2; // lower quarter index - int u = h + q; // upper quarter - FJSubSorter ls = new FJSubSorter(new Sorter(a, w, l, q, g), - new Sorter(a, w, l+q, h-q, g), - new Merger(a, w, l, q, - l+q, h-q, l, g, null)); - FJSubSorter rs = new FJSubSorter(new Sorter(a, w, l + h, q, g), - new Sorter(a, w, l+u, n-u, g), - new Merger(a, w, l+h, q, - l+u, n-u, l+h, g, null)); - rs.fork(); - ls.compute(); - if (rs.tryUnfork()) rs.compute(); else rs.join(); - new Merger(w, a, l, h, l + h, n - h, l, g, null).compute(); - } else { - DualPivotQuicksort.sort(a, l, l+n-1); // skip rangeCheck + 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 RecursiveAction { - static final long serialVersionUID = 1518176433845397426L; - final float[] a; - final float[] w; - final int lo; - final int ln; - final int ro; - final int rn; - final int wo; - final int gran; - final Merger next; - - Merger(float[] a, float[] w, int lo, int ln, int ro, int rn, int wo, - int gran, Merger next) { - this.a = a; - this.w = w; - this.lo = lo; - this.ln = ln; - this.ro = ro; - this.rn = rn; - this.wo = wo; - this.gran = gran; - this.next = next; + static final class Merger extends CountedCompleter { + 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 void compute() { - final float[] a = this.a; - final float[] w = this.w; - Merger rights = null; - int nleft = ln; - int nright = rn; - while (nleft > gran) { - int lh = nleft >>> 1; - int splitIndex = lo + lh; - float split = a[splitIndex]; - int rl = 0; - int rh = nright; - while (rl < rh) { - int mid = (rl + rh) >>> 1; - if (Float.compare(split, a[ro+mid]) <= 0) - rh = mid; - else - rl = mid + 1; + 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; + } } - (rights = new Merger(a, w, splitIndex, nleft-lh, ro+rh, - nright-rh, wo+lh+rh, gran, rights)).fork(); - nleft = lh; - nright = rh; + 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 l = lo; - int lFence = l + nleft; - int r = ro; - int rFence = r + nright; - int k = wo; - while (l < lFence && r < rFence) { - float al = a[l]; - float ar = a[r]; - float t; - if (Float.compare(al, ar) <= 0) { - ++l; - t = al; - } else { - ++r; - t = ar; + 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; } - while (l < lFence) - w[k++] = a[l++]; - while (r < rFence) - w[k++] = a[r++]; - while (rights != null) { - if (rights.tryUnfork()) - rights.compute(); - else - rights.join(); - rights = rights.next; - } + 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 RecursiveAction { + static final class Sorter extends CountedCompleter { static final long serialVersionUID = 2446542900576103244L; - final double[] a; // array to be sorted. - final double[] w; // workspace for merge - final int origin; // origin of the part of array we deal with - final int n; // Number of elements in (sub)arrays. - final int gran; // split control - - Sorter(double[] a, double[] w, int origin, int n, int gran) { - this.a = a; - this.w = w; - this.origin = origin; - this.n = n; - this.gran = gran; + 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 void compute() { - final int l = origin; - final int g = gran; - final int n = this.n; - final double[] a = this.a; - final double[] w = this.w; - if (n > g) { - int h = n >>> 1; // half - int q = n >>> 2; // lower quarter index - int u = h + q; // upper quarter - FJSubSorter ls = new FJSubSorter(new Sorter(a, w, l, q, g), - new Sorter(a, w, l+q, h-q, g), - new Merger(a, w, l, q, - l+q, h-q, l, g, null)); - FJSubSorter rs = new FJSubSorter(new Sorter(a, w, l + h, q, g), - new Sorter(a, w, l+u, n-u, g), - new Merger(a, w, l+h, q, - l+u, n-u, l+h, g, null)); - rs.fork(); - ls.compute(); - if (rs.tryUnfork()) rs.compute(); else rs.join(); - new Merger(w, a, l, h, l + h, n - h, l, g, null).compute(); - } else { - DualPivotQuicksort.sort(a, l, l+n-1); // skip rangeCheck + 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 RecursiveAction { - static final long serialVersionUID = 8076242187166127592L; - final double[] a; - final double[] w; - final int lo; - final int ln; - final int ro; - final int rn; - final int wo; - final int gran; - final Merger next; - - Merger(double[] a, double[] w, int lo, int ln, int ro, int rn, int wo, - int gran, Merger next) { - this.a = a; - this.w = w; - this.lo = lo; - this.ln = ln; - this.ro = ro; - this.rn = rn; - this.wo = wo; - this.gran = gran; - this.next = next; + static final class Merger extends CountedCompleter { + 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 void compute() { - final double[] a = this.a; - final double[] w = this.w; - Merger rights = null; - int nleft = ln; - int nright = rn; - while (nleft > gran) { - int lh = nleft >>> 1; - int splitIndex = lo + lh; - double split = a[splitIndex]; - int rl = 0; - int rh = nright; - while (rl < rh) { - int mid = (rl + rh) >>> 1; - if (Double.compare(split, a[ro+mid]) <= 0) - rh = mid; - else - rl = mid + 1; + 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; + } } - (rights = new Merger(a, w, splitIndex, nleft-lh, ro+rh, - nright-rh, wo+lh+rh, gran, rights)).fork(); - nleft = lh; - nright = rh; + 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 l = lo; - int lFence = l + nleft; - int r = ro; - int rFence = r + nright; - int k = wo; - while (l < lFence && r < rFence) { - double al = a[l]; - double ar = a[r]; - double t; - if (Double.compare(al, ar) <= 0) { - ++l; - t = al; - } else { - ++r; - t = ar; + 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; } - while (l < lFence) - w[k++] = a[l++]; - while (r < rFence) - w[k++] = a[r++]; - while (rights != null) { - if (rights.tryUnfork()) - rights.compute(); - else - rights.join(); - rights = rights.next; - } + 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 - /** Comparable support class */ - static final class FJComparable { - static final class Sorter> extends RecursiveAction { - static final long serialVersionUID = -1024003289463302522L; - final T[] a; - final T[] w; - final int origin; - final int n; - final int gran; - - Sorter(T[] a, T[] w, int origin, int n, int gran) { - this.a = a; - this.w = w; - this.origin = origin; - this.n = n; - this.gran = gran; - } - - public void compute() { - final int l = origin; - final int g = gran; - final int n = this.n; - final T[] a = this.a; - final T[] w = this.w; - if (n > g) { - int h = n >>> 1; - int q = n >>> 2; - int u = h + q; - FJSubSorter ls = new FJSubSorter(new Sorter<>(a, w, l, q, g), - new Sorter<>(a, w, l+q, h-q, g), - new Merger<>(a, w, l, q, - l+q, h-q, l, g, null)); - FJSubSorter rs = new FJSubSorter(new Sorter<>(a, w, l+h, q, g), - new Sorter<>(a, w, l+u, n-u, g), - new Merger<>(a, w, l+h, q, - l+u, n-u, l+h, g, null)); - rs.fork(); - ls.compute(); - if (rs.tryUnfork()) rs.compute(); else rs.join(); - new Merger<>(w, a, l, h, l + h, n - h, l, g, null).compute(); - } else { - Arrays.sort(a, l, l+n); - } - } - } - - static final class Merger> extends RecursiveAction { - static final long serialVersionUID = -3989771675258379302L; - final T[] a; - final T[] w; - final int lo; - final int ln; - final int ro; - final int rn; - final int wo; - final int gran; - final Merger next; - - Merger(T[] a, T[] w, int lo, int ln, int ro, int rn, int wo, - int gran, Merger next) { - this.a = a; - this.w = w; - this.lo = lo; - this.ln = ln; - this.ro = ro; - this.rn = rn; - this.wo = wo; - this.gran = gran; - this.next = next; - } - - public void compute() { - final T[] a = this.a; - final T[] w = this.w; - Merger rights = null; - int nleft = ln; - int nright = rn; - while (nleft > gran) { - int lh = nleft >>> 1; - int splitIndex = lo + lh; - T split = a[splitIndex]; - int rl = 0; - int rh = nright; - while (rl < rh) { - int mid = (rl + rh) >>> 1; - if (split.compareTo(a[ro + mid]) <= 0) - rh = mid; - else - rl = mid + 1; - } - (rights = new Merger<>(a, w, splitIndex, nleft-lh, ro+rh, - nright-rh, wo+lh+rh, gran, rights)).fork(); - nleft = lh; - nright = rh; - } - - int l = lo; - int lFence = l + nleft; - int r = ro; - int rFence = r + nright; - int k = wo; - while (l < lFence && r < rFence) { - T al = a[l]; - T ar = a[r]; - T t; - if (al.compareTo(ar) <= 0) {++l; t=al;} else {++r; t=ar; } - w[k++] = t; - } - while (l < lFence) - w[k++] = a[l++]; - while (r < rFence) - w[k++] = a[r++]; - while (rights != null) { - if (rights.tryUnfork()) - rights.compute(); - else - rights.join(); - rights = rights.next; - } - } - } - } // FJComparable - - /** Object + Comparator support class */ - static final class FJComparator { - static final class Sorter extends RecursiveAction { - static final long serialVersionUID = 9191600840025808581L; - final T[] a; // array to be sorted. - final T[] w; // workspace for merge - final int origin; // origin of the part of array we deal with - final int n; // Number of elements in (sub)arrays. - final int gran; // split control - final Comparator cmp; // Comparator to use - - Sorter(T[] a, T[] w, int origin, int n, int gran, Comparator cmp) { - this.a = a; - this.w = w; - this.origin = origin; - this.n = n; - this.cmp = cmp; - this.gran = gran; - } - - public void compute() { - final int l = origin; - final int g = gran; - final int n = this.n; - final T[] a = this.a; - final T[] w = this.w; - if (n > g) { - int h = n >>> 1; // half - int q = n >>> 2; // lower quarter index - int u = h + q; // upper quarter - FJSubSorter ls = new FJSubSorter(new Sorter<>(a, w, l, q, g, cmp), - new Sorter<>(a, w, l+q, h-q, g, cmp), - new Merger<>(a, w, l, q, - l+q, h-q, l, g, null, cmp)); - FJSubSorter rs = new FJSubSorter(new Sorter<>(a, w, l + h, q, g, cmp), - new Sorter<>(a, w, l+u, n-u, g, cmp), - new Merger<>(a, w, l+h, q, - l+u, n-u, l+h, g, null, cmp)); - rs.fork(); - ls.compute(); - if (rs.tryUnfork()) rs.compute(); else rs.join(); - new Merger<>(w, a, l, h, l + h, n - h, l, g, null, cmp).compute(); - } else { - Arrays.sort(a, l, l+n, cmp); - } - } - } - - static final class Merger extends RecursiveAction { - static final long serialVersionUID = -2679539040379156203L; - final T[] a; - final T[] w; - final int lo; - final int ln; - final int ro; - final int rn; - final int wo; - final int gran; - final Merger next; - final Comparator cmp; - - Merger(T[] a, T[] w, int lo, int ln, int ro, int rn, int wo, - int gran, Merger next, Comparator cmp) { - this.a = a; - this.w = w; - this.lo = lo; - this.ln = ln; - this.ro = ro; - this.rn = rn; - this.wo = wo; - this.gran = gran; - this.next = next; - this.cmp = cmp; - } - - public void compute() { - final T[] a = this.a; - final T[] w = this.w; - Merger rights = null; - int nleft = ln; - int nright = rn; - while (nleft > gran) { - int lh = nleft >>> 1; - int splitIndex = lo + lh; - T split = a[splitIndex]; - int rl = 0; - int rh = nright; - while (rl < rh) { - int mid = (rl + rh) >>> 1; - if (cmp.compare(split, a[ro+mid]) <= 0) - rh = mid; - else - rl = mid + 1; - } - (rights = new Merger<>(a, w, splitIndex, nleft-lh, ro+rh, - nright-rh, wo+lh+rh, gran, rights, cmp)).fork(); - nleft = lh; - nright = rh; - } - - int l = lo; - int lFence = l + nleft; - int r = ro; - int rFence = r + nright; - int k = wo; - while (l < lFence && r < rFence) { - T al = a[l]; - T ar = a[r]; - T t; - if (cmp.compare(al, ar) <= 0) { - ++l; - t = al; - } else { - ++r; - t = ar; - } - w[k++] = t; - } - while (l < lFence) - w[k++] = a[l++]; - while (r < rFence) - w[k++] = a[r++]; - while (rights != null) { - if (rights.tryUnfork()) - rights.compute(); - else - rights.join(); - rights = rights.next; - } - } - } - } // FJComparator - - /** Utility class to sort half a partitioned array */ - private static final class FJSubSorter extends RecursiveAction { - static final long serialVersionUID = 9159249695527935512L; - final RecursiveAction left; - final RecursiveAction right; - final RecursiveAction merger; - - FJSubSorter(RecursiveAction left, RecursiveAction right, - RecursiveAction merger) { - this.left = left; - this.right = right; - this.merger = merger; - } - - public void compute() { - right.fork(); - left.invoke(); - right.join(); - merger.invoke(); - } - } } diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/src/share/classes/java/util/ComparableTimSort.java --- a/jdk/src/share/classes/java/util/ComparableTimSort.java Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/src/share/classes/java/util/ComparableTimSort.java Wed Jun 05 00:37:11 2013 -0700 @@ -86,9 +86,13 @@ private static final int INITIAL_TMP_STORAGE_LENGTH = 256; /** - * Temp storage for merges. + * Temp storage for merges. A workspace array may optionally be + * provided in constructor, and if so will be used as long as it + * is big enough. */ private Object[] tmp; + private int tmpBase; // base of tmp array slice + private int tmpLen; // length of tmp array slice /** * A stack of pending runs yet to be merged. Run i starts at @@ -108,15 +112,27 @@ * Creates a TimSort instance to maintain the state of an ongoing sort. * * @param a the array 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 */ - private ComparableTimSort(Object[] a) { + private ComparableTimSort(Object[] a, Object[] work, int workBase, int workLen) { this.a = a; // Allocate temp storage (which may be increased later if necessary) int len = a.length; - Object[] newArray = new Object[len < 2 * INITIAL_TMP_STORAGE_LENGTH ? - len >>> 1 : INITIAL_TMP_STORAGE_LENGTH]; - tmp = newArray; + int tlen = (len < 2 * INITIAL_TMP_STORAGE_LENGTH) ? + len >>> 1 : INITIAL_TMP_STORAGE_LENGTH; + if (work == null || workLen < tlen || workBase + tlen > work.length) { + tmp = new Object[tlen]; + tmpBase = 0; + tmpLen = tlen; + } + else { + tmp = work; + tmpBase = workBase; + tmpLen = workLen; + } /* * Allocate runs-to-be-merged stack (which cannot be expanded). The @@ -136,17 +152,28 @@ } /* - * The next two methods (which are package private and static) constitute - * the entire API of this class. Each of these methods obeys the contract - * of the public method with the same signature in java.util.Arrays. + * The next method (package private and static) constitutes the + * entire API of this class. */ - static void sort(Object[] a) { - sort(a, 0, a.length); - } + /** + * Sorts the given range, using the given workspace array slice + * for temp storage when possible. This method is designed to be + * invoked from public methods (in class Arrays) after performing + * any necessary array bounds checks and expanding parameters into + * the required forms. + * + * @param a the array to be sorted + * @param lo the index of the first element, inclusive, to be sorted + * @param hi the index of the last element, exclusive, 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 + * @since 1.8 + */ + static void sort(Object[] a, int lo, int hi, Object[] work, int workBase, int workLen) { + assert a != null && lo >= 0 && lo <= hi && hi <= a.length; - static void sort(Object[] a, int lo, int hi) { - rangeCheck(a.length, lo, hi); int nRemaining = hi - lo; if (nRemaining < 2) return; // Arrays of size 0 and 1 are always sorted @@ -163,7 +190,7 @@ * extending short natural runs to minRun elements, and merging runs * to maintain stack invariant. */ - ComparableTimSort ts = new ComparableTimSort(a); + ComparableTimSort ts = new ComparableTimSort(a, work, workBase, workLen); int minRun = minRunLength(nRemaining); do { // Identify next run @@ -619,11 +646,11 @@ // Copy first run into temp array Object[] a = this.a; // For performance Object[] tmp = ensureCapacity(len1); - System.arraycopy(a, base1, tmp, 0, len1); - int cursor1 = 0; // Indexes into tmp array + int cursor1 = tmpBase; // Indexes into tmp array int cursor2 = base2; // Indexes int a int dest = base1; // Indexes int a + System.arraycopy(a, base1, tmp, cursor1, len1); // Move first element of second run and deal with degenerate cases a[dest++] = a[cursor2++]; @@ -736,16 +763,17 @@ // Copy second run into temp array Object[] a = this.a; // For performance Object[] tmp = ensureCapacity(len2); - System.arraycopy(a, base2, tmp, 0, len2); + int tmpBase = this.tmpBase; + System.arraycopy(a, base2, tmp, tmpBase, len2); int cursor1 = base1 + len1 - 1; // Indexes into a - int cursor2 = len2 - 1; // Indexes into tmp array + int cursor2 = tmpBase + len2 - 1; // Indexes into tmp array int dest = base2 + len2 - 1; // Indexes into a // Move last element of first run and deal with degenerate cases a[dest--] = a[cursor1--]; if (--len1 == 0) { - System.arraycopy(tmp, 0, a, dest - (len2 - 1), len2); + System.arraycopy(tmp, tmpBase, a, dest - (len2 - 1), len2); return; } if (len2 == 1) { @@ -803,7 +831,7 @@ if (--len2 == 1) break outer; - count2 = len2 - gallopLeft((Comparable) a[cursor1], tmp, 0, len2, len2 - 1); + count2 = len2 - gallopLeft((Comparable) a[cursor1], tmp, tmpBase, len2, len2 - 1); if (count2 != 0) { dest -= count2; cursor2 -= count2; @@ -835,7 +863,7 @@ } else { assert len1 == 0; assert len2 > 0; - System.arraycopy(tmp, 0, a, dest - (len2 - 1), len2); + System.arraycopy(tmp, tmpBase, a, dest - (len2 - 1), len2); } } @@ -848,7 +876,7 @@ * @return tmp, whether or not it grew */ private Object[] ensureCapacity(int minCapacity) { - if (tmp.length < minCapacity) { + if (tmpLen < minCapacity) { // Compute smallest power of 2 > minCapacity int newSize = minCapacity; newSize |= newSize >> 1; @@ -863,30 +891,13 @@ else newSize = Math.min(newSize, a.length >>> 1); + @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"}) Object[] newArray = new Object[newSize]; tmp = newArray; + tmpLen = newSize; + tmpBase = 0; } return tmp; } - /** - * Checks that fromIndex and toIndex are in range, and throws an - * appropriate exception if they aren't. - * - * @param arrayLen the length of the array - * @param fromIndex the index of the first element of the range - * @param toIndex the index after the last element of the range - * @throws IllegalArgumentException if fromIndex > toIndex - * @throws ArrayIndexOutOfBoundsException if fromIndex < 0 - * or toIndex > arrayLen - */ - private static void rangeCheck(int arrayLen, int fromIndex, int toIndex) { - if (fromIndex > toIndex) - throw new IllegalArgumentException("fromIndex(" + fromIndex + - ") > toIndex(" + toIndex+")"); - if (fromIndex < 0) - throw new ArrayIndexOutOfBoundsException(fromIndex); - if (toIndex > arrayLen) - throw new ArrayIndexOutOfBoundsException(toIndex); - } } diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/src/share/classes/java/util/DualPivotQuicksort.java --- a/jdk/src/share/classes/java/util/DualPivotQuicksort.java Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/src/share/classes/java/util/DualPivotQuicksort.java Wed Jun 05 00:37:11 2013 -0700 @@ -32,6 +32,11 @@ * quicksorts to degrade to quadratic performance, 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. + * * @author Vladimir Yaroslavskiy * @author Jon Bentley * @author Josh Bloch @@ -89,22 +94,18 @@ */ /** - * Sorts the specified array. - * - * @param a the array to be sorted - */ - public static void sort(int[] a) { - sort(a, 0, a.length - 1); - } - - /** - * Sorts the specified range of the array. + * Sorts the specified range of the array using the given + * workspace array slice if possible for merging * * @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 */ - public static void sort(int[] a, int left, int right) { + 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); @@ -147,24 +148,35 @@ } // Check special cases + // Implementation note: variable "right" is increased by 1. if (run[count] == right++) { // The last run contains one element run[++count] = right; } else if (count == 1) { // The array is already sorted return; } - /* - * Create temporary array, which is used for merging. - * Implementation note: variable "right" is increased by 1. - */ - int[] b; byte odd = 0; + // 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) { - b = a; a = new int[b.length]; - for (int i = left - 1; ++i < right; a[i] = b[i]); + System.arraycopy(a, left, work, workBase, blen); + b = a; + bo = 0; + a = work; + ao = workBase - left; } else { - b = new int[a.length]; + b = work; + ao = 0; + bo = workBase - left; } // Merging @@ -172,21 +184,22 @@ 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] <= a[q]) { - b[i] = a[p++]; + if (q >= hi || p < mi && a[p + ao] <= a[q + ao]) { + b[i + bo] = a[p++ + ao]; } else { - b[i] = a[q++]; + 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] = a[i] + b[i + bo] = a[i + ao] ); run[++last] = right; } int[] t = a; a = b; b = t; + int o = ao; ao = bo; bo = o; } } @@ -529,22 +542,18 @@ } /** - * Sorts the specified array. - * - * @param a the array to be sorted - */ - public static void sort(long[] a) { - sort(a, 0, a.length - 1); - } - - /** - * Sorts the specified range of the array. + * Sorts the specified range of the array using the given + * workspace array slice if possible for merging * * @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 */ - public static void sort(long[] a, int left, int right) { + 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); @@ -587,24 +596,35 @@ } // Check special cases + // Implementation note: variable "right" is increased by 1. if (run[count] == right++) { // The last run contains one element run[++count] = right; } else if (count == 1) { // The array is already sorted return; } - /* - * Create temporary array, which is used for merging. - * Implementation note: variable "right" is increased by 1. - */ - long[] b; byte odd = 0; + // 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) { - b = a; a = new long[b.length]; - for (int i = left - 1; ++i < right; a[i] = b[i]); + System.arraycopy(a, left, work, workBase, blen); + b = a; + bo = 0; + a = work; + ao = workBase - left; } else { - b = new long[a.length]; + b = work; + ao = 0; + bo = workBase - left; } // Merging @@ -612,21 +632,22 @@ 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] <= a[q]) { - b[i] = a[p++]; + if (q >= hi || p < mi && a[p + ao] <= a[q + ao]) { + b[i + bo] = a[p++ + ao]; } else { - b[i] = a[q++]; + 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] = a[i] + b[i + bo] = a[i + ao] ); run[++last] = right; } long[] t = a; a = b; b = t; + int o = ao; ao = bo; bo = o; } } @@ -969,22 +990,18 @@ } /** - * Sorts the specified array. - * - * @param a the array to be sorted - */ - public static void sort(short[] a) { - sort(a, 0, a.length - 1); - } - - /** - * Sorts the specified range of the array. + * Sorts the specified range of the array using the given + * workspace array slice if possible for merging * * @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 */ - public static void sort(short[] a, int left, int right) { + 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]; @@ -1002,7 +1019,7 @@ } while (--s > 0); } } else { // Use Dual-Pivot Quicksort on small arrays - doSort(a, left, right); + doSort(a, left, right, work, workBase, workLen); } } @@ -1015,8 +1032,12 @@ * @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 */ - private static void doSort(short[] a, int left, int right) { + 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); @@ -1059,24 +1080,35 @@ } // Check special cases + // Implementation note: variable "right" is increased by 1. if (run[count] == right++) { // The last run contains one element run[++count] = right; } else if (count == 1) { // The array is already sorted return; } - /* - * Create temporary array, which is used for merging. - * Implementation note: variable "right" is increased by 1. - */ - short[] b; byte odd = 0; + // 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) { - b = a; a = new short[b.length]; - for (int i = left - 1; ++i < right; a[i] = b[i]); + System.arraycopy(a, left, work, workBase, blen); + b = a; + bo = 0; + a = work; + ao = workBase - left; } else { - b = new short[a.length]; + b = work; + ao = 0; + bo = workBase - left; } // Merging @@ -1084,21 +1116,22 @@ 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] <= a[q]) { - b[i] = a[p++]; + if (q >= hi || p < mi && a[p + ao] <= a[q + ao]) { + b[i + bo] = a[p++ + ao]; } else { - b[i] = a[q++]; + 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] = a[i] + b[i + bo] = a[i + ao] ); run[++last] = right; } short[] t = a; a = b; b = t; + int o = ao; ao = bo; bo = o; } } @@ -1441,22 +1474,18 @@ } /** - * Sorts the specified array. - * - * @param a the array to be sorted - */ - public static void sort(char[] a) { - sort(a, 0, a.length - 1); - } - - /** - * Sorts the specified range of the array. + * Sorts the specified range of the array using the given + * workspace array slice if possible for merging * * @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 */ - public static void sort(char[] a, int left, int right) { + 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]; @@ -1474,7 +1503,7 @@ } while (--s > 0); } } else { // Use Dual-Pivot Quicksort on small arrays - doSort(a, left, right); + doSort(a, left, right, work, workBase, workLen); } } @@ -1487,8 +1516,12 @@ * @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 */ - private static void doSort(char[] a, int left, int right) { + 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); @@ -1531,24 +1564,35 @@ } // Check special cases + // Implementation note: variable "right" is increased by 1. if (run[count] == right++) { // The last run contains one element run[++count] = right; } else if (count == 1) { // The array is already sorted return; } - /* - * Create temporary array, which is used for merging. - * Implementation note: variable "right" is increased by 1. - */ - char[] b; byte odd = 0; + // 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 (odd == 0) { - b = a; a = new char[b.length]; - for (int i = left - 1; ++i < right; a[i] = b[i]); + System.arraycopy(a, left, work, workBase, blen); + b = a; + bo = 0; + a = work; + ao = workBase - left; } else { - b = new char[a.length]; + b = work; + ao = 0; + bo = workBase - left; } // Merging @@ -1556,21 +1600,22 @@ 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] <= a[q]) { - b[i] = a[p++]; + if (q >= hi || p < mi && a[p + ao] <= a[q + ao]) { + b[i + bo] = a[p++ + ao]; } else { - b[i] = a[q++]; + 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] = a[i] + b[i + bo] = a[i + ao] ); run[++last] = right; } char[] t = a; a = b; b = t; + int o = ao; ao = bo; bo = o; } } @@ -1916,22 +1961,13 @@ private static final int NUM_BYTE_VALUES = 1 << 8; /** - * Sorts the specified array. - * - * @param a the array to be sorted - */ - public static void sort(byte[] a) { - sort(a, 0, a.length - 1); - } - - /** * Sorts the specified range of the array. * * @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 */ - public static void sort(byte[] a, int left, int right) { + 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]; @@ -1963,22 +1999,18 @@ } /** - * Sorts the specified array. - * - * @param a the array to be sorted - */ - public static void sort(float[] a) { - sort(a, 0, a.length - 1); - } - - /** - * Sorts the specified range of the array. + * Sorts the specified range of the array using the given + * workspace array slice if possible for merging * * @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 */ - public static void sort(float[] a, int left, int right) { + static void sort(float[] a, int left, int right, + float[] work, int workBase, int workLen) { /* * Phase 1: Move NaNs to the end of the array. */ @@ -1997,7 +2029,7 @@ /* * Phase 2: Sort everything except NaNs (which are already in place). */ - doSort(a, left, right); + doSort(a, left, right, work, workBase, workLen); /* * Phase 3: Place negative zeros before positive zeros. @@ -2064,8 +2096,12 @@ * @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 */ - private static void doSort(float[] a, int left, int right) { + 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); @@ -2108,24 +2144,35 @@ } // Check special cases + // Implementation note: variable "right" is increased by 1. if (run[count] == right++) { // The last run contains one element run[++count] = right; } else if (count == 1) { // The array is already sorted return; } - /* - * Create temporary array, which is used for merging. - * Implementation note: variable "right" is increased by 1. - */ - float[] b; byte odd = 0; + // 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) { - b = a; a = new float[b.length]; - for (int i = left - 1; ++i < right; a[i] = b[i]); + System.arraycopy(a, left, work, workBase, blen); + b = a; + bo = 0; + a = work; + ao = workBase - left; } else { - b = new float[a.length]; + b = work; + ao = 0; + bo = workBase - left; } // Merging @@ -2133,21 +2180,22 @@ 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] <= a[q]) { - b[i] = a[p++]; + if (q >= hi || p < mi && a[p + ao] <= a[q + ao]) { + b[i + bo] = a[p++ + ao]; } else { - b[i] = a[q++]; + 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] = a[i] + b[i + bo] = a[i + ao] ); run[++last] = right; } float[] t = a; a = b; b = t; + int o = ao; ao = bo; bo = o; } } @@ -2490,22 +2538,18 @@ } /** - * Sorts the specified array. - * - * @param a the array to be sorted - */ - public static void sort(double[] a) { - sort(a, 0, a.length - 1); - } - - /** - * Sorts the specified range of the array. + * Sorts the specified range of the array using the given + * workspace array slice if possible for merging * * @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 */ - public static void sort(double[] a, int left, int right) { + static void sort(double[] a, int left, int right, + double[] work, int workBase, int workLen) { /* * Phase 1: Move NaNs to the end of the array. */ @@ -2524,7 +2568,7 @@ /* * Phase 2: Sort everything except NaNs (which are already in place). */ - doSort(a, left, right); + doSort(a, left, right, work, workBase, workLen); /* * Phase 3: Place negative zeros before positive zeros. @@ -2591,8 +2635,12 @@ * @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 */ - private static void doSort(double[] a, int left, int right) { + 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); @@ -2635,24 +2683,35 @@ } // Check special cases + // Implementation note: variable "right" is increased by 1. if (run[count] == right++) { // The last run contains one element run[++count] = right; } else if (count == 1) { // The array is already sorted return; } - /* - * Create temporary array, which is used for merging. - * Implementation note: variable "right" is increased by 1. - */ - double[] b; byte odd = 0; + // 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) { - b = a; a = new double[b.length]; - for (int i = left - 1; ++i < right; a[i] = b[i]); + System.arraycopy(a, left, work, workBase, blen); + b = a; + bo = 0; + a = work; + ao = workBase - left; } else { - b = new double[a.length]; + b = work; + ao = 0; + bo = workBase - left; } // Merging @@ -2660,21 +2719,22 @@ 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] <= a[q]) { - b[i] = a[p++]; + if (q >= hi || p < mi && a[p + ao] <= a[q + ao]) { + b[i + bo] = a[p++ + ao]; } else { - b[i] = a[q++]; + 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] = a[i] + b[i + bo] = a[i + ao] ); run[++last] = right; } double[] t = a; a = b; b = t; + int o = ao; ao = bo; bo = o; } } diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/src/share/classes/java/util/ListResourceBundle.java --- a/jdk/src/share/classes/java/util/ListResourceBundle.java Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/src/share/classes/java/util/ListResourceBundle.java Wed Jun 05 00:37:11 2013 -0700 @@ -89,7 +89,7 @@ * * public class MyResources_fr extends ListResourceBundle { * protected Object[][] getContents() { - * return new Object[][] = { + * return new Object[][] { * // LOCALIZE THIS * {"s1", "Le disque \"{1}\" {0}."}, // MessageFormat pattern * {"s2", "1"}, // location of {0} in pattern diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/src/share/classes/java/util/PropertyResourceBundle.java --- a/jdk/src/share/classes/java/util/PropertyResourceBundle.java Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/src/share/classes/java/util/PropertyResourceBundle.java Wed Jun 05 00:37:11 2013 -0700 @@ -124,6 +124,8 @@ * to read from. * @throws IOException if an I/O error occurs * @throws NullPointerException if stream is null + * @throws IllegalArgumentException if {@code stream} contains a + * malformed Unicode escape sequence. */ @SuppressWarnings({"unchecked", "rawtypes"}) public PropertyResourceBundle (InputStream stream) throws IOException { @@ -142,6 +144,8 @@ * read from. * @throws IOException if an I/O error occurs * @throws NullPointerException if reader is null + * @throws IllegalArgumentException if a malformed Unicode escape sequence appears + * from {@code reader}. * @since 1.6 */ @SuppressWarnings({"unchecked", "rawtypes"}) diff -r 14a0ae3ca973 -r 1bbdae29327c jdk/src/share/classes/java/util/Spliterator.java --- a/jdk/src/share/classes/java/util/Spliterator.java Mon Jun 03 16:37:13 2013 +0400 +++ b/jdk/src/share/classes/java/util/Spliterator.java Wed Jun 05 00:37:11 2013 -0700 @@ -140,32 +140,32 @@ * (in approximate order of decreasing desirability): *

    *
  • The source cannot be structurally interfered with. - *
    For example, an instance of + *
    For example, an instance of * {@link java.util.concurrent.CopyOnWriteArrayList} is an immutable source. * A Spliterator created from the source reports a characteristic of * {@code IMMUTABLE}.
  • *
  • The source manages concurrent modifications. - *
    For example, a key set of a {@link java.util.concurrent.ConcurrentHashMap} + *
    For example, a key set of a {@link java.util.concurrent.ConcurrentHashMap} * is a concurrent source. A Spliterator created from the source reports a * characteristic of {@code CONCURRENT}.
  • *
  • The mutable source provides a late-binding and fail-fast Spliterator. - *
    Late binding narrows the window during which interference can affect + *
    Late binding narrows the window during which interference can affect * the calculation; fail-fast detects, on a best-effort basis, that structural * interference has occurred after traversal has commenced and throws * {@link ConcurrentModificationException}. For example, {@link ArrayList}, * and many other non-concurrent {@code Collection} classes in the JDK, provide * a late-binding, fail-fast spliterator.
  • *
  • The mutable source provides a non-late-binding but fail-fast Spliterator. - *
    The source increases the likelihood of throwing + *
    The source increases the likelihood of throwing * {@code ConcurrentModificationException} since the window of potential * interference is larger.
  • *
  • The mutable source provides a late-binding and non-fail-fast Spliterator. - *
    The source risks arbitrary, non-deterministic behavior after traversal + *
    The source risks arbitrary, non-deterministic behavior after traversal * has commenced since interference is not detected. *
  • *
  • The mutable source provides a non-late-binding and non-fail-fast * Spliterator. - *
    The source increases the risk of arbitrary, non-deterministic behavior + *
    The source increases the risk of arbitrary, non-deterministic behavior * since non-detected interference may occur after construction. *
  • *
@@ -284,6 +284,8 @@ * is set to {@code true} then diagnostic warnings are reported if boxing of * primitive values occur when operating on primitive subtype specializations. * + * @param the type of elements returned by this Spliterator + * * @see Collection * @since 1.8 */ @@ -333,9 +335,8 @@ * Upon non-null return: *