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