# 8038468.sh --
#
#    Run ParallelTransformerLoader.sh in parallel to reproduce the java.lang.ClassCircularityError
#    as reported in https://bugs.openjdk.java.net/browse/JDK-8038468
#
#    On 2014/09/23, I was able to reproduce the error in a couple of minutes on ioilinux.us.oracle.com:
#
#        Linux ioilinux 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
#        Intel(R) Xeon(R) CPU E5-2665 0 @ 2.40GHz, 2 sockets, 32 total threads
#        64GB RAM
#
#        test JDK: (/java/re/jdk/8u40/promoted/ea/b06/binaries/linux-x64)
#        java version "1.8.0_40-ea"
#        Java(TM) SE Runtime Environment (build 1.8.0_40-ea-b06)
#        Java HotSpot(TM) 64-Bit Server VM (build 25.40-b10, mixed mode)


# Modify the following variables to suit your environment
JTREG=${HOME}/jdk/tools/jtreg/execution/linux/bin/jtreg
GOODJAVAHOME=/java/re/jdk/8/latest/binaries/linux-i586
#jdk=/java/re/jdk/9/promoted/ea/b31/binaries/linux-x64
 jdk=/java/re/jdk/8u40/promoted/ea/b06/binaries/linux-x64
#jdk=${TESTBED}

if [[ "$1" = "" ]]; then
    echo "Usage: bash $0 <num jobs>"
    exit 1
fi

echo JTREG={$JTREG}
echo GOODJAVAHOME=${GOODJAVAHOME}
echo jdk=${jdk}
echo jobs="$1"

for i in $(seq 1 $1); do
    (
        loop=1
        mkdir -p /tmp/$USER/8038468/$i.w
        mkdir -p /tmp/$USER/8038468/$i.r
        while printf "%3d:%d\n" $i $loop && \
            JAVA_HOME=${GOODJAVAHOME} $JTREG \
                -conc:1 -testjdk:${jdk} -compilejdk:${GOODJAVAHOME} \
                -verbose:2 -javacoption:-J-Xmx512m \
                -w /tmp/$USER/8038468/$i.w \
                -r /tmp/$USER/8038468/$i.r -ignore:run jdk/test/java/lang/instrument/ParallelTransformerLoader.sh 2>&1 > /tmp/$USER/8038468/$i.log ; do
            loop=$(expr $loop + 1)
        done
        echo "Error detected by job $i"
    ) &
done

while wait; do true; done

