1 #!/bin/sh
   2 # 
   3 # Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
   4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5 # 
   6 # This code is free software; you can redistribute it and/or modify it
   7 # under the terms of the GNU General Public License version 2 only, as
   8 # published by the Free Software Foundation.
   9 # 
  10 # This code is distributed in the hope that it will be useful, but WITHOUT
  11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13 # version 2 for more details (a copy is included in the LICENSE file that
  14 # accompanied this code).
  15 # 
  16 # You should have received a copy of the GNU General Public License version
  17 # 2 along with this work; if not, write to the Free Software Foundation,
  18 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19 # 
  20 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21 # or visit www.oracle.com if you need additional information or have any
  22 # questions.
  23 # 
  24 # 
  25 set -x
  26 
  27 # $1 - error code
  28 # $2 - test name
  29 # $3,.. - decription
  30 test_fail() {
  31     error=$1
  32     shift
  33     name=$1
  34     shift
  35     echo "TEST [$name] FAILED:"
  36     echo "$@"
  37     exit $error
  38 }
  39 
  40 # $@ - additional vm opts
  41 start_test() {
  42     # disable core dump on *nix
  43     ulimit -S -c 0
  44     # disable core dump on windows
  45     VMOPTS="$@ -XX:-CreateMinidumpOnCrash"
  46     cmd="${JAVA} ${VMOPTS} -XX:+ReplayCompiles -XX:ReplayDataFile=${replay_data}"
  47     echo $cmd
  48     $cmd
  49     return $?
  50 }
  51 
  52 # $1 - error_code
  53 # $2 - test name
  54 # $3,.. - additional vm opts
  55 positive_test() {
  56     error=$1
  57     shift
  58     name=$1
  59     shift
  60     VMOPTS="${TESTOPTS} $@"
  61     echo "POSITIVE TEST [$name]"
  62     start_test ${VMOPTS}
  63     exit_code=$?
  64     if [ ${exit_code} -ne 0 ]
  65     then
  66         test_fail $error "$name" "exit_code[${exit_code}] != 0 during replay "\
  67                 "w/ vmopts: ${VMOPTS}"
  68     fi
  69 }
  70 
  71 # $1 - error_code
  72 # $2 - test name
  73 # $2,.. - additional vm opts
  74 negative_test() {
  75     error=$1
  76     shift
  77     name=$1
  78     shift
  79     VMOPTS="${TESTOPTS} $@"
  80     echo "NEGATIVE TEST [$name]"
  81     start_test ${VMOPTS}
  82     exit_code=$?
  83     if [ ${exit_code} -eq 0 ]
  84     then
  85         test_fail $error "$name" "exit_code[${exit_code}] == 0 during replay "\
  86                 "w/ vmopts: ${VMOPTS}"
  87     fi
  88 }
  89 
  90 # $1 - initial error_code
  91 common_tests() {
  92     positive_test $1 "COMMON :: THE SAME FLAGS"
  93     if [ $tiered_available -eq 1 ]
  94     then
  95         positive_test `expr $1 + 1` "COMMON :: TIERED" -XX:+TieredCompilation
  96     fi
  97 }
  98 
  99 # $1 - initial error_code
 100 # $2 - non-tiered comp_level 
 101 nontiered_tests() {
 102     level=`grep "^compile " $replay_data | awk '{print $6}'`
 103     # is level available in non-tiered
 104     if [ "$level" -eq $2 ]
 105     then
 106         positive_test $1 "NON-TIERED :: AVAILABLE COMP_LEVEL" \
 107                 -XX:-TieredCompilation
 108     else
 109         negative_test `expr $1 + 1` "NON-TIERED :: UNAVAILABLE COMP_LEVEL" \
 110                 -XX:-TieredCompilation
 111     fi
 112 }
 113 
 114 # $1 - initial error_code
 115 client_tests() {
 116     # testing in opposite VM
 117     if [ $server_available -eq 1 ]
 118     then
 119         negative_test $1 "SERVER :: NON-TIERED" -XX:-TieredCompilation \
 120                 -server
 121         if [ $tiered_available -eq 1 ]
 122         then
 123             positive_test `expr $1 + 1` "SERVER :: TIERED" -XX:+TieredCompilation \
 124                     -server
 125         fi
 126     fi
 127     nontiered_tests `expr $1 + 2` $client_level 
 128 }
 129 
 130 # $1 - initial error_code
 131 server_tests() {
 132     # testing in opposite VM
 133     if [ $client_available -eq 1 ]
 134     then
 135         # tiered is unavailable in client vm, so results w/ flags will be the same as w/o flags
 136         negative_test $1 "CLIENT" -client
 137     fi
 138     nontiered_tests `expr $1 + 2` $server_level
 139 }
 140 
 141 cleanup() {
 142     ${RM} -f core*
 143     ${RM} -f replay*.txt
 144     ${RM} -f hs_err_pid*.log
 145     ${RM} -f test_core
 146     ${RM} -f test_replay.txt
 147 }
 148 
 149 JAVA=${TESTJAVA}${FS}bin${FS}java
 150 
 151 replay_data=test_replay.txt
 152 
 153 ${JAVA} ${TESTOPTS} -Xinternalversion 2>&1 | grep debug
 154 
 155 # Only test fastdebug 
 156 if [ $? -ne 0 ]
 157 then
 158     echo TEST SKIPPED: product build
 159     exit 0
 160 fi
 161 
 162 is_int=`${JAVA} ${TESTOPTS} -version 2>&1 | grep -c "interpreted mode"`
 163 # Not applicable for Xint
 164 if [ $is_int -ne 0 ]
 165 then
 166     echo TEST SKIPPED: interpreted mode
 167     exit 0
 168 fi
 169 
 170 cleanup
 171 
 172 client_available=`${JAVA} ${TESTOPTS} -client -Xinternalversion 2>&1 | \
 173         grep -c Client`
 174 server_available=`${JAVA} ${TESTOPTS} -server -Xinternalversion 2>&1 | \
 175         grep -c Server`
 176 tiered_available=`${JAVA} ${TESTOPTS} -XX:+TieredCompilation -XX:+PrintFlagsFinal -version | \
 177         grep TieredCompilation | \
 178         grep -c true`
 179 is_tiered=`${JAVA} ${TESTOPTS} -XX:+PrintFlagsFinal -version | \
 180         grep TieredCompilation | \
 181         grep -c true`
 182 # CompLevel_simple -- C1
 183 client_level=1
 184 # CompLevel_full_optimization -- C2 or Shark 
 185 server_level=4
 186 
 187 echo "client_available=$client_available"
 188 echo "server_available=$server_available"
 189 echo "tiered_available=$tiered_available"
 190 echo "is_tiered=$is_tiered"
 191 
 192 # crash vm in compiler thread with generation replay data and 'small' dump-file
 193 # $@ - additional vm opts
 194 generate_replay() {
 195     if [ $VM_OS != "windows" ]
 196     then
 197         # enable core dump
 198         ulimit -c unlimited
 199         new_ulimit=`ulimit -c`
 200         if [ $new_ulimit != "unlimited" -a $new_ulimit != "-1" ]
 201         then
 202             test_fail 2 "CHECK :: ULIMIT" "Could not set 'ulimit -c unlimited'. 'ulimit -c' returns : $new_ulimit"
 203         fi
 204 
 205         if [ $VM_OS = "solaris" ]
 206         then
 207             coreadm -p core $$
 208         fi
 209     fi
 210 
 211     cmd="${JAVA} ${TESTOPTS} $@ \
 212             -Xms8m \
 213             -Xmx32m \
 214             -XX:MetaspaceSize=4m \
 215             -XX:MaxMetaspaceSize=16m \
 216             -XX:InitialCodeCacheSize=512k \
 217             -XX:ReservedCodeCacheSize=4m \
 218             -XX:ThreadStackSize=512 \
 219             -XX:VMThreadStackSize=512 \
 220             -XX:CompilerThreadStackSize=512 \
 221             -XX:ParallelGCThreads=1 \
 222             -XX:CICompilerCount=2 \
 223             -Xcomp \
 224             -XX:CICrashAt=1 \
 225             -XX:+CreateMinidumpOnCrash \
 226             -XX:+DumpReplayDataOnError \
 227             -XX:-TransmitErrorReport \
 228             -XX:+PreferInterpreterNativeStubs \
 229             -XX:+PrintCompilation \
 230             -XX:ReplayDataFile=${replay_data} \
 231             -version"
 232     echo GENERATION OF REPLAY.TXT:
 233     echo $cmd
 234 
 235     ${cmd} > crash.out 2>&1
 236 
 237     exit_code=$?
 238     if [ ${exit_code} -eq 0 ]
 239     then
 240         cat crash.out
 241         test_fail 3 "CHECK :: CRASH" "JVM exits gracefully"
 242     fi
 243 
 244     core_locations=`grep -i core crash.out | grep "location:" | \
 245             sed -e 's/.*location: //'`
 246    
 247     if [ -z "${core_locations}" ]
 248     then
 249         test_fail 4 "CHECK :: CORE_LOCATION" "output doesn't contain the location of core file, see crash.out"
 250     fi
 251 
 252     rm crash.out 
 253     
 254     # processing core locations for *nix
 255     if [ $VM_OS != "windows" ]
 256     then
 257         # remove 'or' between '<core_path>/core.<pid>' and 'core'
 258         # and the rest of line -- ' (max size ...) . To ensure a full core ...'
 259         core_locations=`echo $core_locations | \
 260                 sed -e 's/\([^ ]*\) or \([^ ]*\).*/\1 \2/'`
 261         core_with_dir=`echo $core_locations | awk '{print $1}'`
 262         core_with_pid=`echo $core_locations | awk '{print $2}'`
 263         dir=`dirname $core_with_dir`
 264         file=`basename $core_with_dir`
 265         # add <core_path>/core.<pid> core
 266         core_locations='$core_with_dir' '$file'
 267         if [ -n "${core_with_pid}" ]
 268         then
 269             core_locations=$core_locations '$core_with_pid' '$dir${FS}$core_with_pid'
 270         fi
 271     fi
 272 
 273     echo "LOOKING FOR CORE IN ${core_locations}"
 274     for core in $core_locations
 275     do
 276         if [ -r "$core" ]
 277         then
 278             core_file=$core
 279         fi
 280     done
 281 
 282     # core-file was found
 283     if [ -n "$core_file" ]
 284     then
 285         ${MV} "${core_file}" test_core
 286         core_file=test_core
 287     fi
 288 
 289     ${RM} -f hs_err_pid*.log
 290 }
 291