1 #!/bin/sh
   2 # 
   3 # Copyright (c) 2013, 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 
  26 # $1 - error code
  27 # $2 - test name
  28 # $3,.. - decription
  29 test_fail() {
  30     error=$1
  31     shift
  32     name=$1
  33     shift
  34     echo "TEST [$name] FAILED:"
  35     echo "$@"
  36     exit $error
  37 }
  38 
  39 # $@ - additional vm opts
  40 start_test() {
  41     # disable core dump on *nix
  42     ulimit -S -c 0
  43     # disable core dump on windows
  44     VMOPTS="$@ -XX:-CreateMinidumpOnCrash"
  45     cmd="${JAVA} ${VMOPTS} -XX:+ReplayCompiles -XX:ReplayDataFile=${replay_data}"
  46     echo $cmd
  47     $cmd
  48     return $?
  49 }
  50 
  51 # $1 - error_code
  52 # $2 - test name
  53 # $3,.. - additional vm opts
  54 positive_test() {
  55     error=$1
  56     shift
  57     name=$1
  58     shift
  59     VMOPTS="${TESTVMOPTS} $@"
  60     echo "POSITIVE TEST [$name]"
  61     start_test ${VMOPTS}
  62     exit_code=$?
  63     if [ ${exit_code} -ne 0 ]
  64     then
  65         test_fail $error "$name" "exit_code[${exit_code}] != 0 during replay "\
  66                 "w/ vmopts: ${VMOPTS}"
  67     fi
  68 }
  69 
  70 # $1 - error_code
  71 # $2 - test name
  72 # $2,.. - additional vm opts
  73 negative_test() {
  74     error=$1
  75     shift
  76     name=$1
  77     shift
  78     VMOPTS="${TESTVMOPTS} $@"
  79     echo "NEGATIVE TEST [$name]"
  80     start_test ${VMOPTS}
  81     exit_code=$?
  82     if [ ${exit_code} -eq 0 ]
  83     then
  84         test_fail $error "$name" "exit_code[${exit_code}] == 0 during replay "\
  85                 "w/ vmopts: ${VMOPTS}"
  86     fi
  87 }
  88 
  89 # $1 - initial error_code
  90 common_tests() {
  91     positive_test $1 "COMMON :: THE SAME FLAGS"
  92     if [ $tiered_available -eq 1 ]
  93     then
  94         positive_test `expr $1 + 1` "COMMON :: TIERED" -XX:+TieredCompilation
  95     fi
  96 }
  97 
  98 # $1 - initial error_code
  99 # $2 - non-tiered comp_level 
 100 nontiered_tests() {
 101     level=`grep "^compile " $replay_data | awk '{print $6}'`
 102     # is level available in non-tiered
 103     if [ "$level" -eq $2 ]
 104     then
 105         positive_test $1 "NON-TIERED :: AVAILABLE COMP_LEVEL" \
 106                 -XX:-TieredCompilation
 107     else
 108         negative_test `expr $1 + 1` "NON-TIERED :: UNAVAILABLE COMP_LEVEL" \
 109                 -XX:-TieredCompilation
 110     fi
 111 }
 112 
 113 # $1 - initial error_code
 114 client_tests() {
 115     # testing in opposite VM
 116     if [ $server_available -eq 1 ]
 117     then
 118         negative_test $1 "SERVER :: NON-TIERED" -XX:-TieredCompilation \
 119                 -server
 120         if [ $tiered_available -eq 1 ]
 121         then
 122             positive_test `expr $1 + 1` "SERVER :: TIERED" -XX:+TieredCompilation \
 123                     -server
 124         fi
 125     fi
 126     nontiered_tests `expr $1 + 2` $client_level 
 127 }
 128 
 129 # $1 - initial error_code
 130 server_tests() {
 131     # testing in opposite VM
 132     if [ $client_available -eq 1 ]
 133     then
 134         # tiered is unavailable in client vm, so results w/ flags will be the same as w/o flags
 135         negative_test $1 "CLIENT" -client
 136     fi
 137     nontiered_tests `expr $1 + 2` $server_level
 138 }
 139 
 140 cleanup() {
 141     ${RM} -f core*
 142     ${RM} -f replay*.txt
 143     ${RM} -f hs_err_pid*.log
 144     ${RM} -f test_core
 145     ${RM} -f test_replay.txt
 146 }
 147 
 148 JAVA=${TESTJAVA}${FS}bin${FS}java
 149 
 150 replay_data=test_replay.txt
 151 
 152 ${JAVA} ${TESTVMOPTS} -Xinternalversion 2>&1 | grep debug
 153 
 154 # Only test fastdebug 
 155 if [ $? -ne 0 ]
 156 then
 157     echo TEST SKIPPED: product build
 158     exit 0
 159 fi
 160 
 161 is_int=`${JAVA} ${TESTVMOPTS} -version 2>&1 | grep -c "interpreted mode"`
 162 # Not applicable for Xint
 163 if [ $is_int -ne 0 ]
 164 then
 165     echo TEST SKIPPED: interpreted mode
 166     exit 0
 167 fi
 168 
 169 cleanup
 170 
 171 client_available=`${JAVA} ${TESTVMOPTS} -client -Xinternalversion 2>&1 | \
 172         grep -c Client`
 173 server_available=`${JAVA} ${TESTVMOPTS} -server -Xinternalversion 2>&1 | \
 174         grep -c Server`
 175 tiered_available=`${JAVA} ${TESTVMOPTS} -XX:+TieredCompilation -XX:+PrintFlagsFinal -version | \
 176         grep TieredCompilation | \
 177         grep -c true`
 178 is_tiered=`${JAVA} ${TESTVMOPTS} -XX:+PrintFlagsFinal -version | \
 179         grep TieredCompilation | \
 180         grep -c true`
 181 # CompLevel_simple -- C1
 182 client_level=1
 183 # CompLevel_full_optimization -- C2 or Shark 
 184 server_level=4
 185 
 186 echo "client_available=$client_available"
 187 echo "server_available=$server_available"
 188 echo "tiered_available=$tiered_available"
 189 echo "is_tiered=$is_tiered"
 190 
 191 # crash vm in compiler thread with generation replay data and 'small' dump-file
 192 # $@ - additional vm opts
 193 generate_replay() {
 194     if [ $VM_OS != "windows" ]
 195     then
 196         # enable core dump
 197         ulimit -c unlimited
 198         new_ulimit=`ulimit -c`
 199         if [ $new_ulimit != "unlimited" -a $new_ulimit != "-1" ]
 200         then
 201             test_fail 2 "CHECK :: ULIMIT" "Could not set 'ulimit -c unlimited'. 'ulimit -c' returns : $new_ulimit"
 202         fi
 203 
 204         if [ $VM_OS = "solaris" ]
 205         then
 206             coreadm -p core $$
 207         fi
 208     fi
 209 
 210     cmd="${JAVA} ${TESTVMOPTS} $@ \
 211             -Xms8m \
 212             -Xmx32m \
 213             -XX:MetaspaceSize=4m \
 214             -XX:MaxMetaspaceSize=16m \
 215             -XX:InitialCodeCacheSize=512k \
 216             -XX:ReservedCodeCacheSize=4m \
 217             -XX:ThreadStackSize=512 \
 218             -XX:VMThreadStackSize=512 \
 219             -XX:CompilerThreadStackSize=512 \
 220             -XX:ParallelGCThreads=1 \
 221             -XX:CICompilerCount=1 \
 222             -Xcomp \
 223             -XX:CICrashAt=1 \
 224             -XX:+CreateMinidumpOnCrash \
 225             -XX:+DumpReplayDataOnError \
 226             -XX:ReplayDataFile=${replay_data} \
 227             -version"
 228     echo GENERATION OF REPLAY.TXT:
 229     echo $cmd
 230 
 231     ${cmd} > crash.out 2>&1
 232     
 233     core_locations=`grep -i core crash.out | grep "location:" | \
 234             sed -e 's/.*location: //'`
 235     echo CRASH OUTPUT:
 236     cat crash.out    
 237     rm crash.out 
 238     
 239     # processing core locations for *nix
 240     if [ $VM_OS != "windows" ]
 241     then
 242         # remove 'or' between '/core.<pid>' and 'core'
 243         core_locations=`echo $core_locations | \
 244                 sed -e 's/\([^ ]*\) or \([^ ]*\)/\1 \2/'`
 245         # add <core_path>/core.<pid> core.<pid>
 246         core_with_dir=`echo $core_locations | awk '{print $1}'`
 247         dir=`dirname $core_with_dir`
 248         core_with_pid=`echo $core_locations | awk '{print $2}'`
 249         if [ -n ${core_with_pid} ]
 250         then
 251             core_locations="$core_locations $dir${FS}$core_with_pid $core_with_pid"
 252         fi
 253     fi
 254 
 255     echo "LOOKING FOR CORE IN ${core_locations}"
 256     for core in $core_locations
 257     do
 258         if [ -r "$core" ]
 259         then
 260             core_file=$core
 261         fi
 262     done
 263 
 264     # core-file was found
 265     if [ -n "$core_file" ]
 266     then
 267         ${MV} "${core_file}" test_core
 268         core_file=test_core
 269     fi
 270 
 271     ${RM} -f hs_err_pid*.log
 272 }
 273