1 ## 2 ## @test @(#)test6941923.sh 3 ## @bug 6941923 4 ## @summary test new added flags for gc log rotation 5 ## @author yqi 6 ## @run shell test6941923.sh 7 ## 8 9 ## skip on windows 10 OS=`uname -s` 11 case "$OS" in 12 SunOS | Linux | Darwin ) 13 NULL=/dev/null 14 PS=":" 15 FS="/" 16 ;; 17 Windows_* | CYGWIN_* ) 18 echo "Test skipped for Windows" 19 exit 0 20 ;; 21 * ) 22 echo "Unrecognized system!" 23 exit 1; 24 ;; 25 esac 26 27 if [ "${JAVA_HOME}" = "" ] 28 then 29 echo "JAVA_HOME not set" 30 exit 0 31 fi 32 33 $JAVA_HOME/bin/java ${TESTVMOPTS} -version > $NULL 2>&1 34 35 if [ $? != 0 ]; then 36 echo "Wrong JAVA_HOME? JAVA_HOME: $JAVA_HOME" 37 exit $? 38 fi 39 40 # create a small test case 41 testname="Test" 42 if [ -e ${testname}.java ]; then 43 rm -rf ${testname}.* 44 fi 45 46 cat >> ${testname}.java << __EOF__ 47 import java.util.Vector; 48 49 public class Test implements Runnable 50 { 51 private boolean _should_stop = false; 52 53 public static void main(String[] args) throws Exception { 54 55 long limit = Long.parseLong(args[0]) * 60L * 1000L; // minutes 56 Test t = new Test(); 57 t.set_stop(false); 58 Thread thr = new Thread(t); 59 thr.start(); 60 61 long time1 = System.currentTimeMillis(); 62 long time2 = System.currentTimeMillis(); 63 while (time2 - time1 < limit) { 64 try { 65 Thread.sleep(2000); // 2 seconds 66 } 67 catch(Exception e) {} 68 time2 = System.currentTimeMillis(); 69 System.out.print("\r... " + (time2 - time1)/1000 + " seconds"); 70 } 71 System.out.println(); 72 t.set_stop(true); 73 } 74 public void set_stop(boolean value) { _should_stop = value; } 75 public void run() { 76 int cap = 20000; 77 int fix_size = 2048; 78 int loop = 0; 79 Vector< byte[] > v = new Vector< byte[] >(cap); 80 while(!_should_stop) { 81 byte[] g = new byte[fix_size]; 82 v.add(g); 83 loop++; 84 if (loop > cap) { 85 v = null; 86 cap *= 2; 87 if (cap > 80000) cap = 80000; 88 v = new Vector< byte[] >(cap); 89 } 90 } 91 } 92 } 93 __EOF__ 94 95 msgsuccess="succeeded" 96 msgfail="failed" 97 gclogsize="16K" 98 filesize=$((16*1024)) 99 $JAVA_HOME/bin/javac ${testname}.java > $NULL 2>&1 100 101 if [ $? != 0 ]; then 102 echo "$JAVA_HOME/bin/javac ${testname}.java $fail" 103 exit -1 104 fi 105 106 # test for 2 minutes, it will complete circulation of gc log rotation 107 tts=2 108 logfile="test.log" 109 hotspotlog="hotspot.log" 110 111 if [ -e $logfile ]; then 112 rm -rf $logfile 113 fi 114 115 #also delete $hotspotlog if it exists 116 if [ -f $hotspotlog ]; then 117 rm -rf $hotspotlog 118 fi 119 120 options="-Xloggc:$logfile -XX:+UseConcMarkSweepGC -XX:+PrintGC -XX:+PrintGCDetails -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=1 -XX:GCLogFileSize=$gclogsize" 121 echo "Test gc log rotation in same file, wait for $tts minutes ...." 122 $JAVA_HOME/bin/java ${TESTVMOPTS} $options $testname $tts 123 if [ $? != 0 ]; then 124 echo "$msgfail" 125 exit -1 126 fi 127 128 # rotation file will be $logfile.0 129 if [ -f $logfile.0 ]; then 130 outfilesize=`ls -l $logfile.0 | awk '{print $5 }'` 131 if [ $((outfilesize)) -ge $((filesize)) ]; then 132 echo $msgsuccess 133 else 134 echo $msgfail 135 fi 136 else 137 echo $msgfail 138 exit -1 139 fi 140 141 # delete log file 142 rm -rf $logfile.0 143 if [ -f $hotspotlog ]; then 144 rm -rf $hotspotlog 145 fi 146 147 #multiple log files 148 numoffiles=3 149 options="-Xloggc:$logfile -XX:+UseConcMarkSweepGC -XX:+PrintGC -XX:+PrintGCDetails -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=$numoffiles -XX:GCLogFileSize=$gclogsize" 150 echo "Test gc log rotation in $numoffiles files, wait for $tts minutes ...." 151 $JAVA_HOME/bin/java ${TESTVMOPTS} $options $testname $tts 152 if [ $? != 0 ]; then 153 echo "$msgfail" 154 exit -1 155 fi 156 157 atleast=0 # at least size of numoffile-1 files >= $gclogsize 158 tk=0 159 while [ $(($tk)) -lt $(($numoffiles)) ] 160 do 161 if [ -f $logfile.$tk ]; then 162 outfilesize=`ls -l $logfile.$tk | awk '{ print $5 }'` 163 if [ $(($outfilesize)) -ge $(($filesize)) ]; then 164 atleast=$((atleast+1)) 165 fi 166 fi 167 tk=$((tk+1)) 168 done 169 170 rm -rf $logfile.* 171 rm -rf $testname.* 172 rm -rf $hotspotlog 173 174 if [ $(($atleast)) -ge $(($numoffiles-1)) ]; then 175 echo $msgsuccess 176 else 177 echo $msgfail 178 exit -1 179 fi