annotate test/java/nio/Buffer/LimitDirectMemory.sh @ 3076:f24699d8c892

6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended Reviewed-by: chegar
author alanb
date Fri, 15 Oct 2010 15:09:37 +0100
parents
children b79600ecf0e4
rev   line source
alanb@3076 1 #!/bin/sh
alanb@3076 2
alanb@3076 3 #
alanb@3076 4 # Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
alanb@3076 5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
alanb@3076 6 #
alanb@3076 7 # This code is free software; you can redistribute it and/or modify it
alanb@3076 8 # under the terms of the GNU General Public License version 2 only, as
alanb@3076 9 # published by the Free Software Foundation.
alanb@3076 10 #
alanb@3076 11 # This code is distributed in the hope that it will be useful, but WITHOUT
alanb@3076 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
alanb@3076 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
alanb@3076 14 # version 2 for more details (a copy is included in the LICENSE file that
alanb@3076 15 # accompanied this code).
alanb@3076 16 #
alanb@3076 17 # You should have received a copy of the GNU General Public License version
alanb@3076 18 # 2 along with this work; if not, write to the Free Software Foundation,
alanb@3076 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
alanb@3076 20 #
alanb@3076 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
alanb@3076 22 # or visit www.oracle.com if you need additional information or have any
alanb@3076 23 # questions.
alanb@3076 24 #
alanb@3076 25
alanb@3076 26 # @test
alanb@3076 27 # @bug 4627316 6743526
alanb@3076 28 # @summary Test option to limit direct memory allocation
alanb@3076 29 #
alanb@3076 30 # @build LimitDirectMemory
alanb@3076 31 # @run shell LimitDirectMemory.sh
alanb@3076 32
alanb@3076 33 # set platform-dependent variable
alanb@3076 34 OS=`uname -s`
alanb@3076 35 case "$OS" in
alanb@3076 36 SunOS | Linux ) TMP=/tmp ;;
alanb@3076 37 Windows* ) TMP="c:/temp" ;;
alanb@3076 38 * )
alanb@3076 39 echo "Unrecognized system!"
alanb@3076 40 exit 1;
alanb@3076 41 ;;
alanb@3076 42 esac
alanb@3076 43
alanb@3076 44 TMP1=${TMP}/tmp1_$$
alanb@3076 45
alanb@3076 46 runTest() {
alanb@3076 47 echo "Testing: $*"
alanb@3076 48 ${TESTJAVA}/bin/java $*
alanb@3076 49 if [ $? -eq 0 ]
alanb@3076 50 then echo "--- passed as expected"
alanb@3076 51 else
alanb@3076 52 echo "--- failed"
alanb@3076 53 exit 1
alanb@3076 54 fi
alanb@3076 55 }
alanb@3076 56
alanb@3076 57 launchFail() {
alanb@3076 58 echo "Testing: -XX:MaxDirectMemorySize=$* -cp ${TESTCLASSES} \
alanb@3076 59 LimitDirectMemory true DEFAULT DEFAULT+1M"
alanb@3076 60 ${TESTJAVA}/bin/java -XX:MaxDirectMemorySize=$* -cp ${TESTCLASSES} \
alanb@3076 61 LimitDirectMemory true DEFAULT DEFAULT+1M > ${TMP1} 2>&1
alanb@3076 62 cat ${TMP1}
alanb@3076 63 cat ${TMP1} | grep -s "Unrecognized VM option: \'MaxDirectMemorySize="
alanb@3076 64 if [ $? -ne 0 ]
alanb@3076 65 then echo "--- failed as expected"
alanb@3076 66 else
alanb@3076 67 echo "--- failed"
alanb@3076 68 exit 1
alanb@3076 69 fi
alanb@3076 70 }
alanb@3076 71
alanb@3076 72 # $java LimitDirectMemory throwp fill_direct_memory size_per_buffer
alanb@3076 73
alanb@3076 74 # Memory is properly limited using multiple buffers.
alanb@3076 75 runTest -XX:MaxDirectMemorySize=10 -cp ${TESTCLASSES} LimitDirectMemory true 10 1
alanb@3076 76 runTest -XX:MaxDirectMemorySize=1k -cp ${TESTCLASSES} LimitDirectMemory true 1k 100
alanb@3076 77 runTest -XX:MaxDirectMemorySize=10m -cp ${TESTCLASSES} LimitDirectMemory true 10m 10m
alanb@3076 78
alanb@3076 79 # We can increase the amount of available memory.
alanb@3076 80 runTest -XX:MaxDirectMemorySize=65M -cp ${TESTCLASSES} \
alanb@3076 81 LimitDirectMemory false 64M 65M
alanb@3076 82
alanb@3076 83 # Exactly the default amount of memory is available.
alanb@3076 84 runTest -cp ${TESTCLASSES} LimitDirectMemory false 10 1
alanb@3076 85 runTest -cp ${TESTCLASSES} LimitDirectMemory false 0 DEFAULT
alanb@3076 86 runTest -cp ${TESTCLASSES} LimitDirectMemory true 0 DEFAULT+1
alanb@3076 87
alanb@3076 88 # We should be able to eliminate direct memory allocation entirely.
alanb@3076 89 runTest -XX:MaxDirectMemorySize=0 -cp ${TESTCLASSES} LimitDirectMemory true 0 1
alanb@3076 90
alanb@3076 91 # Setting the system property should not work so we should be able to allocate
alanb@3076 92 # the default amount.
alanb@3076 93 runTest -Dsun.nio.MaxDirectMemorySize=1K -cp ${TESTCLASSES} \
alanb@3076 94 LimitDirectMemory false DEFAULT-1 DEFAULT/2
alanb@3076 95
alanb@3076 96 # Various bad values fail to launch the VM.
alanb@3076 97 launchFail foo
alanb@3076 98 launchFail 10kmt
alanb@3076 99 launchFail -1