Tue, 19 Mar 2013 11:33:11 -0700
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
7123945: runtime/6878713/Test6878713.sh require about 2G of native memory, swaps and times out
Summary: Add new diagnostic option -XX:MallocMaxTestWords=NNN and fix Test6878713.sh.
Reviewed-by: dcubed, coleenp, dholmes, iklam
1.1 --- a/src/share/vm/runtime/globals.hpp Tue Mar 19 13:44:26 2013 +0100 1.2 +++ b/src/share/vm/runtime/globals.hpp Tue Mar 19 11:33:11 2013 -0700 1.3 @@ -2905,6 +2905,10 @@ 1.4 "if non-zero, start verifying C heap after Nth call to " \ 1.5 "malloc/realloc/free") \ 1.6 \ 1.7 + diagnostic(uintx, MallocMaxTestWords, 0, \ 1.8 + "if non-zero, max # of Words that malloc/realloc can allocate " \ 1.9 + "(for testing only)") \ 1.10 + \ 1.11 product(intx, TypeProfileWidth, 2, \ 1.12 "number of receiver types to record in call/cast profile") \ 1.13 \
2.1 --- a/src/share/vm/runtime/os.cpp Tue Mar 19 13:44:26 2013 +0100 2.2 +++ b/src/share/vm/runtime/os.cpp Tue Mar 19 11:33:11 2013 -0700 2.3 @@ -1,5 +1,5 @@ 2.4 /* 2.5 - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 2.6 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 2.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.8 * 2.9 * This code is free software; you can redistribute it and/or modify it 2.10 @@ -80,6 +80,8 @@ 2.11 julong os::free_bytes = 0; // # of bytes freed 2.12 #endif 2.13 2.14 +static juint cur_malloc_words = 0; // current size for MallocMaxTestWords 2.15 + 2.16 void os_init_globals() { 2.17 // Called from init_globals(). 2.18 // See Threads::create_vm() in thread.cpp, and init.cpp. 2.19 @@ -570,6 +572,26 @@ 2.20 } 2.21 #endif 2.22 2.23 +// 2.24 +// This function supports testing of the malloc out of memory 2.25 +// condition without really running the system out of memory. 2.26 +// 2.27 +static u_char* testMalloc(size_t alloc_size) { 2.28 + 2.29 + if (MallocMaxTestWords > 0 && 2.30 + (cur_malloc_words + (alloc_size / BytesPerWord)) > MallocMaxTestWords) { 2.31 + return NULL; 2.32 + } 2.33 + 2.34 + u_char* ptr = (u_char*)::malloc(alloc_size); 2.35 + 2.36 + if (MallocMaxTestWords > 0 && (ptr != NULL)) { 2.37 + Atomic::add(((jint) (alloc_size / BytesPerWord)), 2.38 + (volatile jint *) &cur_malloc_words); 2.39 + } 2.40 + return ptr; 2.41 +} 2.42 + 2.43 void* os::malloc(size_t size, MEMFLAGS memflags, address caller) { 2.44 NOT_PRODUCT(inc_stat_counter(&num_mallocs, 1)); 2.45 NOT_PRODUCT(inc_stat_counter(&alloc_bytes, size)); 2.46 @@ -579,11 +601,22 @@ 2.47 // if NULL is returned the calling functions assume out of memory. 2.48 size = 1; 2.49 } 2.50 - if (size > size + space_before + space_after) { // Check for rollover. 2.51 + 2.52 + const size_t alloc_size = size + space_before + space_after; 2.53 + 2.54 + if (size > alloc_size) { // Check for rollover. 2.55 return NULL; 2.56 } 2.57 + 2.58 NOT_PRODUCT(if (MallocVerifyInterval > 0) check_heap()); 2.59 - u_char* ptr = (u_char*)::malloc(size + space_before + space_after); 2.60 + 2.61 + u_char* ptr; 2.62 + 2.63 + if (MallocMaxTestWords > 0) { 2.64 + ptr = testMalloc(alloc_size); 2.65 + } else { 2.66 + ptr = (u_char*)::malloc(alloc_size); 2.67 + } 2.68 2.69 #ifdef ASSERT 2.70 if (ptr == NULL) return NULL;
3.1 --- a/test/runtime/6878713/Test6878713.sh Tue Mar 19 13:44:26 2013 +0100 3.2 +++ b/test/runtime/6878713/Test6878713.sh Tue Mar 19 11:33:11 2013 -0700 3.3 @@ -1,10 +1,38 @@ 3.4 #!/bin/sh 3.5 3.6 +# 3.7 +# Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. 3.8 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.9 +# 3.10 +# This code is free software; you can redistribute it and/or modify it 3.11 +# under the terms of the GNU General Public License version 2 only, as 3.12 +# published by the Free Software Foundation. 3.13 +# 3.14 +# This code is distributed in the hope that it will be useful, but WITHOUT 3.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.16 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.17 +# version 2 for more details (a copy is included in the LICENSE file that 3.18 +# accompanied this code). 3.19 +# 3.20 +# You should have received a copy of the GNU General Public License version 3.21 +# 2 along with this work; if not, write to the Free Software Foundation, 3.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.23 +# 3.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.25 +# or visit www.oracle.com if you need additional information or have any 3.26 +# questions. 3.27 +# 3.28 + 3.29 + 3.30 + 3.31 ## 3.32 ## @test 3.33 ## @bug 6878713 3.34 +## @bug 7030610 3.35 +## @bug 7037122 3.36 +## @bug 7123945 3.37 ## @summary Verifier heap corruption, relating to backward jsrs 3.38 -## @run shell/timeout=120 Test6878713.sh 3.39 +## @run shell Test6878713.sh 3.40 ## 3.41 3.42 if [ "${TESTSRC}" = "" ] 3.43 @@ -49,23 +77,98 @@ 3.44 ;; 3.45 esac 3.46 3.47 -JEMMYPATH=${CPAPPEND} 3.48 -CLASSPATH=.${PS}${TESTCLASSES}${PS}${JEMMYPATH} ; export CLASSPATH 3.49 - 3.50 -THIS_DIR=`pwd` 3.51 +CLASSPATH=.${PS}${TESTCLASSES} ; export CLASSPATH 3.52 3.53 ${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} -version 3.54 3.55 -${TESTJAVA}${FS}bin${FS}jar xvf ${TESTSRC}${FS}testcase.jar 3.56 +TARGET_CLASS=OOMCrashClass1960_2 3.57 3.58 -${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} OOMCrashClass1960_2 > test.out 2>&1 3.59 +echo "INFO: extracting the target class." 3.60 +${TESTJAVA}${FS}bin${FS}jar xvf \ 3.61 + ${TESTSRC}${FS}testcase.jar ${TARGET_CLASS}.class 3.62 3.63 -if [ -s core -o -s "hs_*.log" ] 3.64 -then 3.65 - cat hs*.log 3.66 - echo "Test Failed" 3.67 - exit 1 3.68 +# remove any hs_err_pid that might exist here 3.69 +rm -f hs_err_pid*.log 3.70 + 3.71 +echo "INFO: checking for 32-bit versus 64-bit VM." 3.72 +${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} -version 2>&1 \ 3.73 + | grep "64-Bit [^ ][^ ]* VM" > /dev/null 2>&1 3.74 +status="$?" 3.75 +if [ "$status" = 0 ]; then 3.76 + echo "INFO: testing a 64-bit VM." 3.77 + is_64_bit=true 3.78 else 3.79 - echo "Test Passed" 3.80 - exit 0 3.81 + echo "INFO: testing a 32-bit VM." 3.82 fi 3.83 + 3.84 +if [ "$is_64_bit" = true ]; then 3.85 + # limit is 768MB in 8-byte words (1024 * 1024 * 768 / 8) == 100663296 3.86 + MALLOC_MAX=100663296 3.87 +else 3.88 + # limit is 768MB in 4-byte words (1024 * 1024 * 768 / 4) == 201326592 3.89 + MALLOC_MAX=201326592 3.90 +fi 3.91 +echo "INFO: MALLOC_MAX=$MALLOC_MAX" 3.92 + 3.93 +echo "INFO: executing the target class." 3.94 +# -XX:+PrintCommandLineFlags for debugging purposes 3.95 +# -XX:+IgnoreUnrecognizedVMOptions so test will run on a VM without 3.96 +# the new -XX:MallocMaxTestWords option 3.97 +# -XX:+UnlockDiagnosticVMOptions so we can use -XX:MallocMaxTestWords 3.98 +# -XX:MallocMaxTestWords limits malloc to $MALLOC_MAX 3.99 +${TESTJAVA}${FS}bin${FS}java \ 3.100 + -XX:+PrintCommandLineFlags \ 3.101 + -XX:+IgnoreUnrecognizedVMOptions \ 3.102 + -XX:+UnlockDiagnosticVMOptions \ 3.103 + -XX:MallocMaxTestWords=$MALLOC_MAX \ 3.104 + ${TESTVMOPTS} ${TARGET_CLASS} > test.out 2>&1 3.105 + 3.106 +echo "INFO: begin contents of test.out:" 3.107 +cat test.out 3.108 +echo "INFO: end contents of test.out." 3.109 + 3.110 +echo "INFO: checking for memory allocation error message." 3.111 +# We are looking for this specific memory allocation failure mesg so 3.112 +# we know we exercised the right allocation path with the test class: 3.113 +MESG1="Native memory allocation (malloc) failed to allocate 25696531[0-9][0-9] bytes" 3.114 +grep "$MESG1" test.out 3.115 +status="$?" 3.116 +if [ "$status" = 0 ]; then 3.117 + echo "INFO: found expected memory allocation error message." 3.118 +else 3.119 + echo "INFO: did not find expected memory allocation error message." 3.120 + 3.121 + # If we didn't find MESG1 above, then there are several scenarios: 3.122 + # 1) -XX:MallocMaxTestWords is not supported by the current VM and we 3.123 + # didn't fail TARGET_CLASS's memory allocation attempt; instead 3.124 + # we failed to find TARGET_CLASS's main() method. The TARGET_CLASS 3.125 + # is designed to provoke a memory allocation failure during class 3.126 + # loading; we actually don't care about running the class which is 3.127 + # why it doesn't have a main() method. 3.128 + # 2) we failed a memory allocation, but not the one we were looking 3.129 + # so it might be that TARGET_CLASS no longer tickles the same 3.130 + # memory allocation code path 3.131 + # 3) TARGET_CLASS reproduces the failure mode (SIGSEGV) fixed by 3.132 + # 6878713 because the test is running on a pre-fix VM. 3.133 + echo "INFO: checking for no main() method message." 3.134 + MESG2="Error: Main method not found in class" 3.135 + grep "$MESG2" test.out 3.136 + status="$?" 3.137 + if [ "$status" = 0 ]; then 3.138 + echo "INFO: found no main() method message." 3.139 + else 3.140 + echo "FAIL: did not find no main() method message." 3.141 + # status is non-zero for exit below 3.142 + 3.143 + if [ -s hs_err_pid*.log ]; then 3.144 + echo "INFO: begin contents of hs_err_pid file:" 3.145 + cat hs_err_pid*.log 3.146 + echo "INFO: end contents of hs_err_pid file." 3.147 + fi 3.148 + fi 3.149 +fi 3.150 + 3.151 +if [ "$status" = 0 ]; then 3.152 + echo "PASS: test found one of the expected messages." 3.153 +fi 3.154 +exit "$status"